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 1uAM0Z-00EAh3-PG for pgsql-general@arkaria.postgresql.org; Thu, 01 May 2025 04:58:52 +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 1uAM0X-000p2b-Lz for pgsql-general@arkaria.postgresql.org; Thu, 01 May 2025 04:58:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uAM0X-000p2Q-Ad for pgsql-general@lists.postgresql.org; Thu, 01 May 2025 04:58:50 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uAM0W-000TzX-1I for pgsql-general@lists.postgresql.org; Thu, 01 May 2025 04:58:50 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso3684045e9.0 for ; Wed, 30 Apr 2025 21:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1746075527; x=1746680327; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=esraS/Qf7oLyIP14y4aFNrbHZmkEGvr/rWC/fGhmP/M=; b=lY/V1c2Uru4fLskRq9Jw5kGs/r4dUW8KrWYIrTlzgMn/45eUKsjCJigx2DmU9+c8rl ojPgYXPpudZZoyq3eRmeczvVIrsx7ZyqabimF11q33+WgcJmh8thegvY+q3txvt/8RlI ZVhVjzMvT0nrBhIILlNkBgzrrNxNPjzQxwKhi8s70+Y6COXzS0BBdKwNsvssBaYOakJ6 Lx7wHvBtokh7G2gYYpCeLfceqz1XTcH35RJAla+UbKa/SGTDQq5cxjbk3IhucAEPpfjF OQeyy3fiG9V1Hx6Lw8G/UCcbAqPmSWn7TB6BRCfaN5IyMTSwz9//O4CjHggx5J4NuaJ1 kTIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746075527; x=1746680327; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=esraS/Qf7oLyIP14y4aFNrbHZmkEGvr/rWC/fGhmP/M=; b=qenyADwF0uTGkhOMlJyQf4CFzbbnCEZfxtlKhM6LxxjVlUhewQE1cDywrW4FHiLTca txqovacVZu+fayHNyWGVbqovkfJMbhtibqQdLnXktpWxxjXi2RCknHfoUwz+LKUnNMPc KsTOJmUgbl4OCxatnTw7VRKiuzbVXNwNySIm2x2xi1YnpODb6RMuwlzcbzLiC5bmPEX3 VL3th5fMUH3foIrK+0GAauQiF9LLmQj42PKzUOZytF3qXcWmSdGJOuj2M/7nqOJ3sPX3 lT3sykVsKNXEu+bU09jFXm00ZZMywIXlJAqnKacS3GLoZ8v44sAsmCovOYagwPK6K6lT ifQw== X-Gm-Message-State: AOJu0YwSI2hYmMEo/pa0IZ5iJHHkLtVNMwHU/13rrZDvgFpZF8Q0OJeQ MoWrlmjBdAtJ61Ar3/kIWyRGY/bfORlPRGdXr6JywmUHY+0cwJmJGv99RBAeCKw= X-Gm-Gg: ASbGncu2UQrTsjAIFbC/XFq1LbT2SpjE58do5e2EgudqxfwXCYrp14rpcvukG0wBGPp AUdC2XeL3miNBf5r10saCNtZHnuE1serG5VCBxogcgQp/BfhJcf4VAT/rrUnA4BeSDS+w0w4cPO mW/9D7j5apSwbyug7gW9t/EfDrRD9wS/6zMBO1pXm1TE95Sfe74KaUv4BpT7OaWuEnzzWtNJjqS ZykeLZAOD7Xl3GAvXiDdZsPQn+myrikGHY2wxNxkzwiSRzlEwveLLK4+kqkp54JCBrSTm6y57vn 8B2/id2yx9P190C3cgTJsFW3l4sPT16a9mG5RKlPunyf9Eu4R6ngHx+Ry7VClw== X-Google-Smtp-Source: AGHT+IESMED9A0B54hyYcljvrN7887fO7Nl0Ol2oh34K0uAgPsjfjUlX4E5n7KTDaEn78/WX1mZzTA== X-Received: by 2002:a05:600c:820f:b0:43b:bfa7:c7d with SMTP id 5b1f17b1804b1-441b72b10dcmr7443495e9.2.1746075526945; Wed, 30 Apr 2025 21:58:46 -0700 (PDT) Received: from localhost.localdomain ([2001:871:260:68ef:ebd1:b5e2:5a9d:7c87]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b2bb5c6asm45589715e9.22.2025.04.30.21.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Apr 2025 21:58:46 -0700 (PDT) Message-ID: <91e617539ff887f1aac4e27bf1481b51fcf4b131.camel@cybertec.at> Subject: Re: Index not used in certain nested views but not in others From: Laurenz Albe To: Tom Lane , Markus Demleitner Cc: pgsql-general@lists.postgresql.org Date: Thu, 01 May 2025 06:58:45 +0200 In-Reply-To: <1400978.1746046929@sss.pgh.pa.us> References: <20250430151647.7kootztymzznydn5@victor> <1400978.1746046929@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2025-04-30 at 17:02 -0400, Tom Lane wrote: > Markus Demleitner writes: > > So, when the SELECT statement on dfbsspec.ssa stands along in the view > > definition, Postgres does the right thing; when the exact same query > > stands in a UNION ALL with other tables, Postgres doesn't use the > > index. Hu? >=20 > 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 > to see that the outer query's join operator is compatible with > the table's index. For a more detailed description of that problem, see https://www.cybertec-postgresql.com/en/union-all-data-types-performance/ Yours, Laurenz Albe