powered by simpleCommunicator - 2.0.52     © 2025 Programmizd 02
Форумы / IBExpert [игнор отключен] [закрыт для гостей] / IBExpert vs link SQL Server Management Studio
3 сообщений из 28, страница 2 из 2
IBExpert vs link SQL Server Management Studio
    #37514979
FB2.5
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Dimitry Sibiryakov,

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
( 1  row(s) affected)
StmtText
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
select * from avr_vs_request...kp_request kp
where (select count(kp1.numberreceivedrequest) from avr_vs_request...kp_request kp1
       where kp1.numberreceivedrequest = kp.numberreceivedrequest) >  1 
order by kp.numberreceivedrequest

( 1  row(s) affected)

StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  |--Sort(ORDER BY:([avr_vs_request]...[kp_request].[NUMBERRECEIVEDREQUEST] ASC))
       |--Filter(WHERE:(CASE WHEN [Expr1004] IS NULL THEN (0) ELSE [Expr1004] END>(1)))
            |--Hash Match(Right Outer Join, HASH:([avr_vs_request]...[kp_request].[NUMBERRECEIVEDREQUEST])=([avr_vs_request]...[kp_request].[NUMBERRECEIVEDREQUEST]), RESIDUAL:([avr_vs_request].[kp_request].[NUMBERRECEIVEDREQUEST] as [kp1].[NUMBERRECEIVEDRE
                 |--Compute Scalar(DEFINE:([Expr1004]=CONVERT_IMPLICIT(int,[Expr1011],0)))
                 |    |--Hash Match(Aggregate, HASH:([avr_vs_request]...[kp_request].[NUMBERRECEIVEDREQUEST]), RESIDUAL:([avr_vs_request].[kp_request].[NUMBERRECEIVEDREQUEST] as [kp1].[NUMBERRECEIVEDREQUEST] = [avr_vs_request].[kp_request].[NUMBERRECEIVEDR
                 |         |--Remote Scan(SOURCE:(avr_vs_request), OBJECT:(kp_request))
                 |--Remote Scan(SOURCE:(avr_vs_request), OBJECT:(kp_request))

( 7  row(s) affected)



я надеюсь поможет
...
Рейтинг: 0 / 0
IBExpert vs link SQL Server Management Studio
    #37514994
Dimitry Sibiryakov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FB2.5я надеюсь поможет
Ну, собственно, как я предполагал: агрегирование потом джоин. То же самое, что и Таблоид
написал. Только MS SQL умеет hash outer join, а Firebird пока нет.
Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
IBExpert vs link SQL Server Management Studio
    #37515026
Таблоид
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
m7mИ почему никто не предложил EXISTS неужели он будет медленнее работатьне зная точного распределения данных у таблице ТСа, невозможно предсказать.
Но вот на таком распределении, когда 10% строк - уникальные, а остальные имеют дубли (от 1 до 49) - что типично для дочерних таблиц - получается, что join немного быстрее exists'a. Вариант же, показанный ТС'ом, нервно покуривает в стороне.
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
execute block as begin
execute statement 'drop sequence gen_ft;';
when any do begin end
end;
commit;
create sequence gen_ft;
commit;

recreate table t(id int, ii int primary key); commit;
execute block as
declare n int =  150000 ; -- общее число записей
declare m int =  50 ; -- сколько макс. дублей делать на одну запись
declare i int;
declare j int;
declare k int;
begin
  k=n;
  while (n> 0 ) do begin
    i= 1 ;
    j=iif(rand()< 0 . 25 , rand()*m,  1 ); -- j>1 ==> дубли в кол-ве от 1 до j-1.
    while (i<=j) do begin
      insert into t values( iif(:j= 1 , -:n, :n), gen_id(gen_ft, 1 ) );
      i=i+ 1 ;
    end
    n=n-j;
  end
end;
commit;
create index t_idx on t(id);
commit;
var_1. join
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
select sum(ft.id)
from t ft
join (
  select x.id
  from t x
  group by x.id
  having count(*)> 1 
)ft1
on ft.id=ft1.id
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
Execute time = 296ms
Avg fetch time =  296,00 ms 
Current memory = 9454304
Max memory = 14253136
Memory buffers = 1024
Reads from disk to cache = 0
Writes from cache to disk = 0
Fetches from cache = 784785

var_2. exists
Код: plaintext
1.
2.
select sum(ft.id)
from t ft
where exists(select * from t x where x.id=ft.id and x.ii<>ft.ii)
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
Execute time =  734ms 
Avg fetch time = 734,00 ms
Current memory = 10068960
Max memory = 14936928
Memory buffers = 1024
Reads from disk to cache = 999
Writes from cache to disk = 0
Fetches from cache = 1064768

var_3. count(*) внутри where:
Код: plaintext
1.
2.
3.
4.
select sum(id) --count(*)
from(
select * from t f_t
where (select count(f_t1.id) from t f_t1  where f_t1.id = f_t.id) >  1 
)z
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
Execute time =  4s 890ms 
Avg fetch time = 0,03 ms
Current memory = 9438408
Max memory = 14253136
Memory buffers = 1024
Reads from disk to cache = 920
Writes from cache to disk = 0
Fetches from cache = 10389357

В ситуации, когда индекса на поле ID нет, запрос по var_1 практически остался на той же скорости: 396 ms (хотя там кеширование, конечно, сыграло роль). А вот запрос по var_2 (с exists) провалился в небытие. Тоже самое, ес-сно, случилось и с запросом var_3.
...
Рейтинг: 0 / 0
3 сообщений из 28, страница 2 из 2
Форумы / IBExpert [игнор отключен] [закрыт для гостей] / IBExpert vs link SQL Server Management Studio
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]