pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryce Nesbitt <bryce1@obviously.com>
To: pgsql-sql@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: Difference between "foo is false" and "foo=false"? Partial index on boolean.
Date: Mon, 03 Sep 2007 22:07:04 -0700
Message-ID: <46DCE7F8.6080000@obviously.com> (raw)
In-Reply-To: <14040.1188881806@sss.pgh.pa.us>
References: <46DCE263.6040207@obviously.com>
	<14040.1188881806@sss.pgh.pa.us>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tom Lane wrote:
<blockquote cite="mid:14040.1188881806@sss.pgh.pa.us" type="cite">
  <pre wrap="">Bryce Nesbitt <a class="moz-txt-link-rfc2396E" href="mailto:bryce1@obviously.com">&lt;bryce1@obviously.com&gt;</a> writes:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Could someone explain
the difference between "foo=false" and "foo is false", for a boolean
type column?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
They give different results for NULL --- specifically, NULL for the
former and FALSE for the latter.  Don't blame me, it's in the spec...</pre>
</blockquote>
Thanks, and Got It.  This particular column is:<br>
    reconciled       | boolean                     | not null<br>
On PostgreSQL 8.1.9.<br>
<br>
<br>
So given all that, why would the Hibernate query fail to use the
partial index?   I eventually created three indexes, and only the
hideously large full index increases performance:<br>
<br>
<tt>Indexes:<br>
    "eg_vehicle_event_pkey" PRIMARY KEY, btree (vehicle_event_id)<br>
    "no_duplicate_events" UNIQUE, btree (cso_id, event_type,
"timestamp", fob_number, hardware_number)<br>
    "eg_ve_reconciled_full" btree (reconciled)<br>
    "eg_ve_reconciled_partial" btree (reconciled) WHERE reconciled =
false<br>
    "eg_ve_reconciled_partial_is" btree (reconciled) WHERE reconciled
IS FALSE<br>
Foreign-key constraints:<br>
    "fk_event_admin" FOREIGN KEY (admin_id) REFERENCES
eg_admin(admin_id)<br>
    "fkd28396aacabde72e" FOREIGN KEY (vehicle_id) REFERENCES
eg_vehicle(vehicle_id)<br>
    "fkd28396aaf61930e0" FOREIGN KEY (member_id) REFERENCES
eg_member(member_id)<br>
</tt><br>
<br>
Only the full index prevents a "false" scan from taking 4 seconds:<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>
<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>



view thread (4+ messages)  latest in thread

Message-ID: <46DCE7F8.6080000@obviously.com>
Permalink:  ../46DCE7F8.6080000@obviously.com/
Also on:    postgresql.org/message-id/46DCE7F8.6080000@obviously.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bryce1@obviously.com, tgl@sss.pgh.pa.us
  Subject: Re: Difference between "foo is false" and "foo=false"? Partial index on boolean.
  In-Reply-To: <46DCE7F8.6080000@obviously.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox