How to tame a gigantic (100+ lines) query in a web app? - Mailing list pgsql-general

From W. Matthew Wilson
Subject How to tame a gigantic (100+ lines) query in a web app?
Date
Msg-id CAGHfCUDQc8RywD1_qa1_d3K3pFA5mGa4y5dyWh+ysdAgAgzfPg@mail.gmail.com
Whole thread Raw
Responses Re: How to tame a gigantic (100+ lines) query in a web app?  (Peter Bex <Peter.Bex@xs4all.nl>)
Re: How to tame a gigantic (100+ lines) query in a web app?  (Rob Sargent <robjsargent@gmail.com>)
Re: How to tame a gigantic (100+ lines) query in a web app?  (Sim Zacks <sim@compulab.co.il>)
Re: How to tame a gigantic (100+ lines) query in a web app?  (Thomas Markus <t.markus@proventis.net>)
List pgsql-general
I'm sure I'm not the first person to end up with a gigantic query that
does lots of left joins and subselects.

It seems to work, but I would love to break it up into smaller chunks.

I'm thinking about rewriting the query to make several temporary
tables that are dropped on commit, and then joining them at the end.

I can't just use views for everything because I use parameters passed
in from the web app.  I am using a few views where I can.

Is there anything dangerous about making temporary tables in this way?
 I started two transactions simultaneously and they were both able to
make their own temporary tables.

More generally, how to tame this big ol' query?

The temporary tables mean I'm only pulling data from the database one
time.  ORMs often pull data from one query and then use that data to
write the next query.  This seems slow to me.

Matt


--
W. Matthew Wilson
matt@tplus1.com
http://tplus1.com

pgsql-general by date:

Previous
From: Gavin Flower
Date:
Subject: Re: Using Postgresql as application server
Next
From: Colin Beckingham
Date:
Subject: Compile pgadmin1-1.14.0-beta3 - ctlMenuToolbar