Re: How to optimize monstrous query, sorts instead of

От: Rod Taylor
Тема: Re: How to optimize monstrous query, sorts instead of
Дата: ,
Msg-id: 1056548165.25587.23.camel@jester
(см: обсуждение, исходный текст)
Ответ на: Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox")
Ответы: Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox")
Re: How to optimize monstrous query, sorts instead of  (Tom Lane)
Список: pgsql-performance

Скрыть дерево обсуждения

How to optimize monstrous query, sorts instead of using index  ("Michael Mattox", )
 Re: How to optimize monstrous query, sorts instead of using index  (Rod Taylor, )
  Re: How to optimize monstrous query, sorts instead of using index  ("Michael Mattox", )
   Re: How to optimize monstrous query, sorts instead of  (Rod Taylor, )
    Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
     Re: How to optimize monstrous query, sorts instead of  (Rod Taylor, )
      Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
       Re: How to optimize monstrous query, sorts instead of  (Rod Taylor, )
        Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
        Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
         Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
          Re: How to optimize monstrous query, sorts instead of  (Rod Taylor, )
           Re: How to optimize monstrous query, sorts instead of  ("Michael Mattox", )
         Re: How to optimize monstrous query, sorts instead of  (Rod Taylor, )
       Re: How to optimize monstrous query, sorts instead of  (SZUCS Gábor, )
      Re: How to optimize monstrous query, sorts instead of  (Tom Lane, )
   Re: How to optimize monstrous query, sorts instead of using index  (SZUCS Gábor, )
    Re: How to optimize monstrous query, sorts instead of using index  ("Michael Mattox", )
     Re: How to optimize monstrous query, sorts instead of using index  (Tom Lane, )

> > You might try a multi-column index on (ms.monitorx, ms.datex).
>
> Just tried it, it didn't prevent the sort.  But it sounds like the sort
> isn't the problem, correct?

The sort isn't actually doing any sorting, so it's virtually free.  The
sort is taking less than 3ms as the data is already 99% sorted due to
the correlation between datex and monitorx.

For similar reasons, the datex index will not be used, as it has no
advantage to being used.

>                            ->  Index Scan using
> monitorstatusx_datex_monitorx_index on monitorstatusx ms
> (cost=0.00..1159.33 rows=890 width=83) (actual time=0.19..1287.02 rows=628
> loops=1)
>                                  Index Cond: (("outer".jdoidx = ms.monitorx)
> AND (ms.datex >= '2003-06-20 08:57:21.36'::timestamp without time zone) AND
> (ms.datex <= '2003-06-29 08:57:21.36'::timestamp without time zone))

You can see that it used the new multi-key index for both items, rather
than finding for monitorx, then filtering out unwanted results by datex.

It doesn't appear to have made much difference (looks like data was
partially cached for this new run), but it changed a bit for the better.

I'm afraid thats the best I can do on the query itself I think.


Oh, and using tables in your where clause that aren't in the from clause
is non-portable and often hides bugs:

 from monitorstatusx ms
    , monitorstatusitemx msi
where monitorx.idx = 'M-TEST_1444-TEST_00_10560561260561463219352'

Are you sure you sure you don't have any duplicated constraints by
pulling information in from other tables that you don't need to?
Removing some of those nested loops would make a significant impact to
the results.

--
Rod Taylor <>

PGP Key: http://www.rbt.ca/rbtpub.asc

Вложения

В списке pgsql-performance по дате сообщения:

От: "Fernando Papa"
Дата:
Сообщение: Similar querys, better execution time on worst execution plan
От: "Sailer, Denis (YBUSA-CDR)"
Дата:
Сообщение: Query running slower than same on Oracle