Difference between "foo is false" and "foo=false"? Partial index on boolean.

From: Bryce Nesbitt <bryce1(at)obviously(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Difference between "foo is false" and "foo=false"? Partial index on boolean.
Date: 2007-09-04 04:43:15
Message-ID: 46DCE263.6040207@obviously.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Expecting to save 4 seconds per query, I built a partial index on a
table, and was surprised that it did not work.  Could someone explain
the difference between "foo=false" and "foo is false", for a boolean
type column?<br>
<tt><br>
stage=# create index eg_ve_reconciled_partial on eg_vehicle_event
(reconciled) where <b>reconciled=false;</b><br>
stage=# select pg_total_relation_size('eg_ve_reconciled_partial');<br>
 pg_total_relation_size <br>
------------------------<br>
                   8192<br>
<br>
<br>
stage=# explain select count(*) from EG_VEHICLE_EVENT where reconciled <b>is
false;</b><br>
--------------------------------------------------------------------------<br>
 Aggregate  (cost=33169.57..33169.58 rows=1 width=0)<br>
   -&gt;  <b>Seq Scan</b> on eg_vehicle_event  (cost=0.00..33169.57
rows=1 width=0)<br>
         Filter: (reconciled IS FALSE)<br>
<br>
<br>
<br>
stage=# explain select count(*) from EG_VEHICLE_EVENT where <b>reconciled=false;</b><br>
-------------------------------------------------------------------------------------------------------<br>
 Aggregate  (cost=1.02..1.03 rows=1 width=0)<br>
   -&gt;  <b>Index Scan</b> using eg_ve_reconciled_partial on
eg_vehicle_event  (cost=0.00..1.01 rows=1 width=0)<br>
         Index Cond: (reconciled = false)<br>
</tt><br>
<br>
The problem is that my test query above is fast, but the real query
from Hibernate is still dog slow.  Here's the pg_log entry:<br>
<br>
<tt>LOG:  duration: 4260.575 ms  statement: EXECUTE C_50292  [PREPARE: 
select count(vehicleeve0_.VEHICLE_EVENT_ID) as x0_0_ from
EG_VEHICLE_EVENT vehicleeve0_ where (vehicleeve0_.CSO_ID=$1 ) and
(vehicleeve0_.<b>RECONCILED=$2</b> )]</tt><br>
<br>
<br>
I tried building two indexes, one for "is false" one for "=false", but
the Hibernate query is still slow.  Yet the hand-run version  uses the
index easily:<br>
<br>
<tt>stage=# explain analyze select count(vehicleeve0_.VEHICLE_EVENT_ID)
as x0_0_ from EG_VEHICLE_EVENT vehicleeve0_ where
(vehicleeve0_.CSO_ID=2 )and(vehicleeve0_.<b>RECONCILED=false</b>);<br>
                                                                             
QUERY
PLAN                                                                              
<br>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
 Aggregate  (cost=81.75..81.76 rows=1 width=4) (actual
time=56.153..56.154 rows=1 loops=1)<br>
   -&gt;  <b>Index Scan</b> using eg_ve_reconciled_partial on
eg_vehicle_event vehicleeve0_  (cost=0.00..60.05 rows=8679 width=4)
(actual time=0.126..44.548 rows=10345 loops=1)<br>
         Index Cond: (reconciled = false)<br>
         Filter: (cso_id = 2)<br>
 Total runtime: 64.825 ms<br>
(5 rows)</tt><br>
<br>
<br>
<pre class="moz-signature" cols="100">--
----
Visit <a class="moz-txt-link-freetext" href="http://www.obviously.com/">http://www.obviously.com/</a>
</pre>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 3.3 KB

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-09-04 04:56:46 Re: Difference between "foo is false" and "foo=false"? Partial index on boolean.
Previous Message Dmitry Turin 2007-09-04 04:25:15 Re: Request into several DBMS simultaneously on DDL and DML