pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedIndexing a boolean
5+ messages / 5 participants
[nested] [flat]
* Indexing a boolean
@ 2003-08-21 20:47 Kris Kiger <kris@musicrebellion.com>
2003-08-21 21:13 ` Re: Indexing a boolean Bruno Wolff III <bruno@wolff.to>
2003-08-21 22:48 ` Re: Indexing a boolean scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 2 replies; 5+ messages in thread
From: Kris Kiger @ 2003-08-21 20:47 UTC (permalink / raw)
To: pgsql-admin
I would appreciate it if I could get some thoughts on indexing a field
with only two values? For example, I have a table with a few million
rows in it. All items in this table are broken up into two categories
using 'T' or 'F'. It seems logical to me that an index on this field
would create two logical 'buckets', so that one could say, "I want all
'T' values", or "I want all 'F' values" and merely have to look in the
appropriate bucket, rather than have to perform a sequential scan
through three million items every time a request is made based on 'T' or
'F'. If I were to create an index on a char(1) field that contains only
values of 'T' or 'F', would the query analyzer override the use of this
index? How does Postgres address this problem and what are all of your
thoughts on this issue? I appreciate the help!
Kris
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Indexing a boolean
2003-08-21 20:47 Indexing a boolean Kris Kiger <kris@musicrebellion.com>
@ 2003-08-21 21:13 ` Bruno Wolff III <bruno@wolff.to>
1 sibling, 0 replies; 5+ messages in thread
From: Bruno Wolff III @ 2003-08-21 21:13 UTC (permalink / raw)
To: Kris Kiger <kris@musicrebellion.com>; +Cc: pgsql-admin
On Thu, Aug 21, 2003 at 15:47:39 -0500,
Kris Kiger <kris@musicrebellion.com> wrote:
> I would appreciate it if I could get some thoughts on indexing a field
> with only two values? For example, I have a table with a few million
> rows in it. All items in this table are broken up into two categories
> using 'T' or 'F'. It seems logical to me that an index on this field
> would create two logical 'buckets', so that one could say, "I want all
> 'T' values", or "I want all 'F' values" and merely have to look in the
> appropriate bucket, rather than have to perform a sequential scan
> through three million items every time a request is made based on 'T' or
> 'F'. If I were to create an index on a char(1) field that contains only
> values of 'T' or 'F', would the query analyzer override the use of this
> index? How does Postgres address this problem and what are all of your
> thoughts on this issue? I appreciate the help!
You probably don't want to use an index unless one of the two values
is much more common than the other. In that case you want to use a partial
index on the rare condition.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Indexing a boolean
2003-08-21 20:47 Indexing a boolean Kris Kiger <kris@musicrebellion.com>
@ 2003-08-21 22:48 ` scott.marlowe <scott.marlowe@ihs.com>
2003-08-23 04:14 ` Re: Indexing a boolean Renney Thomas <renneyt@yahoo.com>
1 sibling, 1 reply; 5+ messages in thread
From: scott.marlowe @ 2003-08-21 22:48 UTC (permalink / raw)
To: Kris Kiger <kris@musicrebellion.com>; +Cc: pgsql-admin
On Thu, 21 Aug 2003, Kris Kiger wrote:
> I would appreciate it if I could get some thoughts on indexing a field
> with only two values? For example, I have a table with a few million
> rows in it. All items in this table are broken up into two categories
> using 'T' or 'F'. It seems logical to me that an index on this field
> would create two logical 'buckets', so that one could say, "I want all
> 'T' values", or "I want all 'F' values" and merely have to look in the
> appropriate bucket, rather than have to perform a sequential scan
> through three million items every time a request is made based on 'T' or
> 'F'. If I were to create an index on a char(1) field that contains only
> values of 'T' or 'F', would the query analyzer override the use of this
> index? How does Postgres address this problem and what are all of your
> thoughts on this issue? I appreciate the help!
Often the best approach here is to make a partial index:
create index table_dx on table (bool_field) where bool_field IS TRUE;
This works well if you have a large portion of the boolean fields set to
FALSE, and want to find the few that are TRUE. Reverse the TRUE and false
for other situations.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Indexing a boolean
2003-08-21 20:47 Indexing a boolean Kris Kiger <kris@musicrebellion.com>
2003-08-21 22:48 ` Re: Indexing a boolean scott.marlowe <scott.marlowe@ihs.com>
@ 2003-08-23 04:14 ` Renney Thomas <renneyt@yahoo.com>
2003-08-27 02:02 ` Re: Indexing a boolean Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Renney Thomas @ 2003-08-23 04:14 UTC (permalink / raw)
To: ; +Cc: pgsql-admin
scott.marlowe wrote:
>On Thu, 21 Aug 2003, Kris Kiger wrote:
>
>
>>I would appreciate it if I could get some thoughts on indexing a field
>>with only two values? For example, I have a table with a few million
>>
>>Often the best approach here is to make a partial index:
>>
>>create index table_dx on table (bool_field) where bool_field IS TRUE;
>>
>>This works well if you have a large portion of the boolean fields set to
>>FALSE, and want to find the few that are TRUE. Reverse the TRUE and false
>>for other situations.
>>
>>
>>
When will PGSql have bitmapped indexes for these cases - like Oracle?
Will it be in a release sometime soon?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Indexing a boolean
2003-08-21 20:47 Indexing a boolean Kris Kiger <kris@musicrebellion.com>
2003-08-21 22:48 ` Re: Indexing a boolean scott.marlowe <scott.marlowe@ihs.com>
2003-08-23 04:14 ` Re: Indexing a boolean Renney Thomas <renneyt@yahoo.com>
@ 2003-08-27 02:02 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Bruce Momjian @ 2003-08-27 02:02 UTC (permalink / raw)
To: Renney Thomas <renneyt@yahoo.com>; +Cc: pgsql-admin
Renney Thomas wrote:
> scott.marlowe wrote:
>
> >On Thu, 21 Aug 2003, Kris Kiger wrote:
> >
> >
> >>I would appreciate it if I could get some thoughts on indexing a field
> >>with only two values? For example, I have a table with a few million
> >>
>
> >>Often the best approach here is to make a partial index:
> >>
> >>create index table_dx on table (bool_field) where bool_field IS TRUE;
> >>
> >>This works well if you have a large portion of the boolean fields set to
> >>FALSE, and want to find the few that are TRUE. Reverse the TRUE and false
> >>for other situations.
> >>
> >>
> >>
>
> When will PGSql have bitmapped indexes for these cases - like Oracle?
> Will it be in a release sometime soon?
Uh, we really don't know --- when someone codes it. We do have
/contrib/intarray, which might help.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-08-27 02:02 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-21 20:47 Indexing a boolean Kris Kiger <kris@musicrebellion.com>
2003-08-21 21:13 ` Bruno Wolff III <bruno@wolff.to>
2003-08-21 22:48 ` scott.marlowe <scott.marlowe@ihs.com>
2003-08-23 04:14 ` Renney Thomas <renneyt@yahoo.com>
2003-08-27 02:02 ` Bruce Momjian <pgman@candle.pha.pa.us>
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