Re: Prepared statements and suboptimal plans - Mailing list pgsql-performance

From Grzegorz Jaśkiewicz
Subject Re: Prepared statements and suboptimal plans
Date
Msg-id CAJY59_h40-A+=K4GV4SXcV1rk2acp2uc71nLaYpAycZ4YUCcqg@mail.gmail.com
Whole thread Raw
In response to Prepared statements and suboptimal plans  (Royce Ausburn <esapersona@royce.id.au>)
List pgsql-performance
one thing, in SUM() , you don't have to coalesce. Consider following example:

foo=# create table bar(id serial primary key, a float);
NOTICE:  CREATE TABLE will create implicit sequence "bar_id_seq" for
serial column "bar.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"bar_pkey" for table "bar"
CREATE TABLE
Time: 666.094 ms
foo=# insert into bar(a) select random()*random()*random() from
generate_series(1, 1000) x;
INSERT 0 1000
Time: 496.451 ms
foo=# update bar set a = NULL where random() < 0.1;
UPDATE 97
Time: 150.599 ms
foo=# select sum(a) from bar;
       sum
------------------
 108.757220804033
(1 row)

Time: 277.227 ms
foo=# select sum(coalesce(a, 0.0)) from bar;
       sum
------------------
 108.757220804033
(1 row)

Time: 0.709 ms


But that obviously isn't going to improve it a lot.

pgsql-performance by date:

Previous
From: Gunnlaugur Þór Briem
Date:
Subject: Re: Constraint exclusion on UNION ALL subqueries with WHERE conditions
Next
From: Robert Klemme
Date:
Subject: Re: Slow query with self-join, group by, 100m rows