Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / Помогите победить оптимизатор / 6 сообщений из 6, страница 1 из 1
18.01.2009, 19:35
    #35763548
cherrex_Den
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
есть простой запрос(не я писал!!!) который на ASE 15 работает хуже чем на ASE 12.5! Не как не могу это побороть

Код: 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.
select   -- добовляем импортные контейнера расход             
	job_time_period = convert(char( 10 ),c.DATE_RASX, 111 ),              
	agreement_cargo_code = c.KOD_GRUZA_DOG,                
        agreement_code = ag.agreement_id,                
	cargo_type = 'CONT',                        
	packet_count = null,                     
	package_count = (select count (cr.NUM_KONT)     
                         from ext_import_kont cr --(index ind_date_rasx)     
                         join agreement ag2 on cr.AGREEMENT_NUMBER = ag2.number     
			 where cr.PR_FIKT =  0  and     
                               convert(char( 10 ),c.DATE_RASX, 111 ) = convert(char( 10 ),cr.DATE_RASX, 111 ) and     
                               c.SKLAD = cr.SKLAD and                                   
                               c.KOD_GRUZA_DOG = cr.KOD_GRUZA_DOG and      
                               ag.agreement_id = ag2.agreement_id     
                        ),              
	weight_gross = sum(c.BRUTTO_FAKT)/ 1000 ,               
	weight_nett = sum(c.TARA_F)/ 1000 ,                        
	job_type = 'Импорт',             
        type_status = 'Убыло     ',             
        storage = 'СКЛ.' + convert (char( 20 ),c.SKLAD)               
from ext_import_kont c  
join agreement ag on c.AGREEMENT_NUMBER = ag.number              
where c.DATE_RASX between '20090101' and '20090120' and c.KOD_GRUZA_DOG is not null              
group by convert(char( 10 ),c.DATE_RASX, 111 ),            
	 c.KOD_GRUZA_DOG,              
	 ag.agreement_id,      
	 c.SKLAD      

все дело в подзапросе, плохо ASE 15 его раскручивает. Настройки оптимизатор ASE 15 пока не трогал(стоит allrow_mix).


План 12.5
Код: 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.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
STEP  1  
        The type of query is SELECT (into Worktable1). 
        GROUP BY 
        Evaluate Grouped SUM OR AVERAGE AGGREGATE. 
        Evaluate Grouped SUM OR AVERAGE AGGREGATE. 
        Executed in parallel by coordinating process and  2  worker processes. 


        FROM TABLE 
            ext_import_kont 
            c 
        Nested iteration. 
        Index : ind_date_rasx 
        Forward scan. 
        Positioning by key. 
        Keys are: 
            DATE_RASX  ASC 
        Executed in parallel with a  2 -way hash scan. 
        Using I/O Size  2  Kbytes for index leaf pages. 
        With LRU Buffer Replacement Strategy for index leaf pages. 
        Using I/O Size  2  Kbytes for data pages. 
        With LRU Buffer Replacement Strategy for data pages. 


        FROM TABLE 
            agreement 
            ag 
        Nested iteration. 
        Index : ind_agrement_number 
        Forward scan. 
        Positioning by key. 
        Keys are: 
            number  ASC 
        Using I/O Size  2  Kbytes for index leaf pages. 
        With LRU Buffer Replacement Strategy for index leaf pages. 
        Using I/O Size  2  Kbytes for data pages. 
        With LRU Buffer Replacement Strategy for data pages. 
        TO TABLE 
            Worktable1. 


        Parallel work table merge. 


    STEP  2  
        The type of query is INSERT. 
        The update mode is direct. 
        Executed by coordinating process. 
        Worktable2 created for REFORMATTING. 


        FROM TABLE 
            ext_import_kont 
            cr 
        Nested iteration. 
        Table Scan. 
        Forward scan. 
        Positioning at start of table. 
        Using I/O Size  2  Kbytes for data pages. 
        With LRU Buffer Replacement Strategy for data pages. 
        TO TABLE 
            Worktable2. 


    STEP  3  
        The type of query is SELECT. 
        Executed by coordinating process. 


        FROM TABLE 
            Worktable1. 
        Nested iteration. 
        Table Scan. 
        Forward scan. 
        Positioning at start of table. 


        Run subquery  1  (at nesting level  1 ). 
        Using I/O Size  2  Kbytes for data pages. 
        With MRU Buffer Replacement Strategy for data pages. 
    STEP  1  


