question about index

From: Jerome Alet <alet(at)librelogiciel(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: question about index
Date: 2004-12-16 10:41:54
Message-ID: 20041216104154.GA30578@mail.librelogiciel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

For a future databas, I plan to have got a table with a text field
which can contain only three different values, say "VALUE1",
"VALUE2", and "VALUE3"

this table may have, over the course of one year, several million
rows for a size around 2 Gb or more.

I'd be interested in having :

SELECT count(*) AS nbvalue1 FROM mytable WHERE myfield='VALUE1';
SELECT count(*) AS nbvalue2 FROM mytable WHERE myfield='VALUE2';
SELECT count(*) AS nbvalue3 FROM mytable WHERE myfield='VALUE3';

be as fast as possible.

considering that almost 70% of the rows will be with 'VALUE1', 20%
will be with 'VALUE2' and 10% will be with 'VALUE3' on the average.

should I create an index to speedup the counts or not ?

any idea of the impact of running these three queries every 5 minutes
on say 10 000 000 rows ?

thanks in advance

Jerome Alet

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2004-12-16 11:01:39 Re: [despammed] question about index
Previous Message Roberto Fichera 2004-12-16 10:34:33 Query aid