Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqKhJ-0001Hb-Al for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2019 17:05:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqKhI-0006Cc-0Z for pgsql-general@arkaria.postgresql.org; Wed, 24 Jul 2019 17:05:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hqKhH-00068h-Hu for pgsql-general@lists.postgresql.org; Wed, 24 Jul 2019 17:04:59 +0000 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hqKhE-0001T4-RG for pgsql-general@lists.postgresql.org; Wed, 24 Jul 2019 17:04:58 +0000 Received: from zimbra61-e11.priv.proxad.net (unknown [172.20.243.211]) by smtp4-g21.free.fr (Postfix) with ESMTP id 0744A19F4F3 for ; Wed, 24 Jul 2019 19:04:53 +0200 (CEST) Date: Wed, 24 Jul 2019 19:04:53 +0200 (CEST) From: gtreguier@free.fr To: pgsql-general@lists.postgresql.org Message-ID: <494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net> In-Reply-To: <590558932.-1717397096.1563987306958.JavaMail.root@zimbra61-e11.priv.proxad.net> Subject: Sequential scan with composite type in primary key MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [78.192.41.37] X-Mailer: Zimbra 7.2.0-GA2598 (ZimbraWebClient - SAF3 (Mac)/7.2.0-GA2598) X-Authenticated-User: gtreguier@free.fr List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, With this schema: CREATE TYPE item AS ( name text, date date ); CREATE TABLE item_comment ( item item, user_id text, comment text, CONSTRAINT item_comment_pk PRIMARY KEY (item, user_id) ); And this query: EXPLAIN SELECT * FROM item_comment WHERE item = ('', '2019-07-24'); -- OK: Bitmap Index Scan Postgresql uses the primary key index. But with this query: EXPLAIN SELECT * FROM item_comment WHERE (item).name = ''; -- KO: Seq Scan Postgresql does a full table scan. Should I inline the composite type ? CREATE TABLE item_comment ( name text, date date, user_id text, comment text, CONSTRAINT item_comment_pk PRIMARY KEY (name, date, user_id) ); Or is there a better way (without creating another index) ? Thanks.