query gone haywire :) - Mailing list pgsql-general

From Robin Ericsson
Subject query gone haywire :)
Date
Msg-id 1097227197.7088.90.camel@pylver.localhost.nu.
Whole thread Raw
Responses Re: query gone haywire :)
List pgsql-general
The query have been running ok for some time now, but this morning I
decided to run vacuum analyze (vacuumdb -a -z) on the cluster, and
suddenly the query isn't running very well at all. This query has only
one value in the "IN", if I add another id the query becomes really
really slow.

Query:
SELECT
    data.entered,
    data.machine_id,
    datatemplate_intervals.template_id,
    data_values.value
FROM
    data, data_values, datatemplate_intervals
WHERE
    datatemplate_intervals.id = data_values.template_id AND
    data_values.data_id = data.id AND
    data.machine_id IN (2) AND
    current_timestamp::timestamp - interval '60 seconds' < data.entered

Indexes exists on data_values.template_id, data.entered,
data.machine_id, datatemplate_intervals.machine_id,
datatemplate_intervals.template_id.

Data contains almost 1.5milj entries, and data_values around 9.1milj. As
I write this letter I check the tables in pgAdmin, and it tells me this
for table data """
Rows (estimated) 1
Rows (counted)   1491401
""" even though I run vacuum analyze on the table itself from pgadmin.

Explain analyze result attached as explain-analyze.txt

Explain without analyze when using IN(2,3) attached as explain.txt


Regards,
Robin

Attachment

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Question about timezones
Next
From: Miles Keaton
Date:
Subject: interesting! a sequence clashes with data already in that table