Re: additional message to the bug #7499

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: additional message to the bug #7499
Дата
Msg-id 5034B9A802000025000499FC@gw.wicourts.gov
обсуждение исходный текст
Ответ на Re: additional message to the bug #7499  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Список pgsql-bugs
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> wrote:
> Denis Kolesnik <lirex.software@gmail.com> wrote:

>> and even sorting by id:
>> select id, str_last_name from tbl_owners_individual where id in
>> (83,175,111,1) order by str_last_name;
>>
>>  id  |    str_last_name
>> -----+----------------------
>>   83 | GXXXXXXXXX
>>  175 | GXXXXXXXXX
>>    1 | Kolesnik
>>  111 | Kolesnik
>> (4 ******)
>
> No, it didn't go out of its way to sort that way, it just happened
> to fall out that way that time; don't count on it always being
> that way, even if it happens many times in a row.
>
> test=# create table tbl_owners_individual
> test-#   (id int not null primary key, str_last_name text not
> null);
> CREATE TABLE
> test=# insert into tbl_owners_individual values
> test-#   (1, 'Kolesnik'),
> test-#   (83, 'GXXXXXXXXX'),
> test-#   (111, 'Kolesnik'),
> test-#   (175, 'GXXXXXXXXX');
> INSERT 0 4
> test=# select id, str_last_name from tbl_owners_individual
> test-# where id in (83,175,111,1) order by str_last_name;
>  id  | str_last_name
> -----+---------------
>   83 | GXXXXXXXXX
>  175 | GXXXXXXXXX
>    1 | Kolesnik
>  111 | Kolesnik
> (4 rows)

Dang!  I missed the tail of that session, which was the part that
made my point.  If you follow the above with a VACUUM ANALYZE and
then run the same query again, you get a different order:

test=# vacuum analyze tbl_owners_individual;
VACUUM
test=# select id, str_last_name from tbl_owners_individual
test-# where id in (83,175,111,1) order by str_last_name;
 id  | str_last_name
-----+---------------
 175 | GXXXXXXXXX
  83 | GXXXXXXXXX
 111 | Kolesnik
   1 | Kolesnik
(4 rows)

With better statistics from the VACUUM ANALYZE it realized that the
index usage was pointless and slower, so it just used a table scan.

-Kevin

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

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: additional message to the bug #7499
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: bug #7499 additional comments