Query optimizer & prepared statements

Поиск
Список
Период
Сортировка
Искать

Query optimizer & prepared statements

От:
Jack Orenstein <jack.orenstein@hds.com>
Дата:
If x is an integer column with an index, then

     select ...
     from T
     where x > 1

and

     select ...
     from T
     where x > 1000000000

could be optimized differently. So how is optimization done for a prepared 
statement containing a variable, e.g.

     select ...
     from T
     where x > $1

Jack Orenstein

Re: Query optimizer & prepared statements

От:
Emanuel Calvo Franco <postgres.arg@gmail.com>
Дата:
>
>    select ...
>    from T
>    where x > $1
>

prepare testy_prepare(int) as select * from T where x = $1;

execute testy_prepare(4);

Follow the docs :)
http://www.postgresql.org/docs/8.1/interactive/sql-prepare.html


-- 
              Emanuel Calvo Franco
ArPUG [www.arpug.com.ar] / AOSUG Member
        www.emanuelcalvofranco.com.ar

Re: Query optimizer & prepared statements

От:
Chris <dmagick@gmail.com>
Дата:
Jack Orenstein wrote:
> If x is an integer column with an index, then
> 
>     select ...
>     from T
>     where x > 1
> 
> and
> 
>     select ...
>     from T
>     where x > 1000000000
> 
> could be optimized differently. So how is optimization done for a 
> prepared statement containing a variable, e.g.
> 
>     select ...
>     from T
>     where x > $1

http://www.postgresql.org/docs/current/static/sql-prepare.html#AEN58703 
explains this.

If your parameter is a unique key, then you won't see any difference. If 
your parameter is a non-unique key, there may be differences depending 
on your data/distribution etc.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

FAQ