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 1tVAwP-0067ms-Mo for pgsql-sql@arkaria.postgresql.org; Tue, 07 Jan 2025 14:52:22 +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 1tVAwP-004T7Q-0e for pgsql-sql@arkaria.postgresql.org; Tue, 07 Jan 2025 14:52:20 +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 1tVAwO-004T2M-NO for pgsql-sql@lists.postgresql.org; Tue, 07 Jan 2025 14:52:20 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVAwM-000LOd-11 for pgsql-sql@lists.postgresql.org; Tue, 07 Jan 2025 14:52:19 +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 507EqEw71468968; Tue, 7 Jan 2025 09:52:14 -0500 From: Tom Lane To: "Zornoza Sanchez, Jose Blas" cc: Tomasz Szypowski , "pgsql-sql@lists.postgresql.org" Subject: Re: View performance with implicit cast In-reply-to: References: <640397.1736015849@sss.pgh.pa.us> Comments: In-reply-to "Zornoza Sanchez, Jose Blas" message dated "Tue, 07 Jan 2025 07:43:48 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1468966.1736261534.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 07 Jan 2025 09:52:14 -0500 Message-ID: <1468967.1736261534@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Zornoza Sanchez, Jose Blas" writes: > Hello, in this case both index and view have the same name (test), try a= different one... Yeah. If you try the example as-presented it fails immediately: postgres=3D# create table foo (id int); CREATE TABLE postgres=3D# CREATE VIEW test AS SELECT * FROM foo; CREATE VIEW postgres=3D# CREATE INDEX test ON foo(id); ERROR: relation "test" already exists because you can't put a view named test and an index named test into the same schema. (They share the namespace of tables.) What I think the OP might have done is something similar to postgres=3D# create schema s1; CREATE SCHEMA postgres=3D# create schema s2; CREATE SCHEMA postgres=3D# set search_path to s1, s2; SET postgres=3D# create table s2.foo (id int); CREATE TABLE postgres=3D# CREATE VIEW test AS SELECT * FROM foo; CREATE VIEW postgres=3D# CREATE INDEX test ON foo(id); CREATE INDEX postgres=3D# DROP INDEX test; ERROR: "test" is not an index HINT: Use DROP VIEW to remove a view. View test is in schema s1, because that's the default creation schema with this search_path setting. But index test is in s2, because indexes are always put in the same schema as their parent table. So the CREATE INDEX doesn't fail. But then the DROP searches the search_path, and the first "test" it finds is the view s1.test, so it complains. regards, tom lane