AXForum  
Go Back   AXForum > Microsoft Dynamics AX > DAX: Программирование
All
Forgotten Your Password?
Register Forum Rules FAQ Members List Today's Posts Search

 
 
Thread Tools Search this Thread Display Modes
Old 01.11.2007, 13:50   #1  
KpecT is offline
KpecT
Участник
 
56 / 10 (1) +
Join Date: 14.08.2007
Lightbulb Оптимизировать запрос
Данный запрос работает от 7 до 8 мин., сильно долго. Помогииииииииите

while select sum(AmountMST),AccountNum,Dimension[4],Voucher
from
ledgerTrans
index hint ACDate
group by Dimension[4],AccountNum,Voucher
where (ledgerTrans.AccountNum == #Account08_20
|| ledgerTrans.AccountNum == #Account08_30
|| ledgerTrans.AccountNum == #Account08_80
|| ledgerTrans.AccountNum == #Account08_90
|| ledgerTrans.AccountNum == #Account08_91
|| ledgerTrans.AccountNum == #Account08_92)
&& ledgerTrans.TransDate <= transdate
&& ledgerTrans.PeriodCode == PeriodCode::Regular
&& !(ledgerTrans.Voucher like "IV05*")
{
select firstonly firstFast RecId
from
inventTrans
where inventTrans.Voucher == ledgerTrans.Voucher;
if (!inventTrans.RecId)
{
value = ledgerTrans.AmountMST;
b = [ledgerTrans.Dimension[4],ledgerTrans.AccountNum];
simap = this.SetMap(simap,value,b);
}
}
Old 01.11.2007, 14:04   #2  
UNRW is offline
UNRW
Участник
 
383 / 67 (3) ++++
Join Date: 16.09.2004
Location: Москва
сделайте все в одном select
разбейте lederTrans на выбрку по дебету и по кредиту и сделайте outer join InventTrans

lederTransDeb
lederTransCred
InventTrans
Old 01.11.2007, 14:10   #3  
ice is offline
ice
Участник
ice's Avatar
Лучший по профессии 2014
 
1,822 / 402 (17) +++++++
Join Date: 23.03.2006
1) сделайте один индекс по полям входящим в группировку и в where
2) notexists join inventtrans и сделайте индекс по полю voucher
Old 01.11.2007, 14:13   #4  
Владимир Максимов is offline
Владимир Максимов
Участник
КОРУС Консалтинг
 
1,720 / 1207 (44) ++++++++
Join Date: 13.01.2004
Blog Entries: 3
X++:
    while select 
            Dimension[4],
            AccountNum,
            Voucher,
            sum(AmountMST)
    from ledgerTrans
    group by
        Dimension[4],
        AccountNum,
        Voucher
    where
        (ledgerTrans.AccountNum == #Account08_20
        || ledgerTrans.AccountNum == #Account08_30
        || ledgerTrans.AccountNum == #Account08_80
        || ledgerTrans.AccountNum == #Account08_90
        || ledgerTrans.AccountNum == #Account08_91
        || ledgerTrans.AccountNum == #Account08_92)
        && ledgerTrans.TransDate <= transdate
        && ledgerTrans.PeriodCode == PeriodCode::Regular
        && !(ledgerTrans.Voucher like "IV05*")
    notexists join inventTrans
    where inventTrans.Voucher == ledgerTrans.Voucher
    {
        value   = ledgerTrans.AmountMST;
        b       = [ledgerTrans.Dimension[4],ledgerTrans.AccountNum];
        simap   = this.SetMap(simap,value,b);
    }
Old 01.11.2007, 14:13   #5  
Alexius is offline
Alexius
Участник
Alexius's Avatar
 
461 / 248 (9) ++++++
Join Date: 13.12.2001
Попробуйте последовательно:
1. Если у вас MS SQL - выкиньте из запроса index hint ACDate
2. Постройте индекс по таблице InventTrans с полями:
- Voucher
- RecId
3. На таблице LedgerTrans в индекс VoucherDateIdx помимо полей:
- Voucher
- TransDate
добавьте еще вниз поля:
- AccountNum
- PeriodCode
- Dimension[4]
- AmountMST

PS. Последовательность полей в индексе очень важна !
Old 01.11.2007, 14:35   #6  
KpecT is offline
KpecT
Участник
 
56 / 10 (1) +
Join Date: 14.08.2007
Работать стал 15 сек.
Спасибо, очень помогли.
Old 01.11.2007, 15:38   #7  
kashperuk is offline
kashperuk
Участник
kashperuk's Avatar
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Join Date: 30.05.2004
Location: Atlanta, GA, USA
Какой конкретно совет помог?
Old 01.11.2007, 15:53   #8  
KpecT is offline
KpecT
Участник
 
56 / 10 (1) +
Join Date: 14.08.2007
Как раз подумал, что страна должна знать своих героев:
1. ice по идее все написал, что нужно было сделать
2. Владимир Максимов показал, как это должно выглядеть в коде.
3. Alexius подсказал с index' ми.

Last edited by KpecT; 01.11.2007 at 15:57.
 

Similar Threads
Thread Thread Starter Forum Replies Last Post
передача параметров в запрос while select tolstjak DAX: Программирование 13 15.02.2009 19:39
Как собрать запрос? moid DAX: Программирование 11 02.07.2007 12:07
Почему join запрос разбивается на подзапросы!? 3oppo DAX: Программирование 59 28.06.2007 11:52
Долго отрабатывает запрос по таблице InventItemLocation AlexeyBP DAX: Администрирование 1 30.05.2007 17:33
Не работает запрос на нескольких компаниях Bega DAX: Программирование 3 16.09.2005 10:21

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Рейтинг@Mail.ru
All times are GMT +3. The time now is 04:34.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Contacts E-mail, Advertising.