|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi everybody,
I new on this forum and cannot find anything related with this issue. My problem is following: I have a table: CREATE TABLE rights ( userid integer not null REFERENCES user(userid), fishid integer not null REFERENCES fish(speciesid), boatid integer not null REFERENCES boat(boatid), CONSTRAINT rights_pri PRIMARY KEY(userid,fishid,boatid) ); There are some tens of rows in table. I like to use table as: SELECT 1 FROM rights WHERE userid=107 AND fishid=64 AND boatid=2 EXPLAIN shows me, that PG cannot use index: Seq Scan on rights (cost=0.00..3.47 rows=1 width=0) Filter: ((userid = 107) AND (fishid = 64) AND (boatid = 2)) Any ideas why? -- BRH |
|
#2
|
||||
|
||||
|
First of all try disabling seqscan (see here) and check if the index is picked up, if this is the case then tune your postgresql.conf
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
|||
|
|||
|
Quote:
Edit: removed part of my message. I didn't read the first posting closely enough ![]() |
|
#4
|
|||
|
|||
|
I disabled seqscan with
set enable_seqscan=false; and it seems to make query to use index: Index Scan using rigths_pri on rights (cost=0.00..8.27 rows=1 width=0) Index Cond: ((userid = 107) AND (fishid = 64) AND (boatid = 2)) It is not maybe wise to change to postgresql.conf, because there is 12 other databases on same server. What it the reason for this seqscan? |
|
#5
|
||||
|
||||
|
Check shammat's post
|
|
#6
|
|||
|
|||
|
Yeps I read it. In fact, there is 181 rows in table.
This option, when false, decrease (bigger) query speed from 250 sek to 45 sek. Anything else I can do? |
|
#7
|
|||
|
|||
|
Quote:
|
|
#8
|
|||
|
|||
|
I'm not sure, but I think I have.
How it should be done? |
|
#9
|
|||
|
|||
|
Quote:
http://www.postgresql.org/docs/current/static/sql-analyze.html or using VACCUUM ANALYZE http://www.postgresql.org/docs/current/static/sql-vacuum.html |
|
#10
|
|||
|
|||
|
Bingo!
Thank's shammat! It seems that there is something, I haven't done by analyze. After running analyze to whole db, running time drops from 260 sek to 10 sek! With verbose on analyse or vacuum, there are no extra messages than without verbose - why? |
|
#11
|
|||
|
|||
|
Quote:
Which Postgres version are you running? |
|
#12
|
|||
|
|||
|
Yeps Autovacuum has been disabled, but vacuumdb is been running every day.
I'm running on 8.2.6 |
|
#13
|
||||
|
||||
|
Quote:
Quote:
You should really think about an upgrade to 8.4 |
|
#14
|
|||
|
|||
|
You are right. We already have placed a project to upgrade.
Why verbose are not talking? |
|
#15
|
|||
|
|||
|
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > PG cannot use index (combination primary key) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|