Search Postgresql Archives

Re: index being ignored for "limit n" queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Piotr Sulecki <Piotr.Sulecki@xxxxxxxxxxxxxxxxxxxxxxxxx> writes:
> I have two really big tables, the problem is with one of them. The table
> looks as follows:
> ...
> Indexes:
>     "pakiety_pkey" PRIMARY KEY, btree (pktid)
>     "pakiety_stid_received_idx" UNIQUE, btree (stid, received)
>     "pakiety_measured_idx" btree (measured)
>     "pakiety_received_idx" btree (received)
>     "pakiety_stid_measured_idx" btree (stid, measured)

> trax=# explain select * from pakiety where stid = 234::smallint order by
> received desc limit 1;

The reason this won't use the (stid, received) index is that the
requested sort order doesn't match that index.  Try

select * from pakiety where stid = 234::smallint
order by stid desc, received desc
limit 1;

There is code in CVS tip to recognize that the equality constraint on
stid allows the index to be considered as producing data ordered by
received alone --- but no released version will make that deduction
for you.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux