Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uEqHm-00DneK-T1 for pgsql-general@arkaria.postgresql.org; Tue, 13 May 2025 14:07:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uEqHl-005h6s-L4 for pgsql-general@arkaria.postgresql.org; Tue, 13 May 2025 14:07:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uETtQ-00GQX9-7Q for pgsql-general@lists.postgresql.org; Mon, 12 May 2025 14:12:32 +0000 Received: from relay.uni-heidelberg.de ([129.206.100.212]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uETtM-001R9B-0a for pgsql-general@lists.postgresql.org; Mon, 12 May 2025 14:12:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-heidelberg.de; i=@uni-heidelberg.de; q=dns/txt; s=s1; t=1747059149; x=1778595149; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=ihVumU/7XUbZuXnG7zhMwa+/H6QYaWUOCNoiJjVpf1U=; b=qzOBR2OMwGneciNHoHoe8s/hu/P9MSSKDauTZnxER+BQg5w73wcv2MA3 PB88C8c/+kMIqodIKR2y3ZFJ7n+0rtYYfLTSfzO+I9ku6KVp7Ion06LPj 0IN32yy3o2OKO6tX77rqZmYKx68iZ/yr7mJGJ924ihDW//fTIRz6HHtLD BCAEYvkwcio6lB3H7o52cZmNsbBPf8tfQBAKYDGEW107GB+WC7faXsShR ZSukpXMFgeg9CmgID1pN/i2ePaAMIiaSSauvn4W6V0FO8YGZzinfXSLrM dbYR7eGpQCKDMW/2j++0qUb9cIL0jRAIsauH9ZpYcicOn+tdnQ9qEbHWi A==; X-CSE-ConnectionGUID: zHBY3UQSRV+yDeMZcoZzsw== X-CSE-MsgGUID: fDzKnjg9REWzMWVPn+GA+Q== X-IPAS-Result: =?us-ascii?q?A2BUEAAQASJo/zlwzoFaHgEBCxIMQIFVgwE/gWWEVJApA?= =?us-ascii?q?QEBAQaBPgOLdIZZi12Bag8BAQEBAQEBAQEJRA0EAQGFBwKLSic4EwECBAEBA?= =?us-ascii?q?QEDAgMBAQEBAQEBAQ4BAQYBAQEBAQcFgSGFew1JARABhgABBSNmCxgCAiYCA?= =?us-ascii?q?laDHIIiAQEBAUUUsW+BMoEBg2xB2gmBaAaBGy6IUAGGB4RcQn2BEIEVgnkxP?= =?us-ascii?q?oJhAYEngQeDDoJpBIItRFKeW1J7HANZLAFLChMXCwcFOW1DA4EPIw88BS4KE?= =?us-ascii?q?4EHgQaBV4NCghGBXAMDIgGDE3MchGOERytPgySBfkwZP4FWMUADC209NxQbB?= =?us-ascii?q?pclGoNlaEkQaB0TLYEjxjGCP4FmijmBYZUzTROXQpMFmQCOBpsvgX6BfnEUg?= =?us-ascii?q?yJSGQ+SIYUTv3p2AjoCBwsBAQMJjWKDRWABAQ?= IronPort-Data: A9a23:Q7xEMaoHtHt6057qyWciRSWBhqFeBmIQZRIvgKrLsJaIsI4StFCzt garIBnXOvjbMGugKYt+O9mx9BhVsJXXzNdrGVQ4/3tnQihHpePIVI+TRqvSF3rPcZeTEh4PA +byyDXkBJppJpMJjk71atANlVEliOfQAOC6ULWYUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tqaT/f3YDdJ4BYqdDtJg06/gEk35qmq5WpC5gVWic1j5TcyqVFEVPrzGonsdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAazsAG6ZvXAdJHAathZ5VlqPgqo DlFncTYpQ7EpcQgksxFO/VTO3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9cKHw0cUI1dZcmzffU1BryTRzUj7Yi8K0YPnsQ?= =?us-ascii?q?8lvaWEBNOAzHeox30e9py?= X-IronPort-Anti-Spam-Filtered: true Received: from alnilam.zah.uni-heidelberg.de (HELO alnilam2.ari.uni-heidelberg.de) ([129.206.112.57]) by relay.uni-heidelberg.de with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2025 16:12:23 +0200 Received: from submit by alnilam2.ari.uni-heidelberg.de with local (Exim 4.96) (envelope-from ) id 1uETtH-00066C-0b for pgsql-general@lists.postgresql.org; Mon, 12 May 2025 16:12:23 +0200 Date: Mon, 12 May 2025 16:12:17 +0200 From: Markus Demleitner To: pgsql-general@lists.postgresql.org Subject: Re: Index not used in certain nested views but not in others Message-ID: <20250512141217.4dwnfxbaf53mhvi7@victor> References: <20250430151647.7kootztymzznydn5@victor> <1400978.1746046929@sss.pgh.pa.us> <91e617539ff887f1aac4e27bf1481b51fcf4b131.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <91e617539ff887f1aac4e27bf1481b51fcf4b131.camel@cybertec.at> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dear Tom, Dear Laurenz, Thanks for your pointers -- that was already helpful. On Thu, May 01, 2025 at 06:58:45AM +0200, Laurenz Albe wrote: > On Wed, 2025-04-30 at 17:02 -0400, Tom Lane wrote: > > It's hard to be sure when you've shown us no table definitions and > > only fragments of the view definitions. But I suspect what is > > happening here is that the view's UNIONs are causing a data type > > coercion of raw_spectra.pub_did before it gets to the top level > > of the view output. That might interfere with the planner's ability > > For a more detailed description of that problem, see > https://www.cybertec-postgresql.com/en/union-all-data-types-performance/ I've puzzled over this for a while, and while I'm sure the type mixing is what kills the index usage here, I've been unable to actually pinpoint where that happens. You see, when creating the "big", 30-tables view, I do cast all columns to common types in the view statement that actually make up the view. The original SQL fragments look like this: SELECT CAST(ssa_dstype AS text) AS dataproduct_type, CAST(NULL AS text) AS dataproduct_subtype, CAST(2 AS smallint) AS calib_level, ... and have a common source, so I'd believe by the time the things end up in the view, they should type-align even though their source tables do not. Wouldn't that be good enough for the planner at least in the case of the "unreleated", non-constrained columns? In the meantime, I've dumped the minimal number of table definitions involved to https://docs.g-vo.org/tabledefs.txt -- I apologise for the mess, but at least it's stripped down to just two tables of the original 30-tables join. For type incongruencies in the *source* tables, you could look at accsize, which is integer vs. bigint (that would be enough to kill index use, right?), but as you can see postgres gets the cast in the k2c9vst leg of the obscore view (the no-op casts in the view creation aren't shown by postgres). Well, "can see"... ahem. I don't think I'm asking anyone to have a look at tabledefs.txt; but what I'd really be grateful for would be some trick that might guide me to the point where the planner actually decides it can't use the index, i.e., which column stops it). Is there such a thing, short of gdb-ing within pull_up_subqueries_recurse? Thanks, Markus