PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16377
PG Version11.6
OSCentos 7.6
Opened2020-04-18 10:04:05+00
Reported byYunfeng Wang
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16377
Logged by:          Yunfeng Wang
Email address:      (redacted)
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;

Messages

DateAuthorSubject
2020-04-18 10:04:05+00PG Bug reporting formBUG #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:17+00Tomas VondraRe: BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records