pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gtreguier@free.fr
To: pgsql-general@lists.postgresql.org
Subject: Sequential scan with composite type in primary key
Date: Wed, 24 Jul 2019 19:04:53 +0200 (CEST)
Message-ID: <494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net> (raw)
In-Reply-To: <590558932.-1717397096.1563987306958.JavaMail.root@zimbra61-e11.priv.proxad.net>

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.





Message-ID: <494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net>
Permalink:  ../494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net/
Also on:    postgresql.org/message-id/494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: gtreguier@free.fr
  Subject: Re: Sequential scan with composite type in primary key
  In-Reply-To: <494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net>
  References: <590558932.-1717397096.1563987306958.JavaMail.root@zimbra61-e11.priv.proxad.net> <494986266.-1717350093.1563987893717.JavaMail.root@zimbra61-e11.priv.proxad.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox