Thursday, July 1, 2010

Join comparison

This is a slight modification of the standard DAX Development III example of joins being used to increase performance. I expect the data set I've chose isn't ideal to highlight the concept, but it's adequate for my purpose, which is to demonstrate that the concept holds:

static void Nathan_Join(Args _args)
{
System.DateTime first, second;
System.TimeSpan ts;
str dummy;
LedgerTrans lTr;
LedgerTable lTa;
AmountMST amount;
str message;
;

flush LedgerTable;
flush LedgerTrans;
first = System.DateTime::get_Now();
while select AccountNum from lTa where lTa.AccountName like 'Bank*'
{
while select lTr
where lTr.accountNum == lTa.accountNum
{
amount += lTr.amountMST;
}
}
second = System.DateTime::get_Now();
ts = second.Subtract(first);
message += ts.ToString();
message += strFmt("\nNo join: %1\n", amount);

amount = 0;
flush LedgerTable;
flush LedgerTrans;
first = System.DateTime::get_Now();
while select accountNum from lTa where lTa.AccountName like 'Bank*'
join amountMST from lTr
where lTr.accountNum == lTa.accountNum
{
amount += lTr.amountMST;
}
second = System.DateTime::get_Now();
ts = second.Subtract(first);
message += ts.ToString();
message += strFmt("\nJoin amount: %1", amount);

info(message);
}



Result:
00:00:02.5510000
No join: 36,289,571.52
00:00:02.1480000
Join amount: 36,289,571.52

Less that 100% of difference. Smaller scale of difference than the field list and aggregation testing. As mentioned, different data sets would produce different results. If performance matters, it's always worth profiling alternatives - and checking the result is consistent between all alternatives :-)

Note, I've rejigged the output approach so a single infolog message it produced. This is easier to copy/paste into here!

No comments:

Post a Comment