Hi, I'm seeing major performance issues on queryin...
# suiteql
w
Hi, I'm seeing major performance issues on querying transaction+transactionlines+transactionaccountinglines when doing it with a role that has restrictions on which subsidiaries it has access to. Anyone seen similar issues?
This simple query:
Copy code
require(['N/query'],(query)=>{
    console.log('start');
    var t_total = performance.now();
    [39,1043,1143,143].forEach(subsidiaryId =>{
	var t_exec = performance.now();
	var results = query.runSuiteQL(`
		SELECT
			T.recordtype AS type,
			T.number,
			T.trandate AS date,
			TL.entity,
			C.symbol as "Transaction Currency",
			nvl(TAL.debit,0) AS "Debit",
			nvl(TAL.credit,0) AS "Credit",
			nvl(TL.debitforeignamount,0) AS "Debit (FX)",
			nvl(TL.creditforeignamount,0) AS "Credit (FX)",
			TL.memo
		FROM
			transactionLine TL
			INNER JOIN  "TRANSACTION" T
				ON T."ID" = TL."TRANSACTION"
			INNER JOIN transactionaccountingline TAL
				ON T."ID" = TAL.transaction AND TL.ID = TAL.transactionline
			INNER JOIN currency C
				ON T.currency = C.id
		WHERE
			TL.subsidiary = ${subsidiaryId}
			AND TAL.account = 115
			AND TAL.posting = 'T'
			AND ROWNUM <= 5`).asMappedResults();
		console.log(`Execution for subsidiary ${subsidiaryId} complete. Time to execute: ${((performance.now()-t_exec)/1000).toFixed(2)}s`);
	})
	console.log(`end: ${((performance.now()-t_total)/1000).toFixed(2)}s`);
});
With custom (almost admin-role):
Copy code
start
Execution for subsidiary 39 complete. Time to execute: 3.16s
Execution for subsidiary 1043 complete. Time to execute: 3.09s
Execution for subsidiary 1143 complete. Time to execute: 3.04s
Execution for subsidiary 143 complete. Time to execute: 3.09s
end: 12.39s
With a role that has restrictions on subsidiaries:
Copy code
start
Execution for subsidiary 39 complete. Time to execute: 39.87s
Execution for subsidiary 1043 complete. Time to execute: 38.98s
Execution for subsidiary 1143 complete. Time to execute: 40.08s
Execution for subsidiary 143 complete. Time to execute: 39.41s
end: 158.34s
Bad SQL? Any ideas are welcome!
With real admin... this is rediculous :
j
hi @Watz - we approached NetSuite support with a similar situation recently, and our resolution might help you: We were informed that the order of the *JOIN*s can (surprisingly) affect performance, when querying the
transaction
,
transactionline
, and
transactionaccountingline
tables. So, try re-ordering your JOINs in increasing levels of cardinality:
Copy code
FROM
    "TRANSACTION" T
    INNER JOIN transactionLine TL
        ON TL."TRANSACTION" = T."ID"
    INNER JOIN transactionaccountingline TAL
        ON T."ID" = TAL.transaction AND TL.ID = TAL.transactionline
(We originally had
transactionline
as the starting point too, fwiw) After reordering our query, the performance was back to expected levels, so hopefully this helps. fingers crossed
w
Thanks for the tip! I actually started our with the order that you're showing, but recently I switched to the other way around. In my case there is no difference in what order I put them in. I also tried to skip joins and just pull in the tables and then "make" the joins in the WHERE. This is how NS is doing when you extract the SQL from a workbook. But that didn't help either.
j
Dang, sorry to hear. I agree with others here that your best bet is probably to file a support ticket. 😕 If/when you do figure it out, please post back here because I’m really curious to hear about the resolution.