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 1kO3WS-0004nP-19 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Oct 2020 18:41:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kO3WQ-0003Qh-V5 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Oct 2020 18:41:42 +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 1kO3WQ-0003Qa-OC for pgsql-hackers@lists.postgresql.org; Thu, 01 Oct 2020 18:41:42 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kO3WL-0008Rr-R9 for pgsql-hackers@postgresql.org; Thu, 01 Oct 2020 18:41:41 +0000 Received: by mail-ed1-x541.google.com with SMTP id 33so6368097edq.13 for ; Thu, 01 Oct 2020 11:41:37 -0700 (PDT) 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=xJHV+K5BlsalTaSX+EjiflM05KtXVOnwJ9TFlQta9vg=; b=blFNFrTeuWJymTf8XQFumBVpZOML68p2WI1eq1yVBnKEIMhCbdZReJp5zAMxGkTGKg D6frPaw1aU0EtMzpO5bOMxBF6b+iDpl3pmT5oRNi/hQGuFwMqJ7BHoTbFdJhu1mUlE8z 4POP1aMThFXIXn9wVriKW7iP8DW78ftUb+27Lq0IMhDaCoz81qjQZRq3eTDKJryDCHG8 vmN65niBlK0aKudrWxe+IKBDavo1I31FZjkii/HhVQYOZNunTEp/c9LJyJftzmd3sTg+ Pr3LYuAocglxyeP8Tw7JOSNeUHb/ZBt5wsmm1QrmhYiyGR3eRIL1U+gg27E7F8ALXB61 PeIw== 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=xJHV+K5BlsalTaSX+EjiflM05KtXVOnwJ9TFlQta9vg=; b=EZz4CHEEkvXGfvghkybgM5aoi5QrmHjaiJ38KgcT5ACIYL6NToVlpBP35ItaswqOh9 jmcVTQXhYF0DLQgQIkVsOYOZjJLsOS0Hc3xH6Ys+4dG5lYJP+8SHqGjnEK0Iy8EdE3Ur NlA1bD/oDIHZMyiCTPu5qKyHgrCUPdsl79lrzr1BsSuLyuZ5+M7NavCN1hgSsC8V7yRm Hllp6Bq9oaq5Ksu7vbShBnZZRsYDvjITrF4LXCY2j42Zjhw0qoBIZB3mB4IY9g2Lf4I6 hXm3HfbECoU7+hrYtu/I/Gg36UZLBy+3fqunoajYuYKXwYGMLIxbJ+ujwpFCbEYuvuV2 P7YQ== X-Gm-Message-State: AOAM530wixX7VmXR+8q8RPdcHBH8rLPTIJSfsOs4eTFu7J2haWJBgbV5 itL88Ix2vVhc3DRtOr66GAW8iA== X-Google-Smtp-Source: ABdhPJyFzosgEERopj7eZgvAF+8/8kiL1XTB4Dj1BF2596nXBJTRCQuql4U9dg7F6GQX2BZWBlPbiw== X-Received: by 2002:a05:6402:1bc2:: with SMTP id ch2mr9454687edb.60.1601577695463; Thu, 01 Oct 2020 11:41:35 -0700 (PDT) Received: from localhost (ip-86-49-245-76.net.upcbroadband.cz. [86.49.245.76]) by smtp.gmail.com with ESMTPSA id h10sm4687473ejt.93.2020.10.01.11.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 11:41:34 -0700 (PDT) Date: Thu, 1 Oct 2020 20:41:33 +0200 From: Tomas Vondra To: John Naylor Cc: Alvaro Herrera , pgsql-hackers Subject: Re: WIP: BRIN multi-range indexes Message-ID: <20201001184133.oq5uq75sb45pu3aw@development> References: <20200918114014.sz5a3nwt7zont4rz@development> <20200918222702.omsieaphfj3ctqg3@development> <20200921195607.gt6xbia7v55bhuwq@development> <20200924235045.bgxsilvf7askukph@development> <20200929021228.bf2vtpl3negue4y4@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Sep 30, 2020 at 07:57:19AM -0400, John Naylor wrote: >On Mon, Sep 28, 2020 at 10:12 PM Tomas Vondra > wrote: > >> Is it actually all that different from the existing BRIN indexes? >> Consider this example: >> >> create table x (a text, b text, c text); >> >> create index on x using brin (a,b,c); >> >> create or replace function random_str(p_len int) returns text as $$ >> select string_agg(x, '') from (select chr(1 + (254 * random())::int ) as x from generate_series(1,$1)) foo; >> $$ language sql; >> >> test=# insert into x select random_str(1000), random_str(1000), random_str(1000); >> ERROR: index row size 9056 exceeds maximum 8152 for index "x_a_b_c_idx" > >Hmm, okay. As for which comes first, insert or index creation, I'm >baffled, too. I also would expect the example above would take up a >bit over 6000 bytes, but not 9000. > OK, so this seems like a data corruption bug in BRIN, actually. The ~9000 bytes is actually about right, because the strings are in UTF-8 so roughly 1.5B per character seems about right. And we have 6 values to store (3 columns, min/max for each), so 6 * 1500 = 9000. The real question is how come INSERT + CREATE INDEX actually manages to create an index tuple. And the answer is pretty simple - brin_form_tuple kinda ignores toasting, happily building index tuples where some values are toasted. Consider this: create table x (a text, b text, c text); insert into x select random_str(1000), random_str(1000), random_str(1000); create index on x using brin (a,b,c); delete from x; vacuum x; set enable_seqscan=off; insert into x select random_str(10), random_str(10), random_str(10); ERROR: missing chunk number 0 for toast value 16530 in pg_toast_16525 explain analyze select * from x where a = 'xxx'; ERROR: missing chunk number 0 for toast value 16530 in pg_toast_16525 select * from brin_page_items(get_raw_page('x_a_b_c_idx', 2), 'x_a_b_c_idx'::regclass); ERROR: missing chunk number 0 for toast value 16547 in pg_toast_16541 Interestingly enough, running the select before the insert seems to be working - not sure why. Anyway, it behaves like this since 9.5 :-( regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services