Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iT3pM-0007oK-52 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2019 12:57:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iT3pK-0007hA-VG for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2019 12:57:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iT3pK-0007h3-F6 for pgsql-hackers@lists.postgresql.org; Fri, 08 Nov 2019 12:57:22 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iT3pD-0006yp-Bz for pgsql-hackers@postgresql.org; Fri, 08 Nov 2019 12:57:22 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 041C721C4A0A; Fri, 8 Nov 2019 15:57:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.200] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id AB3E721C49D5; Fri, 8 Nov 2019 15:57:13 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1573217833; bh=fA/rhOAxE72Bn3KtH/kYq/Cn9QkrfyL1mW0rqekKPI0=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=j+T96bDCeUt0yIc3ieT3FeJ+Px1QXwtzQmcWeM2AIb4zb1ibzGBzxqIlFAICIH6N1 GJW9szuBuAYGmFrJq6IX4rV8ppBA/ySBo4mlGeyCaT5Waw61JstDqTIGDMn3JLWWDc c/KYoRM9VoyUMz7hb8dUbZYt65MaxcnGNtovgPi8= Subject: Re: [Proposal] Global temporary tables To: =?UTF-8?B?5pu+5paH5peMKOS5ieS7jik=?= Cc: Robert Haas , Pavel Stehule , PostgreSQL Hackers , =?UTF-8?B?6JSh5p2+6Zyy?= =?UTF-8?B?KOWtkOWYiSk=?= , "Cai, Le" , =?UTF-8?B?6JCn5bCR6IGqKOmTgeW6tSk=?= References: <1A1A6EDC-D0EC-47B0-BD21-C2ACBAEA65E4@alibaba-inc.com> <0ef6f482-11ce-a99f-207e-26fa3f2f56db@postgrespro.ru> <8dc812ea-af3f-7a9d-ae9a-d89c25ca89ca@postgrespro.ru> <0FC4E40B-4B4E-4B10-B2AA-F8E8E914F822@alibaba-inc.com> <66623FEE-5EC8-45A2-8225-AF1B83D7197F@alibaba-inc.com> <7a321cef-f9ce-a42e-5860-54fcdf07e77a@postgrespro.ru> From: Konstantin Knizhnik Message-ID: <745ef1fa-5a81-d30d-aa33-bce24a022a3a@postgrespro.ru> Date: Fri, 8 Nov 2019 15:57:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 08.11.2019 10:50, 曾文旌(义从) wrote: > In my opinion, it is not a good idea to trigger a btbuild with a select or DML, the cost of which depends on the amount of data in the GTT. IMHO it is better than returning error. Also index will be used only if cost of plan with index will be considered better than cost of plan without index. If you do not have index, then you have to scan the whole table. Time of such scan is comparable with time of building index. Yes, I agree that indexes for GTT are used to be created together with table itself before it is used by any application. But if later DBA recognized that efficient execution of queries requires some more indexes, it will be strange and dangerous to prevent him from adding such index until all clients which have accessed this table will drop their connections. Also maintaining in shared memory information about attached backends seems to be overkill. >> >> This code initializes B-Tree and load data in it when GTT index is access and is not initialized yet. >> It looks a little bit hacker but it works. >> >> I also wonder why you are keeping information about GTT in shared memory. Looks like the only information we really need to share is table's metadata. >> But it is already shared though catalog. All other GTT related information is private to backend so I do not see reasons to place it in shared memory. > The shared hash structure tracks which backend has initialized the GTT storage in order to implement the DDL of the GTT. Sorry, I do not understand this argument. DDL is performed on shared metadata present in global catalog. Standard postgres invalidation mechanism is used to notify all backends about schema changes. Why do we need to maintain some extra information in shared memory. Can you give me example of DLL which does't work without such shared hash? > As for GTT, there is only one definition(include index on GTT), but each backend may have one data. > For the implementation of drop GTT, I assume that all data and definitions need to be deleted. Data of dropped GTT is removed on normal backend termination or cleaned up at server restart in case of abnormal shutdown (as it is done for local temp tables). I have not used any shared control structures for GTT in my implementation and that is why I wonder why do you need it and what are the expected problems with my implementation? -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company