Re: Patch to clean Query after rewrite-and-analyze - reduces memusage up to 50% - increases TPS by up to 50%

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Migowski <dmigowski(at)ikoffice(dot)de>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Patch to clean Query after rewrite-and-analyze - reduces memusage up to 50% - increases TPS by up to 50%
Date: 2019-08-04 19:14:07
Message-ID: 24988.1564946047@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Daniel Migowski <dmigowski(at)ikoffice(dot)de> writes:
> Am 03.08.2019 um 18:38 schrieb Tom Lane:
>> (After thinking a bit, I'm guessing that it seemed not to break because
>> your tests never actually exercised the generic-plan path, or perhaps
>> there was always a plancache invalidation before we tried to use the
>> query_list submitted by PrepareQuery. I wonder if this is telling us
>> something about the value of having PrepareQuery do that at all,
>> rather than just caching the raw parse tree and calling it a day.)

> Having PreparyQuery do _what_ exactly? Sorry, I am still learning how
> everything works here.

A plancache entry stores a raw parsetree (which is, at least
theoretically, an immutable representation of the parsed string),
and an analyzed-and-rewritten parsetree, and optionally a generic
plan tree. PrepareQuery is setting up the first two of these,
but only the raw parsetree is really essential ... or for that
matter, it might be possible to store just the source string
representation and re-parse that. It's all about space versus
speed tradeoffs. Our current philosophy is that if you bothered
to prepare a query it's because you want speed, but perhaps that
assumption needs rethinking.

> It seems like the patch crashes the postmaster when I use JOINSs
> directly in the PreparedStatement, not when I just place all the Joins
> in views. I will also look into this further.

Um. Now that I think about it, the regression tests probably don't
try to PREPARE any complex queries, so it's not impossible that
they just missed the fact that you were storing broken parse trees
for joins.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-08-04 19:16:12 Re: idea: log_statement_sample_rate - bottom limit for sampling
Previous Message Tomas Vondra 2019-08-04 19:10:37 Re: idea: log_statement_sample_rate - bottom limit for sampling