Partial index question - Mailing list pgsql-general

From Anton Nikiforov
Subject Partial index question
Date
Msg-id 4090B013.6060002@nikiforov.ru
Whole thread Raw
Responses Re: Partial index question
Re: Partial index question
Re: Partial index question
List pgsql-general
Dear All,
I have a question about using partial indexes.
Lets say i have a table containing data types (table_datatype) and the
table containing data entrys (table_data).
While inserting into data entrys i have to number the entrys according
to it's type, so i always have to do
select max(id) from table_data where data_type=X;
And then insert a new value into the table data with this type and index.
Looks like there is no way to use sequences in this case without using
different tables that will make application not so clear.
But "my" way is not so clear also because i could get a collision while
concurrent inserts, so i have to control insertion from the application
and always check that it is unique.
So i'm planning to use partable indexes and hope they will help in
performance improving (the table data will contain millions of records
of each type so without indexing the performance will be not good and it
is not clear form me that it will be faster using complex index)
I know that i can do
create indexe ...... where type=X;
But is there any way to create all types of indexes at a time of
database creation without using triggers and creating indexes from it?
The matter is that data types are being added by the user, so i do not
know the indexes that i should create now.
And what will be faster?
CREATE UNIQUE INDEX type_index ON table_data (type, id);
or
CREATE UNIQUE INDEX type_1_index ON table_data (id) WHERE type=1;
CREATE UNIQUE INDEX type_X_index ON table_data (id) WHERE type=X;

--
Thanks in advance,
Best regads,
Anton Nikiforov


Attachment

pgsql-general by date:

Previous
From: Hervé Piedvache
Date:
Subject: Re: Postgre and Web Request
Next
From: Shridhar Daithankar
Date:
Subject: Re: Postgre and Web Request