NESTING LEVEL  1  SUBQUERIES FOR STATEMENT  1 . 


  QUERY PLAN FOR SUBQUERY  1  (at nesting level  1  and at line  7 ). 


    Correlated Subquery. 
    Subquery under an EXPRESSION predicate. 




    STEP  1  
        The type of query is SELECT. 
        Evaluate Ungrouped COUNT AGGREGATE. 
        Executed by coordinating process. 


        FROM TABLE 
            agreement 
            ag2 
        Nested iteration. 
        Index : pk_agreement 
        Forward scan. 
        Positioning by key. 
        Keys are: 
            agreement_id  ASC 
        Using I/O Size  2  Kbytes for index leaf pages. 
        With LRU Buffer Replacement Strategy for index leaf pages. 
        Using I/O Size  2  Kbytes for data pages. 
        With LRU Buffer Replacement Strategy for data pages. 


        FROM TABLE 
            Worktable2. 
        Nested iteration. 
        Using Clustered Index. 
        Forward scan. 
        Positioning by key. 
        Using I/O Size  2  Kbytes for data pages. 
        With LRU Buffer Replacement Strategy for data pages. 


план 15
Код: 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.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
|ROOT:EMIT Operator 
       | 
       |   |RESTRICT Operator 
       |   | 
       |   |   |SQFILTER Operator has  2  children. 
       |   |   | 
       |   |   |   |HASH VECTOR AGGREGATE Operator 
       |   |   |   |  GROUP BY 
       |   |   |   |  Evaluate Grouped SUM OR AVERAGE AGGREGATE. 
       |   |   |   |  Evaluate Grouped SUM OR AVERAGE AGGREGATE. 
       |   |   |   | Using Worktable2 for internal storage. 
       |   |   |   |  Key Count:  4  
       |   |   |   | 
       |   |   |   |   |RESTRICT Operator 
       |   |   |   |   | 
       |   |   |   |   |   |HASH JOIN Operator (Join Type: Inner Join) 
       |   |   |   |   |   | Using Worktable1 for internal storage. 
       |   |   |   |   |   |  Key Count:  1  
       |   |   |   |   |   | 
       |   |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |   |  ext_import_kont 
       |   |   |   |   |   |   |  c 
       |   |   |   |   |   |   |  Index : ind_date_rasx 
       |   |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |   |  Positioning by key. 
       |   |   |   |   |   |   |  Keys are: 
       |   |   |   |   |   |   |    DATE_RASX ASC 
       |   |   |   |   |   |   |  Using I/O Size  16  Kbytes for index leaf pages. 
       |   |   |   |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages. 
       |   |   |   |   |   |   |  Using I/O Size  16  Kbytes for data pages. 
       |   |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
       |   |   |   |   |   | 
       |   |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |   |  agreement 
       |   |   |   |   |   |   |  ag 
       |   |   |   |   |   |   |  Table Scan. 
       |   |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |   |  Positioning at start of table. 
       |   |   |   |   |   |   |  Using I/O Size  16  Kbytes for data pages. 
       |   |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
       |   |   | 
       |   |   |  Run subquery  1  (at nesting level  1 ). 
       |   |   | 
       |   |   |  QUERY PLAN FOR SUBQUERY  1  (at nesting level  1  and at line  7 ). 
       |   |   | 
       |   |   |   Correlated Subquery. 
       |   |   |   Subquery under an EXPRESSION predicate. 
       |   |   | 
       |   |   |   |SCALAR AGGREGATE Operator 
       |   |   |   |  Evaluate Ungrouped COUNT AGGREGATE. 
       |   |   |   | 
       |   |   |   |   |NESTED LOOP JOIN Operator (Join Type: Inner Join) 
       |   |   |   |   | 
       |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |  agreement 
       |   |   |   |   |   |  ag2 
       |   |   |   |   |   |  Index : pk_agreement 
       |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |  Positioning by key. 
       |   |   |   |   |   |  Keys are: 
       |   |   |   |   |   |    agreement_id ASC 
       |   |   |   |   |   |  Using I/O Size  2  Kbytes for index leaf pages. 
       |   |   |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages. 
       |   |   |   |   |   |  Using I/O Size  2  Kbytes for data pages. 
       |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
       |   |   |   |   | 
       |   |   |   |   |   |RESTRICT Operator 
       |   |   |   |   |   | 
       |   |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |   |  ext_import_kont 
       |   |   |   |   |   |   |  cr 
       |   |   |   |   |   |   |  Table Scan. 
       |   |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |   |  Positioning at start of table. 
       |   |   |   |   |   |   |  Using I/O Size  16  Kbytes for data pages. 
       |   |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
       |   |   | 
       |   |   |  END OF QUERY PLAN FOR SUBQUERY  1 . 


