Re: BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: kingyzf(at)outlook(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
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
Date: 2020-04-18 13:36:17
Message-ID: 20200418133617.gs2yajumqf7q3m43@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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(at)outlook(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2020-04-19 07:07:08 BUG #16378: Invalid memory access on interrupting CLUSTER after CREATE TEMP TABLE
Previous Message PG Bug reporting form 2020-04-18 10:04:05 BUG #16377: select stuck when use order by and limit 1 if order-by-field has one index and result has no records