Re: intermittant performance problem

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: intermittant performance problem
Дата
Msg-id 87ljrd7ejj.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на Re: intermittant performance problem  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: intermittant performance problem  (Mike Charnoky <noky@nextbus.com>)
Список pgsql-general
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Mike Charnoky <noky@nextbus.com> writes:
>> The sampling query which runs really slow on some days looks something
>> like this:
>
>> INSERT INTO sampled_data
>>    (item_name, timestmp, ... )
>>    SELECT item_name, timestmp, ... )
>>    FROM raw_data
>>    WHERE timestmp >= ? and timestmp < ?
>>    AND item_name=?
>>    AND some_data_field NOTNULL
>>    ORDER BY random()
>>    LIMIT ?;
>
> Hmph, I'd expect that that would run pretty slowly *all* the time :-(.
> There's no good way to optimize "ORDER BY random()".

This seems kind of unlikely but does the parameter to the LIMIT vary a lot? If
it's small enough to fit all the chosen records in work_mem then you'll avoid
a disk-sort and do a top-k scan. If it overflows work_mem then it'll fail over
to do a full disk sort of all the records picked from raw_data.

It does seem much more likely that whatever index you have it using on
timestmp or item_name or some_data_field is sometimes being used and sometimes
not. Perhaps it's switching from an index on one of those columns to an index
on some other column and that's what's throwing it off.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

В списке pgsql-general по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: [ADMIN] How to Convert VarChar to Date in PgSQL
Следующее
От: Gregory Stark
Дата:
Сообщение: Re: postgresql and LDAP