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 1jjxSE-00052P-Rf for pgsql-performance@arkaria.postgresql.org; Sat, 13 Jun 2020 04:07:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjxSD-00069P-PS for pgsql-performance@arkaria.postgresql.org; Sat, 13 Jun 2020 04:07:37 +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 1jjxSD-00069I-II for pgsql-performance@lists.postgresql.org; Sat, 13 Jun 2020 04:07:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjxSB-0005mS-DV for pgsql-performance@postgresql.org; Sat, 13 Jun 2020 04:07:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05D47XGq800753; Sat, 13 Jun 2020 00:07:33 -0400 From: Tom Lane To: David Rowley cc: regrog , pgsql-performance Subject: Re: view reading information_schema is slow in PostgreSQL 12 In-reply-to: References: <1591975278775-0.post@n3.nabble.com> <798686.1592017869@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Sat, 13 Jun 2020 15:55:46 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <800751.1592021253.1@sss.pgh.pa.us> Date: Sat, 13 Jun 2020 00:07:33 -0400 Message-ID: <800752.1592021253@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley writes: > On Sat, 13 Jun 2020 at 15:11, Tom Lane wrote: >> I expect you're getting a fairly decent estimate for the "contype <> >> ALL" condition, but the planner has no idea what to make of the CASE >> construct, so it just falls back to a hard-wired default estimate. > This feels quite similar to [1]. Yeah, it's the same thing. As I commented in that thread, I'd seen applications of the idea in information_schema views -- it's the same principle of a view exposing a CASE construct that translates a catalog column to what the SQL spec says should be returned, and then the calling query trying to constrain that output. > I wondered if it would be more simple to add some smarts to look a bit > deeper into case statements for selectivity estimation purposes. An > OpExpr like: > CASE c.contype WHEN 'c' THEN 'CHECK' WHEN 'f' THEN 'FOREIGN KEY' WHEN > 'p' THEN 'PRIMARY KEY' WHEN 'u' THEN 'UNIQUE' END = 'CHECK'; Hm. Maybe we could reasonably assume that the equality operators used for such constructs are error-and-side-effect-free, thus dodging the semantic problem I mentioned in the other thread? regards, tom lane