pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: Paul McGarry <paul@paulmcgarry.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Odd Choice of seq scan
Date: Thu, 1 Dec 2022 19:21:24 -0600
Message-ID: <20221202012124.GA14156@telsasoft.com> (raw)
In-Reply-To: <CAPrE0Sahe_J1R3iN1kfyFR1j7prXE-SaqH5rK5JG-u2ToAzUJA@mail.gmail.com>
References: <CAPrE0Sahe_J1R3iN1kfyFR1j7prXE-SaqH5rK5JG-u2ToAzUJA@mail.gmail.com>

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 FROM orderstotrans 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 FROM orderstotrans 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





view thread (6+ messages)  latest in thread

Message-ID: <20221202012124.GA14156@telsasoft.com>
Permalink:  ../20221202012124.GA14156@telsasoft.com/
Also on:    postgresql.org/message-id/20221202012124.GA14156@telsasoft.com

 · 

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-performance@postgresql.org
  Cc: pryzby@telsasoft.com, paul@paulmcgarry.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Odd Choice of seq scan
  In-Reply-To: <20221202012124.GA14156@telsasoft.com>

* 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