agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Marc Mamin <M.Mamin@intershop.de>
To: Yambu <hyambu@gmail.com>
To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
Subject: RE: Index creation
Date: Tue, 25 May 2021 09:44:00 +0000
Message-ID: <bd8a29930e7848d3b0ee9b6d93e2b3f7@intershop.de> (raw)
In-Reply-To: <CALhHtcCO=nBCBRMJfx_s9dGMwPRoH+GmBQSC2X8bGgGLE-OA6A@mail.gmail.com>
References: <CALhHtcCO=nBCBRMJfx_s9dGMwPRoH+GmBQSC2X8bGgGLE-OA6A@mail.gmail.com>

Hi,

beside the other comments,  you may try to rework your query to reduce the OR clauses which rise the uncertainty for the planner.


e.g.:

SELECT
    *
FROM
    table_name
WHERE code_id IN ( 1, 2)

UNION

SELECT
    *
FROM
    table_name
WHERE  (code_id = 3 AND created_date < now())
LIMIT 1



From: Yambu [mailto:hyambu@gmail.com]
Sent: Montag, 24. Mai 2021 05:42
To: pgsql-sql@lists.postgresql.org
Subject: Index creation

hello people, I would like to create an index so that the query on here can use it,


SELECT

    *

FROM

    table_name

WHERE (code_id = 1

    OR code_id = 2

    OR (code_id = 3

        AND created_date < now()))
LIMIT 1;

please advise me on how I should create index. I created index on code_id but it's not being used


view thread (7+ messages)  latest in thread

Message-ID: <bd8a29930e7848d3b0ee9b6d93e2b3f7@intershop.de>
Permalink:  ../bd8a29930e7848d3b0ee9b6d93e2b3f7@intershop.de/
Also on:    postgresql.org/message-id/bd8a29930e7848d3b0ee9b6d93e2b3f7@intershop.de

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: M.Mamin@intershop.de, hyambu@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: RE: Index creation
  In-Reply-To: <bd8a29930e7848d3b0ee9b6d93e2b3f7@intershop.de>

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

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