Заранее спасибо!!!
...
Рейтинг: 0 / 0
19.01.2009, 18:38
    #35765645
cherrex_Den
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
Подскажите хотя бы абстрактный план запроса в ASE 12.5.0.2 получить(посмотреть) можно?

И подскажите чем отличаются планы подзапросов? Я понимаю что в ASE 12.5 "agreement ag2" джойниться со временной тбл., уже подготовленной и маленькой, а в ASE 15.0.2 происходит джойн с всей "ext_import_kont"(table scan). Я правильно понимаю?
...
Рейтинг: 0 / 0
23.01.2009, 02:00
    #35772851
rcryo
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
авторПодскажите хотя бы абстрактный план запроса в ASE 12.5.0.2 получить(посмотреть) можно?
Для миграциии "сложных" для ASE15 запросов я применял след. последовательность:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
/* ASE 12.5. Capture the plan for the query. */
set plan dump on
go

/* queries to run: select, update, delete*/
SELECT ....
go

set plan dump off
go

/* Use sp_find_qplan to find ID of the plan.*/
sp_find_qplan '%pattern%'
go

/* Use sp_help_qplan to display the SQL text and plan.*/
sp_help_qplan @ID
go

/* ASE 15. Add the plan clause to select, insert...select, update, delete statement */
SELECT ….. PLAN ‘(<your plan>)’
Сори за английский, писалось для заказчика, а счас ночь на дворе - переводить обратно лень.

авторИ подскажите чем отличаются планы подзапросов?
ASE 12.5 строит Worktable2 с кластерным индексом и уже её конектит с agreement ag2 по условию cr.AGREEMENT_NUMBER = ag2.number Кстати сверьте типы данных cr.AGREEMENT_NUMBER и ag2.number - может там Worktable и не нужна.
ASE15 не проводит реформатирования, а тупо соединяет agreement ag2 и ext_import_kont с Table scan'ом последней таблицы
Код: 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.
       |   |   |   |   |NESTED LOOP JOIN Operator (Join Type: Inner Join) 
       |   |   |   |   | 
       |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |  agreement 
       |   |   |   |   |   |  ag2 
       |   |   |   |   |   |  Index : pk_agreement 
       |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |  Positioning by key. 
       |   |   |   |   |   |  Keys are: 
       |   |   |   |   |   |    agreement_id ASC 
       |   |   |   |   |   |  Using I/O Size  2  Kbytes for index leaf pages. 
       |   |   |   |   |   |  With LRU Buffer Replacement Strategy for index leaf pages. 
       |   |   |   |   |   |  Using I/O Size  2  Kbytes for data pages. 
       |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
       |   |   |   |   | 
       |   |   |   |   |   |RESTRICT Operator 
       |   |   |   |   |   | 
       |   |   |   |   |   |   |SCAN Operator 
       |   |   |   |   |   |   |  FROM TABLE 
       |   |   |   |   |   |   |  ext_import_kont 
       |   |   |   |   |   |   |  cr 
       |   |   |   |   |   |   |  Table Scan. 
       |   |   |   |   |   |   |  Forward Scan. 
       |   |   |   |   |   |   |  Positioning at start of table. 
       |   |   |   |   |   |   |  Using I/O Size  16  Kbytes for data pages. 
       |   |   |   |   |   |   |  With LRU Buffer Replacement Strategy for data pages. 
...
Рейтинг: 0 / 0
23.01.2009, 13:00
    #35773606
cherrex_Den
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
Спасибо большое!!! Все получилось!
...
Рейтинг: 0 / 0
23.01.2009, 13:52
    #35773796
Ex_Soft
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
/me думает: во монстры!!! Мо заглянете, на досуге, сюда ?
_________________
"Helo, word!" - 17 errors 56 warnings
Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
23.01.2009, 16:17
    #35774292
rcryo
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Помогите победить оптимизатор
Вас там главный гуру консультирует - я его боюсь.
...
Рейтинг: 0 / 0
Форумы / Sybase ASA, ASE, IQ [игнор отключен] [закрыт для гостей] / Помогите победить оптимизатор / 6 сообщений из 6, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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