pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedMultiple Indexes
4+ messages / 4 participants
[nested] [flat]
* Multiple Indexes
@ 2001-07-02 15:38 dennis@zserve.com <dennis@zserve.com>
2001-07-02 16:27 ` Re: Multiple Indexes Peter Eisentraut <peter_e@gmx.net>
0 siblings, 1 reply; 4+ messages in thread
From: dennis@zserve.com @ 2001-07-02 15:38 UTC (permalink / raw)
To: pgsql-general
Hi Group,
Lets say table a has fields: id serial, name varchar(20) not null, and
somedata int not null.
I'll be doing lots of queries on this table so I'll want to define and
index. ( or two? ).
Some queries will only look up the name. Others will look up the name
depending on somedata.
If I were to define and index like this:
1) create index i on sometable ( name, somedata );
and another one like this:
2) create index i2 on sometable ( name );
Would that be better than defining only the first index?
What I am asking is:
Should I have an index devoted to just the name field, or
would that first index work just fine? I know that more indexes
means slower time on inserts.
Any suggestions appreciated.
-Dennis
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Multiple Indexes
2001-07-02 15:38 Multiple Indexes dennis@zserve.com <dennis@zserve.com>
@ 2001-07-02 16:27 ` Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2001-07-02 16:27 UTC (permalink / raw)
To: dennis@zserve.com <dennis@zserve.com>; +Cc: pgsql-general
dennis@zserve.com writes:
> If I were to define and index like this:
>
> 1) create index i on sometable ( name, somedata );
>
> and another one like this:
>
> 2) create index i2 on sometable ( name );
>
> Would that be better than defining only the first index?
While this kind of question is generally best answered through
experimentation and analysis of the actual query load, note that this
combination of indexes would be quite useless, because queries on "name"
could very well use the (name, somedata) index.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
^ permalink raw reply [nested|flat] 4+ messages in thread
* Multiple Indexes
@ 2022-07-06 16:06 DAVID ROTH <adaptron@comcast.net>
2022-07-06 18:53 ` Re: Multiple Indexes David Rowley <dgrowleyml@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: DAVID ROTH @ 2022-07-06 16:06 UTC (permalink / raw)
To: pgsql-general
I understand the planner can use multiple indexes to get the best plan.
Can someone point me a paper that explains how this works.
Thanks
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Multiple Indexes
2022-07-06 16:06 Multiple Indexes DAVID ROTH <adaptron@comcast.net>
@ 2022-07-06 18:53 ` David Rowley <dgrowleyml@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: David Rowley @ 2022-07-06 18:53 UTC (permalink / raw)
To: DAVID ROTH <adaptron@comcast.net>; +Cc: pgsql-general
On Thu, 7 Jul 2022 at 04:07, DAVID ROTH <adaptron@comcast.net> wrote:
> I understand the planner can use multiple indexes to get the best plan.
> Can someone point me a paper that explains how this works.
I don't know of a paper, but if you're talking about using multiple
indexes to scan a single relation in order to satisfy a condition such
as; WHERE a = 5 OR b = 12; then the query planner is able to make use
of "bitmap index scans". A bitmap index scan simply scans an index
type which supports such scans and collects a set of ctids. For this
example, providing there's a suitable index on the "a" column and
another on the "b" column, the planner may choose to perform a bitmap
index scan on the "a" index and another on the "b" index then perform
a bitmap OR operation to obtain the intersecting ctids. The heap of
the table can then be scanned to fetch the intersecting ctids.
A ctid is the physical (more physiological) address of a tuple the
heap of a table.
David
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2022-07-06 18:53 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-07-02 15:38 Multiple Indexes dennis@zserve.com <dennis@zserve.com>
2001-07-02 16:27 ` Peter Eisentraut <peter_e@gmx.net>
2022-07-06 16:06 Multiple Indexes DAVID ROTH <adaptron@comcast.net>
2022-07-06 18:53 ` David Rowley <dgrowleyml@gmail.com>
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