pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records
2+ messages / 2 participants
[nested] [flat]
* BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records
@ 2020-04-18 10:04 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2020-04-18 10:04 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: kingyzf@outlook.com
The following bug has been logged on the website:
Bug reference: 16377
Logged by: Yunfeng Wang
Email address: kingyzf@outlook.com
PostgreSQL version: 11.6
Operating system: Centos 7.6
Description:
select stuck when use order by and limit 1 if order-by-field has one
index:
and possibility is high if result has no records, otherwise possibility is
low;
if no "limit 1" or no index on column pay_date, no problem;
sql:
select * from
(select ( case when pre_pay is null then 0 else pre_pay end ) as "PRE_PAY"
from inpatientprepay
where cancel='0'
and ehrid=4
order by pay_date desc
) as t
limit 1
;
other info: the inpatientprepay table has nine million records, I think
it's stuck because if no limit 1 ,speed is ok;
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records
@ 2020-04-18 13:36 Tomas Vondra <tomas.vondra@2ndquadrant.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Tomas Vondra @ 2020-04-18 13:36 UTC (permalink / raw)
To: kingyzf@outlook.com; pgsql-bugs@lists.postgresql.org
Hi,
On Sat, Apr 18, 2020 at 10:04:05AM +0000, PG Bug reporting form wrote:
>The following bug has been logged on the website:
>
>Bug reference: 16377
>Logged by: Yunfeng Wang
>Email address: kingyzf@outlook.com
>PostgreSQL version: 11.6
>Operating system: Centos 7.6
>Description:
>
>select stuck when use order by and limit 1 if order-by-field has one
>index:
>and possibility is high if result has no records, otherwise possibility is
>low;
>if no "limit 1" or no index on column pay_date, no problem;
>
>sql:
>select * from
>(select ( case when pre_pay is null then 0 else pre_pay end ) as "PRE_PAY"
>
>from inpatientprepay
>where cancel='0'
>and ehrid=4
>order by pay_date desc
>) as t
>limit 1
>;
>other info: the inpatientprepay table has nine million records, I think
>it's stuck because if no limit 1 ,speed is ok;
>
I think we need to see execution plans for both queries.
Also, when you say "stuck" what does that mean? Does it mean it's
waiting on a lock, or is it doing something but not producing results?
Or what?
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-04-18 13:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 10:04 BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records PG Bug reporting form <noreply@postgresql.org>
2020-04-18 13:36 ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox