dbTalk Databases Forums  

Better index

comp.databases.postgresql comp.databases.postgresql


Discuss Better index in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paolo Holzl
 
Posts: n/a

Default Better index - 03-20-2008 , 07:31 AM






Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?

The creation of an index on a large table can ask for time, how I make
understand if ended?

Thaks' a lot
--


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM






Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #8  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Better index - 03-21-2008 , 05:51 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
Table AAA

ID (PrimaryKey)
Progres (Integer)
DateAndTime (datetime)
xxx (Integer)

to execute this select on a big table
SELECT ID,Progres WHERE Progres=243 AND Date(DateAndTime) > '11-02-2008'

For performance ..
Is better create an index on Progres ?
Is better create an index on Progres and DateTime ?
Is it equal ?
That depends on the distribution of the data.

If there are only three rows in the table where progres=243, the best index
would be:
CREATE INDEX a_index ON aaa(progres);

If half the rows in the table have progres=243, but only few rows
have date(dateandtime) > date('11-02-2008'), the following index would help:
CREATE INDEX b_index ON aaa(date(dateandtime));

If, however, half of your table rows have progres=243 and all rows have
date(dateandtime) > date('11-02-2008'), no concievable index can speed
up your query and the best thing for the planner to do is a sequential
table scan.

You see, the correct index to speed up a query depends
a) on the data in the table and
b) on the constants in the query

Quote:
The creation of an index on a large table can ask for time, how I make
understand if ended?
CREATE INDEX is synchronous, that is, the command will "hang" until it
is done. Once the command returns, the index is created.

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.