Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kajHF-0004bo-J4 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Nov 2020 17:42:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kajHE-0007Gr-5n for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Nov 2020 17:42:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kajHD-0007Gk-Va for pgsql-hackers@lists.postgresql.org; Thu, 05 Nov 2020 17:42:23 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kajH6-0004SO-Mm for pgsql-hackers@postgresql.org; Thu, 05 Nov 2020 17:42:22 +0000 Received: by mail-ej1-x644.google.com with SMTP id k3so3789483ejj.10 for ; Thu, 05 Nov 2020 09:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=0oGCguisVAX2jEDIm0RmlaGaLCvCh4cpky5/PD9RSy0=; b=eSH2Q5rYK0A/KgKqJiQtHL0VUHrwRXdRvj8t3u34QWWRVHLtBKf32gnmkBrlIzZoDN bO+BNEY1i0Plr/irho1JtI0kYXaEGWT1ksxKKzgzsYDfKylVK0Bg6gFWDd3wUMJsCMX6 EmL/Gc3OvgOgwiJL7QCbxj+Tdnk5roD8UxWdmnTLn5F2PItlXl8S0HfuNBAawsgEZXVj /P3ZY7KFAevnU6soHfXJE8z5lpZ6KHLYguC16MK71jA7Rd9nWu8CL2IiXsAnnMDqieod EOHFpZdN9qon6/jEKjSuR6rFSAH/VtxZnv/8ERTccPtakEKGANO3D3Te+3p9EtmorhLt 5dtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=0oGCguisVAX2jEDIm0RmlaGaLCvCh4cpky5/PD9RSy0=; b=Km6VrZPYVyggN0J3/cnqmz928Jc3gtZHk8DgAMym8uCAeAEZU0+PIXk5rAFaDwJtaY gCjBdUb6asodP/fWr1vsvYHpek8nSVkXUzLbsNi5mj+2j+7dMZ11YzuqZCsNrl9f2l0J Itnt/XTTSEuYQ+ribBp1VuecPGctkxY/DUWOLU77oCUWQ1OOvIhCI/qMhL0hg+nRIb+S RVv7zcI3PcFIigOHRswPH7pErs9H7VvfzUU/UXdtD96zydEH54tj0kmSimAA1aN+7r5z q8H6BetspWm2CkJEGqeRU1uLmzIwp9Ns8Vm5pXTcoT9LizkKxm7OT/X5LfNmW9vWCRzs ctrw== X-Gm-Message-State: AOAM533a55t8DNljOmwVQSqbJ0yD3t9CH8CZYFWm1j5FFmnnlSa4IJys VYW9qeTR5IaqUPcXLUykOSNhpxLCqsLq52Onn62bxe/L0V6fx6jP5BX4mobog46cfF7Lm9IzoXQ ryk8IMO18u94x9dtjpiC+pytKcei0MMLpS3J10M36XBKx6uAuxHIJAXiX8Ga2NE1qD8sx6ZfCZU 2fGslFMjeEN35gLIYdrmR32Y6vhgFtnLknVjE0bUTp9NhlrkzVvttZpIJ+EkLuVuT3R7eDVuoAj f2d+ZMvEYDwibVZuw27RX6EvpvNpvZY9yh3vP4j X-Google-Smtp-Source: ABdhPJxd5R7Rrzre0cB/+41h/LxGaDHn1hx3ZkZ0CSqvYymLBJkk3djqV3RTmkkSzzPqHlCCEs633Q== X-Received: by 2002:a17:906:c298:: with SMTP id r24mr3372457ejz.38.1604598133839; Thu, 05 Nov 2020 09:42:13 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-245-76.net.upcbroadband.cz. [86.49.245.76]) by smtp.gmail.com with ESMTPSA id q3sm1341657edv.17.2020.11.05.09.42.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Nov 2020 09:42:13 -0800 (PST) Subject: Re: Fix brin_form_tuple to properly detoast data To: Alvaro Herrera , Tomas Vondra Cc: pgsql-hackers@postgresql.org References: <20201105171717.GA29029@alvherre.pgsql> From: Tomas Vondra Message-ID: <21cacd39-1ca2-54ef-4f3e-ac493238832c@enterprisedb.com> Date: Thu, 5 Nov 2020 18:42:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201105171717.GA29029@alvherre.pgsql> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/5/20 6:17 PM, Alvaro Herrera wrote: > On 2020-Nov-04, Tomas Vondra wrote: > >> The first test is fairly trivial - it simply builds index on toasted data >> and then shows how an insert and select fail. There's a caveat, that this >> requires a DELETE + VACUUM, and the VACUUM actually has to cleanup the rows. >> So there must be no concurrent transactions that might need the rows, which >> is unlikely in regression tests. So this requires waiting for all running >> transactions to finish - I did that by building an index concurrently. It's >> a bit strange, but it's better than any other solution I could think of >> (timeout or some custom wait for xacts). > > There are recent changes in vacuum for temp tables (commit 94bc27b57680?) > that would maybe make this stable enough, without having to have the CIC > there. At least, I tried it locally a few times and it appears to work well. > This won't work for older releases though, just master. This is patch > 0001 attached here. > IIUC you're suggesting to use a temporary table in the test? Unfortunately, this does not work on older releases, and IMHO the test should be backpatched too. IMHO the CIC "hack" is acceptable, unless there's a better solution that I'm not aware of. >> The second test is a bit redundant - it merely checks that both CREATE INDEX >> and INSERT INTO fail the same way when the index tuple gets too large. >> Before the fix there were some inconsistencies - the CREATE INDEX succeeded >> because it used TOASTed data. So ultimately this tests the same thing, but >> from a different perspective. > > Hmm. This one shows page size in the error messages, so it'll fail on > nonstandard builds. I think we try to stay away from introducing those, > so I'd leave this test out. Hmm, OK. I don't think having "redundant" test is a big deal, but I haven't thought about builds with different block sizes. I'll leave this out. > > The code fix looks all right -- I'd just move the #include lines to > their place. Patch 0002. > OK > You add this comment: > >> + /* >> + * Do nothing if value is not of varlena type. We don't need to >> + * care about NULL values here, thanks to bv_allnulls above. >> + * >> + * If value is stored EXTERNAL, must fetch it so we are not >> + * depending on outside storage. >> + * >> + * XXX Is this actually true? Could it be that the summary is >> + * NULL even for range with non-NULL data? E.g. degenerate bloom >> + * filter may be thrown away, etc. >> + */ > > I think the XXX comment points to a bug that we don't have right now, > since neither minmax nor inclusion can end up with a NULL summary > starting from non-NULL data. But if the comment about bloom is correct, > then surely it'll become a bug when bloom is added. > Yeah, but that'd be something for the bloom patch to fix, I think. This got me thinking though - wouldn't it be better to handle too large values by treating the range as "degenerate" (i.e. store NULL and consider it as matching all queries), instead of failing the CREATE INDEX or DML? I find the current behavior rather annoying, because it depends on the other rows in the page range, not just on the one row the user deals with. Perhaps this might even be considered an information leak about the other data. Of course, not something this patch should deal with. > I don't think we need the second part of this comment: > >> +/* >> + * This enables de-toasting of index entries. Needed until VACUUM is >> + * smart enough to rebuild indexes from scratch. >> + */ > > ... because, surely, we're now never working on having VACUUM rebuild > indexes from scratch. In fact, I wonder if we need the #define at > all. I propose to remove all those #ifdef lines in your patch. > That's a verbatim copy of a comment from indextuple.c. IMHO we should keep it the same in both places. > The fix looks good to me. I just added a comment in 0003. > Thanks. Any opinions on fixing this in existing clusters? Any better ideas than just giving users the SQL query to list possibly-affected indexes? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company