pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kingyzf@outlook.com
Subject: BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records
Date: Sat, 18 Apr 2020 10:04:05 +0000
Message-ID: <16377-86af0a40aa096b0d@postgresql.org> (raw)

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;



view thread (2+ messages)  latest in thread

Message-ID: <16377-86af0a40aa096b0d@postgresql.org>
Permalink:  ../16377-86af0a40aa096b0d@postgresql.org/
Also on:    postgresql.org/message-id/16377-86af0a40aa096b0d@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, kingyzf@outlook.com
  Subject: Re: BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records
  In-Reply-To: <16377-86af0a40aa096b0d@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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