[PERFORM] Re: Fwd: Slow query from ~7M rows, joined to two tables of ~100 rowseach - Mailing list pgsql-performance

From Karl Czajkowski
Subject [PERFORM] Re: Fwd: Slow query from ~7M rows, joined to two tables of ~100 rowseach
Date
Msg-id 20170626170120.GB27236@moraine.isi.edu
Whole thread Raw
In response to Re: [PERFORM] Fwd: Slow query from ~7M rows, joined to two tables of ~100 rows each  (Chris Wilson <chris+postgresql@qwirx.com>)
List pgsql-performance
On Jun 26, Chris Wilson modulated:
> ...
>     In your case, the equivalent hack would be to compile the small
>     dimension tables into big CASE statements I suppose...
>
>
> Nice idea! I tried this but unfortunately it made the query 16 seconds
> slower (up to 22 seconds) instead of faster.

Other possible rewrites to try instead of joins:

  -- replace the case statement with a scalar subquery

  -- replace the case statement with a stored procedure wrapping that scalar subquery
     and declare the procedure as STABLE or even IMMUTABLE

These are shots in the dark, but seem easy enough to experiment with and might
behave differently if the query planner realizes it can cache results for
repeated use of the same ~100 input values.


Karl



pgsql-performance by date:

Previous
From: Chris Wilson
Date:
Subject: Re: [PERFORM] Fwd: Slow query from ~7M rows, joined to two tables of ~100 rows each
Next
From: Karl Czajkowski
Date:
Subject: [PERFORM] Re: Fwd: Slow query from ~7M rows, joined to two tables of ~100 rowseach