Openbravo Issue Tracking System - Retail Modules
View Issue Details
0029543Retail ModulesWeb POSpublic2015-04-09 10:222015-06-29 19:17
mtaal 
aaroncalero 
urgentmajorhave not tried
closedfixed 
5
 
RR15Q3RR15Q3 
migueldejuana
No
0029543: slow query for orders
While doing a system sizing guideline a slow query in WebPOS was encountered (on the server) which was particurarly slow, and easy to make faster [1].

Several things where noted:
- several queries are fired after eachother, so there seems to be no delay while the user types (so not related to the sql, but still wanted to mention it)
- the query has 2 like clauses, only the one replacing the \ is enough
- like clauses with a percentage as a start will never use an index
- where clauses with functions will never use an index (hopefully as part of the store server project this can be changed)
- this subquery showed to have a great impact:
(select count(orderlinel3_.QtyDelivered) from C_OrderLine orderlinel3_ where order0_.C_Order_ID=orderlinel3_.C_Order_ID and orderlinel3_.QtyDelivered<>0)>0
changing it to:
exists (select 1 from C_OrderLine orderlinel3_ where order0_.C_Order_ID=orderlinel3_.C_Order_ID and orderlinel3_.QtyDelivered<>0)
makes it the whole query more than 10 times faster! The query went from 6.5 seconds to 500 millis
- also there are 2 count subqueries, would only querying on delivered quantity be enough?

I will enter an issue for it.

gr. Martin

[1]
2015-04-08 16:01:17 CAT [1339-81] tad_halsteds@halsted_live LOG: duration: 6652.366 ms execute <unnamed>: select order0_.C_Order_ID as col_0_0_, order0_.DocumentNo as col_1_0_, order0_.DateOrdered as col_2_0_, businesspa1_.Name as col_3_0_, order0_.GrandTotal as col_4_0_, order0_.C_DocType_ID as col_5_0_, 'false' as col_6_0_ from C_Order order0_, C_BPartner businesspa1_ where order0_.C_BPartner_ID=businesspa1_.C_BPartner_ID and order0_.AD_Client_ID='7B27EAB5E42841E0A0957AF0B16CCB3B' and order0_.AD_Org_ID='2D164FEBDD474277B5AE9858AD9CBA01' and (order0_.EM_Obpos_Applications_ID is not null) and (order0_.DocumentNo like '%B42%' or REPLACE(order0_.DocumentNo, '/', '') like '%B42%' or upper(businesspa1_.Name) like upper('%B42%')) and (order0_.C_DocType_ID='040B0B064AE54A848954C34D902F36D9' or order0_.C_DocType_ID='ABECD2CF89A64FDF90F9B7180FDAD44B') and (select count(orderlinel3_.QtyDelivered) from C_OrderLine orderlinel3_ where order0_.C_Order_ID=orderlinel3_.C_Order_ID and orderlinel3_.QtyDelivered<>0)>0 and (select count(orderlinel4_.QtyOrdered) from C_OrderLine orderlinel4_ where order0_.C_Order_ID=orderlinel4_.C_Order_ID and orderlinel4_.QtyOrdered>0)>0 order by order0_.DateOrdered desc, order0_.DocumentNo desc limit $1
2015-04-08 16:01:17 CAT [1339-82] tad_halsteds@halsted_live DETAIL: parameters: $1 = '300'
[22:35:34] Stefan Huehner: 6.6s: grid query ilike %b42%
In webpos search for existing tickets (preferably on a large database).
Performance
depends on backport 0030284RR15Q2.3 closed aaroncalero slow query for orders 
Issue History
2015-04-09 10:22mtaalNew Issue
2015-04-09 10:22mtaalAssigned To => mtaal
2015-04-09 10:22mtaalTriggers an Emergency Pack => No
2015-04-13 18:00shuehnerTag Attached: Performance
2015-04-23 17:46jonalegriaesarteResolution time => 1432332000
2015-04-23 17:46jonalegriaesartePrioritynormal => urgent
2015-04-28 15:55shuehnerIssue Monitored: shuehner
2015-05-26 17:47aaroncaleroAssigned Tomtaal => aaroncalero
2015-05-28 15:25hgbotCheckin
2015-05-28 15:25hgbotNote Added: 0077870
2015-05-28 15:25hgbotStatusnew => resolved
2015-05-28 15:25hgbotResolutionopen => fixed
2015-05-28 15:25hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/20a372dba994513e44898a291186d87fca31174c [^]
2015-06-01 18:19migueldejuanaReview Assigned To => migueldejuana
2015-06-01 18:19migueldejuanaNote Added: 0077953
2015-06-01 18:19migueldejuanaStatusresolved => closed
2015-06-01 18:19migueldejuanaFixed in Version => RR15Q3
2015-06-29 19:17marvintmStatusclosed => new
2015-06-29 19:17marvintmResolutionfixed => open
2015-06-29 19:17marvintmFixed in VersionRR15Q3 =>
2015-06-29 19:17marvintmStatusnew => scheduled
2015-06-29 19:17marvintmStatusscheduled => resolved
2015-06-29 19:17marvintmResolutionopen => fixed
2015-06-29 19:17marvintmStatusresolved => closed
2015-06-29 19:17marvintmFixed in Version => RR15Q3

Notes
(0077870)
hgbot   
2015-05-28 15:25   
Repository: erp/pmods/org.openbravo.retail.posterminal
Changeset: 20a372dba994513e44898a291186d87fca31174c
Author: Aaron Calero <aaron.calero <at> openbravo.com>
Date: Thu May 28 10:17:40 2015 +0200
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.posterminal/rev/20a372dba994513e44898a291186d87fca31174c [^]

Fixed issue 29543: slow query for orders

Replaced two count subqueries with exist subqueries

---
M src/org/openbravo/retail/posterminal/PaidReceiptsHeader.java
---
(0077953)
migueldejuana   
2015-06-01 18:19   
Tested and reviewed in a5c25afa2d03