coercing int to bigint for indexing purposes - Mailing list pgsql-performance

From Mark Harrison
Subject coercing int to bigint for indexing purposes
Date
Msg-id 402AAEF1.2050703@pixar.com
Whole thread Raw
Responses Re: coercing int to bigint for indexing purposes
List pgsql-performance
Is there a way to automatically coerce an int into a bigint for
indexing purposes?

We have a table with a bigint column that is an index.
For mi, there's no problem, since I now know to say
    select * from foo where id = 123::bigint
but our casual users still say
    select * from foo where id = 123
causing a sequential scan because the type of 123 is not
a bigint.

As you can see, there's nearly 4 orders of magnitude difference
in time, and we anticipate this will only get worse as our
tables increase in size:

LOG:  duration:    0.861 ms  statement: select * from big where id = 123123123123123;
LOG:  duration: 6376.917 ms  statement: select * from big where id = 123;

One thing I have considered is starting our id sequence at 5000000000
so that "real" queries will always be bigint-sized, but this seems
to me a bit of a hack.

Many TIA,
Mark

--
Mark Harrison
Pixar Animation Studios


pgsql-performance by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: slow database
Next
From: Tom Lane
Date:
Subject: Re: coercing int to bigint for indexing purposes