public inbox for [email protected]  
help / color / mirror / Atom feed
From: Konstantin Knizhnik <[email protected]>
To: Robert Haas <[email protected]>
Cc: Pavel Stehule <[email protected]>
Cc: Tomas Vondra <[email protected]>
Cc: 曾文旌(义从) <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: 蔡松露(子嘉) <[email protected]>
Cc: Cai, Le <[email protected]>
Cc: 萧少聪(铁庵) <[email protected]>
Subject: Re: [Proposal] Global temporary tables
Date: Wed, 5 Feb 2020 10:28:31 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+TgmoY=aP4p_AR=z4O_kfMFHoSEg19Ed+f=U+6_0W1HKfJ2-Q@mail.gmail.com>
References: <[email protected]>
	<CAFj8pRAB4Ni+CL6n9QZ24wdp6n_2TLb2hYm60hs_KVXnDzN8tw@mail.gmail.com>
	<[email protected]>
	<CAFj8pRARb4BiT9Nb-YFg2h+EdbVQt8FY=L0utGM_FL6T-gjc-w@mail.gmail.com>
	<[email protected]>
	<CAFj8pRAvegZoQCLw3vjHZ=6_Kr7-1UAA5QgGYOshhXU6j_RuCg@mail.gmail.com>
	<[email protected]>
	<CAFj8pRDVaNQhg1juJKuj3A2fN-TW5LsMVCqyOkEhKKjbjHEk5w@mail.gmail.com>
	<[email protected]>
	<CA+TgmobN=o7d4zTJywJzsvkCeL4-_3ttWK_dhzpt-P3yCJ=77w@mail.gmail.com>
	<[email protected]>
	<CA+TgmoZQmLhPdMGM1YA-if2=iYQdSEr9r5b=WWwmJS9FbJNx+Q@mail.gmail.com>
	<[email protected]>
	<CA+TgmoaNYmuW7oUSeOviXM_8pFfgroDJbY5TXx7j=P7eXhpHqw@mail.gmail.com>
	<[email protected]>
	<CA+TgmoY=aP4p_AR=z4O_kfMFHoSEg19Ed+f=U+6_0W1HKfJ2-Q@mail.gmail.com>



On 05.02.2020 00:38, Robert Haas wrote:
>
> My guess it that the right time to do this work is just after we
> acquire locks, at the end of parse analysis. I think trying to do it
> during execution is too late, since the planner looks at indexes, and
> trying to do it in the planner instead of before we start planning
> seems more likely to cause bugs and has no real advantages. It's just
> better to do complicated things (like creating indexes) separately
> rather than in the middle of some other complicated thing (like
> planning). I could tie my shoelaces the first time they get tangled up
> with my break pedal but it's better to do it before I get in the car.
I have implemented this approach in my new patch

https://www.postgresql.org/message-id/3e88b59f-73e8-685e-4983-9026f94c57c5%40postgrespro.ru

I have added check whether index is initialized or not to plancat.c 
where optimizer checks if index is valid.
Now it should work for all kinds of indexes (B-Tree, hash, user defined 
access methods...).
>
> And I'm still inclined to do it by flat-copying files rather than
> calling ambuild. It will be slightly faster, but also importantly, it
> will guarantee that (1) every backend gets exactly the same initial
> state and (2) it has fewer ways to fail because it doesn't involve
> calling any user-defined code. Those seem like fairly compelling
> advantages, and I don't see what the disadvantages are. I think
> calling ambuild() at the point in time proposed in the preceding
> paragraph would be fairly safe and would probably work OK most of the
> time, but I can't think of any reason it would be better.

There is very important reason (from my point of view): allow other 
sessions to use created index and
so provide compatible behavior with regular tables (and with Oracle).
So we should be able to populate index with existed GTT data.
And ambuild will do it.

>
> Incidentally, what I'd be inclined to do is - if the session is
> running a query that does only read-only operations, let it continue
> to point to the "master" copy of the GTT and its indexes, which is
> stored in the relfilenodes indicated for those relations in pg_class.
> If it's going to acquire a lock heavier than AccessShareLock, then
> give it is own copies of the table and indexes, stored in a temporary
> relfilenode (tXXX_YYY) and redirect all future access to that GTT by
> this backend to there. Maybe there's some reason this won't work, but
> it seems nice to avoid saying that we've "attached" to the GTT if all
> we did is read the empty table.
>
Sorry, I do not understand the benefits of such optimization. It seems 
to be very rare situation when session will try to access temp table 
which was not previously filled with data. But even if it happen, 
keeping "master" copy will not safe much: we in any case have shared 
metadata and no data. Yes, with current approach, first access to GTT 
will cause creation of empty indexes. But It is just initialization of 
1-3 pages. I do not think that delaying index initialization can be 
really useful.

In any case, calling ambuild is the simplest and most universal 
approach, providing desired and compatible behavior.
I really do not understand why we should try yo invent some alternative 
solution.







view thread (492+ messages)  latest in thread

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [Proposal] Global temporary tables
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox