Re: Optimizer & boolean syntax

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Daniele Orlandi <daniele(at)orlandi(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Optimizer & boolean syntax
Date: 2002-11-21 21:13:54
Message-ID: 1037913234.30891.25.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Using the famous WAG tech, in your first query the optimizer has to
evaluate monitored for each record to determine its value.

Robert Treat

On Thu, 2002-11-21 at 13:39, Daniele Orlandi wrote:
>
> Are those two syntaxes eqivalent ?
>
> select * from users where monitored;
> select * from users where monitored=true;
>
> If the answer is yes, the optimimer probably doesn't agree with you :)
>
> Tested on RC1:
>
> template1=# create table a (a boolean, b text);
> CREATE TABLE
>
>
> .... inserted ~18000 rows with just one true (just to make an index scan
> meaningful)....
>
> template1=# vacuum analyze a;
> VACUUM
> template1=# explain select * from a where a;
> QUERY PLAN
> ----------------------------------------------------
> Seq Scan on a (cost=0.00..802.64 rows=1 width=11)
> Filter: a
> (2 rows)
>
> template1=# explain select * from a where a=true;
> QUERY PLAN
> --------------------------------------------------------------
> Index Scan using a_a on a (cost=0.00..2.01 rows=1 width=11)
> Index Cond: (a = true)
> (2 rows)
>
> Bye!
>
> --
> Daniele Orlandi
> Planet Srl
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2002-11-21 21:23:57 Re: performance of insert/delete/update
Previous Message Wei Weng 2002-11-21 20:54:03 performance of insert/delete/update