Re: Odd Choice of seq scan - Mailing list pgsql-performance

From Justin Pryzby
Subject Re: Odd Choice of seq scan
Date
Msg-id 20221202012124.GA14156@telsasoft.com
Whole thread Raw
In response to Odd Choice of seq scan  (Paul McGarry <paul@paulmcgarry.com>)
Responses Re: Odd Choice of seq scan
Re: Odd Choice of seq scan
List pgsql-performance
On Fri, Dec 02, 2022 at 11:52:19AM +1100, Paul McGarry wrote:
> Hi there,
> 
> I'm wondering if anyone has any insight into what might make the database
> choose a sequential scan for a query (table defs and plan below) like :

> Plan - seq scan of table:
> =====
> > explain select orders.orderid FROM orders WHERE (orders.orderid IN ('546111') OR orders.orderid IN  (select orderid
FROMorderstotrans WHERE (transid IN ('546111'))));
 

> Plan - Seq scan and filter of index:
> =====
> > explain select orders.orderid FROM orders WHERE (orders.orderid IN ('546111') OR orders.orderid IN  (select orderid
FROMorderstotrans WHERE (transid IN ('546111'))));
 

Could you show explain analyze ?

Show the size of the table and its indexes 
And GUC settings
And the "statistics" here:
https://wiki.postgresql.org/wiki/Slow_Query_Questions#Statistics:_n_distinct.2C_MCV.2C_histogram
Maybe on both a well-behaving instance and a badly-beving instance.

-- 
Justin



pgsql-performance by date:

Previous
From: Paul McGarry
Date:
Subject: Odd Choice of seq scan
Next
From: Ronuk Raval
Date:
Subject: Re: Odd Choice of seq scan