Servoy setting limit on count queries

Questions and answers regarding general SQL and backend databases

Servoy setting limit on count queries

Postby j.kuizenga » Mon Aug 07, 2023 9:05 am

Hello, I have a question on why servoy is applying a LIMIT on the generated SQL for a count query
example
Code: Select all
00:01:01:974   6   00:10:329   Load foundset   

select count(distinct article.id) as n from article  left outer join article_group article_group on article.article_group_id=article_group.id and article_group.administration_id = ? left outer join article_main_group article_main_group on article_group.article_main_group_id=article_main_group.id and article_main_group.administration_id = ? where article.deleted = ? and article.vat != ? and article_group.id is not null and article_group.deleted = ? and article_main_group.id is not null and article_main_group.deleted = ? and article.deleted = ? and not exists (select article1.id from article article1 where article1.id not in (SELECT                 article1.id         FROM                 article article1         WHERE                 article1.deleted = false         AND     (                         article1.blocked = false                 OR      article1.blocked = true                 AND     (                                 im_blocked_month(article1.blocked_from) <= im_blocked_month(article1.blocked_to)                         AND     (                                         im_make_blocked_date(article1.blocked_from, 0) > im_now()                                 OR      im_make_blocked_date(article1.blocked_to, 0)   < im_now())                         OR      im_blocked_month(article1.blocked_from)        > im_blocked_month(article1.blocked_to)                         AND     im_make_blocked_date(article1.blocked_from, 0) > im_now()                         AND     im_make_blocked_date(article1.blocked_to, 0)   < im_now()))) and not exists (select article_price.article_id from article_price  where article_price.block_caused_by_supplier = ? and article_price.customer_id is not null and article_price.deleted = ? and article_price.blocked = ? and article_price.customer_id = ? and article_price.article_id = article1.id and (article_price.customer_id = ? or article_price.customer_id is null) and article_price.administration_id = ?) and article1.id = article.id and article1.administration_id = ?) and not exists (select article_price1.article_id from article_price article_price1 where article_price1.customer_id is not null and article_price1.deleted = ? and article_price1.blocked = ? and article_price1.customer_id = ? and article_price1.article_id = article.id and (article_price1.customer_id = ? or article_price1.customer_id is null) and article_price1.administration_id = ?) and exists (select article_price2.article_id from article_price article_price2 where article_price2.customer_id = ? and article_price2.blocked = ? and article_price2.article_id = article.id and (article_price2.customer_id = ? or article_price2.customer_id is null) and article_price2.administration_id = ?) and article_main_group.id = ANY(?) and article.extra != ? and article.administration_id = ? limit ?


As seen above this is a query generated by servoy to load the count of a foundset.
If i remove the limit from this query it goes from 10 seconds to 200ms and results in the same value. Postgres is not a big fan of LIMIT statements in a count query so i wonder what makes servoy do this and if this could be disabled.
j.kuizenga
 
Posts: 14
Joined: Wed Jul 13, 2022 10:03 am

Re: Servoy setting limit on count queries

Postby rgansevles » Fri Aug 11, 2023 9:31 am

I agree, the limit van be removed from the sql, the result will be the same.

Strange that the query optimizer does not see that.

If you create a feature request in the Servoy support system we will have a look.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 22 guests

cron