Re: Using indices with long unique IDs.

Поиск
Список
Период
Сортировка
От D. Dante Lorenso
Тема Re: Using indices with long unique IDs.
Дата
Msg-id 3FFE7E3C.7010105@lorenso.com
обсуждение исходный текст
Ответ на Using indices with long unique IDs.  ("Sergey Olefir" <so3lv@yahoo.com>)
Ответы Re: Using indices with long unique IDs.  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Re: Using indices with long unique IDs.  (CoL <col@mportal.hu>)
Список pgsql-general
Sergey Olefir wrote:

>So the logical choice would be int8, right? Unfortunately quite wrong.
>Statement of the form: "SELECT * FROM table WHERE id=1"
>will never use index for id (assumming id is int8) since '1' is of type
>int4. This is confirmed both by documentation and SQL EXPLAIN (after set
>enable_seqscan TO 'off').
>
>
I'm using BIGSERIAL as the primary key for all my tables.  Please tell
me that what is described above will not be true for me as well!
When I say:

    SELECT x, y, z
    FROM mytable
    WHERE pk_mybigint = 1;

That had better be using an index, or in a few months, OMG!  Let me check:

    leads=> EXPLAIN ANALYSE SELECT * FROM leads WHERE lead_id = 555300;
                                                QUERY
PLAN

---------------------------------------------------------------------------------------------------
     Seq Scan on leads  (cost=0.00..334.66 rows=1 width=263) (actual
time=21.35..21.46 rows=1 loops=1)
       Filter: (lead_id = 555300)
     Total runtime: 21.53 msec
    (3 rows)

    leads=> EXPLAIN ANALYSE SELECT * FROM leads WHERE lead_id =
555300::bigint;
                                                       QUERY
PLAN

----------------------------------------------------------------------------------------------------------------
     Index Scan using pk_leads on leads  (cost=0.00..5.36 rows=1
width=263) (actual time=0.18..0.18 rows=1 loops=1)
       Index Cond: (lead_id = 555300::bigint)
     Total runtime: 0.24 msec
    (3 rows)

Well, that just plain sucks.  That means I've gotta go back and
add casts to all my queries?

Tell me it isn't so!

Dante





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

Предыдущее
От: Laurent Perez
Дата:
Сообщение: Postgres planner bug in 7.3.x and 7.4.1 ?
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Using indices with long unique IDs.