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 1iqSPQ-0004cP-8v for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Jan 2020 01:51:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iqSPN-0004Nf-Kd for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Jan 2020 01:51:17 +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 1iqSPN-0004NY-BJ for pgsql-hackers@lists.postgresql.org; Sun, 12 Jan 2020 01:51:17 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iqSPK-0003Xc-39 for pgsql-hackers@postgresql.org; Sun, 12 Jan 2020 01:51:16 +0000 Received: by mail-wm1-x341.google.com with SMTP id u2so5931943wmc.3 for ; Sat, 11 Jan 2020 17:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=inNMpigsr9IXh8thllWmDFTKPnNAuk6DvsgMEzIpgQU=; b=OXrFymJW/gaEa2pRB68dX8x6VSShm7iJ7gm2WcAVVukkx9xv2ihaffLQrFs9NcqtVj UmbiiVfUtG49SsoFNALP7zjhLegduWnzSyEpyEwGV0AFNE4jQgITPJT3nTx3/xh2mnEL IFPzhA/pM4pe4zPom/dwjmfPsEoLIGMpmjg5QPpBdj07+g9VPu9bE2KE8c2vf7lNCDBl jvrj9g3IC/JOM0U5eMhQb1502PcJ3r/cOVxujGZqc8ivlfaxW4JDDyBweQBeKi7pZDgD gxKHf6o9uDVt9OdJV/KyuowEv8Oqvi/FrvYYcQAXTh4nmdGB7zewBvWRjozCmqc+CbQw gPeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=inNMpigsr9IXh8thllWmDFTKPnNAuk6DvsgMEzIpgQU=; b=QGyi3q9v9hqw4hmhnWeGUC/dt2P4icOH7AImG4GYcfclpE6k4eN8WNd6yLZKH8/Jyt awth6NdqmsRiM3ZiPC9ok/4qBYyvlQvWaSBj/CZe3aovYIGVEGmXhbCBSmiRD7jV7xwn wE7HprWZautFtSnRfaIctgEC2KR9SuhcLij+BekCDnBMRkZt6En3DBCiIDpnV5TiFMan JVsbHgSf/3uVV6P9Bd0K1UkhlyrvmIY5ChW6oOCYsV1smskCGT9lQwGCmVIgUvUvY3wS PD9hzy1OkK6SI8h8AHGpzxUyyNDSCud1wSvK+QnHsKSeMDuj7vgvpBdXxEdzSYlTwB4t 36dA== X-Gm-Message-State: APjAAAXWSSmt3XcvClhD2F+VRjqjv+fbQEf8FZcL0ay2eKvPsWvWNWGk IuAcavz4v5WZpc8gTC64t/bUGQ== X-Google-Smtp-Source: APXvYqxgF3UJw0TLTurX64Eoia9NCLNVn3vNZoT9oqP7Sn5QwvePXt0eg9uynG27SEFAeDpoow09DQ== X-Received: by 2002:a1c:6389:: with SMTP id x131mr12031419wmb.174.1578793872010; Sat, 11 Jan 2020 17:51:12 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id m7sm8168902wma.39.2020.01.11.17.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2020 17:51:11 -0800 (PST) Date: Sun, 12 Jan 2020 02:51:09 +0100 From: Tomas Vondra To: Konstantin Knizhnik Cc: =?utf-8?B?5pu+5paH5peMKOS5ieS7jik=?= , Pavel Stehule , Robert Haas , PostgreSQL Hackers , =?utf-8?B?6JSh5p2+6ZyyKOWtkOWYiSk=?= , "Cai, Le" , =?utf-8?B?6JCn5bCR6IGqKOmTgeW6tSk=?= Subject: Re: [Proposal] Global temporary tables Message-ID: <20200112015109.caab6qdr2ob6d5jv@development> References: <24099f4e-742c-e92b-729c-77bac1ca80d4@postgrespro.ru> <80cf30c2-ebd5-a568-9f62-a970e4d91326@postgrespro.ru> <5767433E-1A77-4682-B3FD-4869911021C8@alibaba-inc.com> <6b7570aa-14ea-2f28-c3b5-74dd785bbafe@postgrespro.ru> <20200105200603.wrb4beacwb57hhpk@development> <33969545-BEF7-4518-A741-302CBF7FF269@alibaba-inc.com> <0498c45c-53cb-d9b0-c1e2-7d2d1a618511@postgrespro.ru> <20200109164829.mdl3z5xalmaqxs67@development> <3fef844f-0e73-8fcb-e4b6-595d6317b191@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <3fef844f-0e73-8fcb-e4b6-595d6317b191@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jan 10, 2020 at 11:47:42AM +0300, Konstantin Knizhnik wrote: > > >On 09.01.2020 19:48, Tomas Vondra wrote: >> >>>The most complex and challenged task is to support GTT for all >>>kind of indexes. Unfortunately I can not proposed some good >>>universal solution for it. >>>Just patching all existed indexes implementation seems to be the >>>only choice. >>> >> >>I haven't looked at the indexing issue closely, but IMO we need to >>ensure that every session sees/uses only indexes on GTT that were >>defined before the seesion started using the table. > >Why? It contradicts with behavior of normal tables. >Assume that you have active clients and at some point of time DBA >recognizes that them are spending to much time in scanning some GTT. >It cab create index for this GTT but if existed client will not be >able to use this index, then we need somehow make this clients to >restart their sessions? >In my patch I have implemented building indexes for GTT on demand: if >accessed index on GTT is not yet initialized, then it is filled with >local data. Yes, I know the behavior would be different from behavior for regular tables. And yes, it would not allow fixing slow queries in sessions without interrupting those sessions. I proposed just ignoring those new indexes because it seems much simpler than alternative solutions that I can think of, and it's not like those other solutions don't have other issues. For example, I've looked at the "on demand" building as implemented in global_private_temp-8.patch, I kinda doubt adding a bunch of index build calls into various places in index code seems somewht suspicious. * brinbuild is added to brinRevmapInitialize, which is meant to initialize state for scanning. It seems wrong to build the index we're scanning from this function (layering and all that). * btbuild is called from _bt_getbuf. That seems a bit ... suspicious? ... and so on for other index types. Also, what about custom indexes implemented in extensions? It seems a bit strange each of them has to support this separately. IMHO if this really is the right solution, we need to make it work for existing indexes without having to tweak them individually. Why don't we track a flag whether an index on GTT was initialized in a given session, and if it was not then call the build function before calling any other function from the index AM? But let's talk about other issues caused by "on demand" build. Imagine you have 50 sessions, each using the same GTT with a GB of per-session data. Now you create a new index on the GTT, which forces the sessions to build it's "local" index. Those builds will use maintenance_work_mem each, so 50 * m_w_m. I doubt that's expected/sensible. So I suggest we start by just ignoring the *new* indexes, and improve this in the future (by building the indexes on demand or whatever). >> >>Can't we track which indexes a particular session sees, somehow? >> >>>Statistic is another important case. >>>But once again I do not completely understand why we want to >>>address all this issues with statistic in first version of the >>>patch? >> >>I think the question is which "issues with statistic" you mean. I'm sure >>we can ignore some of them, e.g. the one with parallel workers not >>having any stats (assuming we consider functions using GTT to be >>parallel restricted). > >If we do not use shared buffers for GTT then parallel processing of >GTT is not possible at all, so there is no problem with statistic for >parallel workers. > Right. >> >>I think someone pointed out pushing stuff directly into the cache is >>rather problematic, but I don't recall the details. >> >I have not encountered any problems, so if you can point me on what is >wrong with this approach, I will think about alternative solution. > I meant this comment by Robert: https://www.postgresql.org/message-id/CA%2BTgmoZFWaND4PpT_CJbeu6VZGZKi2rrTuSTL-Ykd97fexTN-w%40mail.gmail.com regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services