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 1j07Qu-0001Kh-N7 for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2020 17:28:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j07Qt-0004de-Gg for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2020 17:28:47 +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 1j07Qt-0004d1-1w for pgsql-hackers@lists.postgresql.org; Fri, 07 Feb 2020 17:28:47 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1j07Qq-000114-6J for pgsql-hackers@postgresql.org; Fri, 07 Feb 2020 17:28:46 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id D5A5E21C637F; Fri, 7 Feb 2020 20:28:41 +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 915D221C637E; Fri, 7 Feb 2020 20:28:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1581096521; bh=Ju48YwLjD31S94fnMIRLUVOA9kENvVu+mVq70QQBnbw=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=bINsnljyAdtSH1nKwo8nvW3JZlLgCFW0BhSXutP1th4BlmNisd/gCbpLpV971GaU2 l1NhPa+JSE0BSmPo2/Xe+NBt674HlH+virs1pJ4owpr6RZVwya48YD+xjO7tGgxBoU je0f8TAdM7yEB8s5ieKZE9i0kppqBvOzrkCe5Or4= Subject: Re: [Proposal] Global temporary tables To: Robert Haas Cc: Pavel Stehule , Tomas Vondra , =?UTF-8?B?5pu+5paH5peMKOS5ieS7jik=?= , PostgreSQL Hackers , =?UTF-8?B?6JSh5p2+6Zyy?= =?UTF-8?B?KOWtkOWYiSk=?= , "Cai, Le" , =?UTF-8?B?6JCn5bCR6IGqKOmTgeW6tSk=?= References: <24099f4e-742c-e92b-729c-77bac1ca80d4@postgrespro.ru> <0bddbc6d-fed1-d56b-d39f-67352461b2d1@postgrespro.ru> <407d6499-950d-e3d9-acbc-a2e86d8b82a3@postgrespro.ru> <6cbc12a0-bf0e-0205-959e-d871eb7e7c3e@postgrespro.ru> <3bfa5b5d-6b3b-743d-573c-b85f933ba540@postgrespro.ru> <3c68995f-0b2e-1c24-d4f5-d2f11c9dd34f@postgrespro.ru> From: Konstantin Knizhnik Message-ID: <674a6a05-5aa6-be32-7531-e1776546d277@postgrespro.ru> Date: Fri, 7 Feb 2020 20:28:41 +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 07.02.2020 18:15, Robert Haas wrote: > On Wed, Feb 5, 2020 at 10:48 AM Konstantin Knizhnik > wrote: > My answer is - yes. >> Just because: >> - Such behavior is compatible with regular tables. So it will not >> confuse users and doesn't require some complex explanations. >> - It is compatible with Oracle. >> - It is what DBA usually want when creating index. >> - >> There are several arguments against such behavior: >> - Concurrent building of index in multiple sessions can consume a lot of >> memory >> - Building index can increase query execution time (which can be not >> expected by clients) > I think those are good arguments, especially the second one. There's > no limit on how long building a new index might take, and it could be > several minutes. A user who was running a query that could have > completed in a few seconds or even milliseconds will be unhappy to > suddenly wait a long time for a new index to be built. And that is an > entirely realistic scenario, because the new index might be better, > but only marginally. Yes, I agree that this arguments are important. But IMHO less important than incompatible behavior (Pavel doesn't agree with word "incompatible" in this context since semantic of temp tables is in any case different with semantic of regular tables). Just want to notice that if we have huge GTT (so that creation of index takes significant amount of time) sequential scan of this table also will not be fast. But in any case, if we agree that we can control thus behavior using GUC or index property, then it is ok for me. > > Also, an important point to which I've already alluded a few times is > that creating an index can fail. Now, one way it can fail is that > there could be some problem writing to disk, or you could run out of > memory, or whatever. However, it can also fail because the new index > is UNIQUE and the data this backend has in the table doesn't conform > to the associated constraint. It will be confusing if all access to a > table suddenly starts complaining about uniqueness violations. Yes, building index can fail (as any other operation with database). What's wring with it? If it is fatal error, then backend is terminated and content of its temp table is disappeared. If it is non-fatal error, then current transaction is aborted: Session1: postgres=# create global temp table gtt(x integer); CREATE TABLE postgres=# insert into gtt values (generate_series(1,100000)); INSERT 0 100000 Session2: postgres=# insert into gtt values (generate_series(1,100000)); INSERT 0 100000 postgres=# insert into gtt values (1); INSERT 0 1 Session1: postgres=# create unique index on gtt(x); CREATE INDEX Sessin2: postgres=# explain select * from gtt where x=1; ERROR:  could not create unique index "gtt_x_idx" DETAIL:  Key (x)=(1) is duplicated. > I don't believe that the feature you are proposing can be correctly > implemented in 10 lines of code. I would be pleasantly surprised if it > can be done in 1000. > Right now I do not see any sources of extra complexity. Will be pleased if you can point them to me. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company