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

Поиск
Список
Период
Сортировка
От Bryce Nesbitt
Тема Difference between "foo is false" and "foo=false"? Partial index on boolean.
Дата
Msg-id 46DCE263.6040207@obviously.com
обсуждение исходный текст
Ответы Re: Difference between "foo is false" and "foo=false"? Partial index on boolean.  (Tom Lane <tgl@sss.pgh.pa.us>)
Partial index on boolean - Sometimes fails to index scan  (Bryce Nesbitt <bryce1@obviously.com>)
Список pgsql-sql
Expecting to save 4 seconds per query, I built a partial index on a table, and was surprised that it did not work. 
Couldsomeone 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_EVENTwhere reconciled <b>is false;</b><br />
--------------------------------------------------------------------------<br/>  Aggregate  (cost=33169.57..33169.58
rows=1width=0)<br />    ->  <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 />    ->  <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_logentry:<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 />    ->  <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.548rows=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>

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

Предыдущее
От: Dmitry Turin
Дата:
Сообщение: Re: Request into several DBMS simultaneously on DDL and DML
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Difference between "foo is false" and "foo=false"? Partial index on boolean.