![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
The table in question has several thousand rows currently, planning several million, it has a date time stamp column. All selects will be on ranges of the date time column. I created an index on the dt column, ran ANALYSE then, EXPLAIN for some queries. The returned plan was always sequential search. The SELECT time also indicates sequential search. Is there anything I can do to improve SELECT performance on what is essentially an ordered table? |
#3
| |||
| |||
|
|
On Mon, Nov 15, 2004 at 04:25:59PM +1100, Harvey, Allan AC wrote: I created an index on the dt column, ran ANALYSE then, EXPLAIN for some queries. The returned plan was always sequential search. Could you post a query and the EXPLAIN ANALYZE output? We could probably give better advice if we could see what's happening. |
#4
| |||
| |||
|
|
don't recommend turning off enable_seqscan as a production solution On your advise I did not go there. |
|
-----Original Message----- From: Tom Lane [mailto:tgl (AT) sss (DOT) pgh.pa.us] Sent: Tuesday, 16 November 2004 2:26 To: Michael Fuhr Cc: Harvey, Allan AC; pgsql-general (AT) postgresql (DOT) org Subject: Re: [GENERAL] table configuration tweak for performance gain. Michael Fuhr <mike (AT) fuhr (DOT) org> writes: On Mon, Nov 15, 2004 at 04:25:59PM +1100, Harvey, Allan AC wrote: I created an index on the dt column, ran ANALYSE then, EXPLAIN for some queries. The returned plan was always sequential search. Could you post a query and the EXPLAIN ANALYZE output? We could probably give better advice if we could see what's happening. Also, let's see EXPLAIN ANALYZE results after setting enable_seqscan to OFF. If that doesn't force it into an indexscan, then you have got more fundamental issues (perhaps a datatype mismatch). Note that I don't recommend turning off enable_seqscan as a production solution; but it's a useful tool for debugging. regards, tom lane |
#5
| |||
| |||
|
|
mill2=> explain select value from history where pointname = 'MILL2-SPEED' and dt < now() - interval '5 minutes'\g |
|
Seq Scan on history (cost=0.00..8263.19 rows=9342 width=8) Filter: (((pointname)::text = 'MILL2-SPEED'::text) AND ((dt)::timestamp with time zone < (now() - '00:05:00'::interval))) |
|
On using BETWEEN:- mill2=> select value from history where pointname = 'MILL2-SPEED' and dt between now() and now() - interval '5 minutes'\g value ------- (0 rows) |
#6
| |||
| |||
|
|
-----Original Message----- From: Michael Fuhr [mailto:mike (AT) fuhr (DOT) org] Sent: Wednesday, 17 November 2004 12:19 To: Harvey, Allan AC Cc: Tom Lane Subject: Re: [GENERAL] table configuration tweak for performance gain. On Wed, Nov 17, 2004 at 09:39:11AM +1100, Harvey, Allan AC wrote: The solution then was:- an index of the right columns. explicit, exact type casting ( I'm a casual ingres user, type casting is something I never need or think you can do) PostgreSQL 8.0 will allow cross-type index usage, making the explicit cast unnecessary. turning off enable_seqscan for specific queries seemed to help a bit too. Performance in general might improve if you address the planner's reasons for chosing an inefficient plan. Even though you're satisifed with performance now, would you mind posting the output of "EXPLAIN ANALYZE select ..." with enable_seqscan on and then with it off? If nothing else, an analysis might be educational for others. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ |
#7
| |||
| |||
|
|
mill2=> explain analyse select count(*) from history where pointname = 'MILL2-SPEED' and dt > (now() - interval '5 minutes')::timestamp\g |
![]() |
| Thread Tools | |
| Display Modes | |
| |