pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Phuong Ma <pma@commandprompt.com>
To: pgsql-general@postgresql.org
To: pgsql-sql@postgresql.org
Subject: performance inconsistency
Date: Wed, 04 Apr 2001 15:12:27 -0700
Message-ID: <3ACB9C4B.1071C2F1@commandprompt.com> (raw)

Good day,

We're running a week-old CVS snapshot of PostgreSQL 7.1, and I'm not
sure
if this performance inconsistency is specific to it, or if this is just
something in PostgreSQL in general, but it seems kind of odd, and I
could
use some help here. ;)

I have run two queries in a table full of invoices where the only
difference
between the queries is the where clause:

SELECT COUNT(DISTINCT l."ORDER_NUM") AS line_orders,
        SUM(l."GROSS_PROFIT" + "REPLACEMENT_COST") AS grand_total,
        SUM(l."LIST_PRICE" * l."SHIPPED_QUANTITY") AS
grand_total_alternative,
        SUM(l."GROSS_PROFIT") AS grand_total_profit
 FROM   cu_invoice_li1_tbl l INNER JOIN cu_invoice_03_tbl h
   ON   l."ORDER_NUM"=h."ORDER_NUM"

WHERE substr("ORDER_NUM", 1, 1) != 'W'; # (Orders NOT prefixed with W.)

OR...

WHERE substr("ORDER_NUM", 1, 1) = 'I';  # (Orders prefixed with I.)

The first query returns more rows than the second (because it includes
orders prefixed with I, C, F, etc), whereas the second only returns
orders
prefixed with I. It seems that the logic of identifying a single
character
as *not* being a single value would be identical or at least similar in
efficiency to the logic of a single character *being* being a single
value.

However, the first query runs in about 10-15 seconds, and the second
query
ran for over 40 minutes before I cancelled it.

Now, I can easily use a series of "!=" statements to get it down so that
it's only the 'I' orders (which runs even faster, at about 5-6
seconds!),
but can anyone explain this to me? :)

Are "!=" substring evaluations inherently faster by an obscene order of
magnitude, or is something really wrong here?



J.



view thread (2+ messages)  latest in thread

Message-ID: <3ACB9C4B.1071C2F1@commandprompt.com>
Permalink:  ../3ACB9C4B.1071C2F1@commandprompt.com/
Also on:    postgresql.org/message-id/3ACB9C4B.1071C2F1@commandprompt.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pma@commandprompt.com, pgsql-general@postgresql.org
  Subject: Re: performance inconsistency
  In-Reply-To: <3ACB9C4B.1071C2F1@commandprompt.com>
  References: <3ACB9C4B.1071C2F1@commandprompt.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