Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0ul7-0007RE-AK for pgsql-performance@arkaria.postgresql.org; Fri, 02 Dec 2022 01:22:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0uk7-0006Ev-A0 for pgsql-performance@arkaria.postgresql.org; Fri, 02 Dec 2022 01:21:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0uk6-0006Ek-PF for pgsql-performance@lists.postgresql.org; Fri, 02 Dec 2022 01:21:30 +0000 Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p0uk3-0001NO-5U for pgsql-performance@lists.postgresql.org; Fri, 02 Dec 2022 01:21:29 +0000 Received: by mail-qt1-x832.google.com with SMTP id fp23so3057705qtb.0 for ; Thu, 01 Dec 2022 17:21:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Wo8suwX+WO/3fwmEiXVo+y91x07owCvdvjiV1ZnwkII=; b=isPK4G4MOUdwngQ9adpuIg4Lr2H3RU2TAkdgWWTxNdZ5MMPr2CuZ7l6x2iF8CY/QhL Iz3SAsSgXgd2J9SFaY3t45xDJ94SH4bwVtdavW7GnQ6+pw6m7o7ZAMqpT2OdcWfcbwKf /8S/V1ADiczASwmPwmP4YU+lkqMTZtfJB99rwMBtDRW/LdlilwBMbJN0P4zsRKqAxXhQ QPOZ3pgPPYi9attgHXTHxqZUuGBO+JujxYoWvwP5bomRAnLCYMckQ1j30nA2T97zqaJp vmeb/wU53oSZ77l6y5MhFXjbcVuT0Uy3dkC8DIPMC0uA2sLi/cWGCFZ0zNhBeYHbHsj+ WkfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wo8suwX+WO/3fwmEiXVo+y91x07owCvdvjiV1ZnwkII=; b=WrQEakujswZCDcrptC6EXYUsD3iyAn4m5MhaW/5SwiOGSKNvphmreQp1dNiVY4dz+U rKwYdqLdeylPWlnwU6bhBeYA/BF1sdek7GtP88iO3539coTGLx1kESIJelNfaOWZesak YFE1Su7/EtKwjFqSYluWyLs50vOgWyRcu0sK77LPP+rxs1SpK3P7iy3JvPVnxLdLqKjU baC0j+ggUZMn0kZUFyWLAiuOzjj9aw7NbM2jwmHcNmfntH70sn7Fs59m2U22fcBhSZPX KCsl4e9P43pRbUwsiBpF9urioXKjnQoVNKBtUsa22ARf2omsYam/eGsUCH8Yf1B/bvPn BjZg== X-Gm-Message-State: ANoB5pn/t38zfSKRYMG+cJC0lff7hEDtOdIiSBm6rqDETwwTMJQGPddJ MNCTMWX/WUlugRypNGnXcUFc34Aed/3Wdw== X-Google-Smtp-Source: AA0mqf5l+7DtsHR7qypc19iALhliGFMYhCitpecQ7PZFojFwGuxBsQvKR5QCYIQlwG6WoCTBqiHksA== X-Received: by 2002:a05:620a:1321:b0:6fc:ae10:ed37 with SMTP id p1-20020a05620a132100b006fcae10ed37mr2071332qkj.785.1669944086266; Thu, 01 Dec 2022 17:21:26 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h4-20020a05620a284400b006cfc7f9eea0sm4490247qkp.122.2022.12.01.17.21.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2022 17:21:25 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id CC071800DAF; Thu, 1 Dec 2022 19:21:24 -0600 (CST) Date: Thu, 1 Dec 2022 19:21:24 -0600 From: Justin Pryzby To: Paul McGarry Cc: pgsql-performance@lists.postgresql.org Subject: Re: Odd Choice of seq scan Message-ID: <20221202012124.GA14156@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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