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 1hj5p5-0000jn-2H for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jul 2019 17:47:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hj5p3-0006bO-Tt for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jul 2019 17:47:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj5p3-0006bH-Hg for pgsql-hackers@lists.postgresql.org; Thu, 04 Jul 2019 17:47:05 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj5p0-0003Tz-8C for pgsql-hackers@postgresql.org; Thu, 04 Jul 2019 17:47:04 +0000 Received: by mail-wr1-x434.google.com with SMTP id x4so7404498wrt.6 for ; Thu, 04 Jul 2019 10:47:01 -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:content-transfer-encoding:in-reply-to :user-agent; bh=obDdmOmNH7LeyFdjb0Q6mHYjd71IyTtYKgZCcrXkRj8=; b=pzsD0kBugKUtkqZhQy9s0699jnz6QYIRGVEa58ZO426gIjiKlTaDpe+v3/GPDI6LuH c4ZA5aNNyDVAFdiqwqKfEsPfm+WKG46HOoMk153r3fz9IM098Sm9rrsehcESYXc2uOcA e037svbDt2BSFLsWJu5hrYB1jj92o4ASJ4+DD9wFDXKrI27SgoNWFrTHIL8R/6iXfKd6 MrWxxrsyXVyH+EpM3qrqm3q7ZCseHdqrhi1VkqanoKV/ILgzG2p99AKVnqJD6nbkOsjS jsjplmyr9S5thHEiVrsyOy1IIBHrT+A1ZnjG9980/5dldEuILtJoV7C3/OilpybPwOyF exsQ== 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:content-transfer-encoding :in-reply-to:user-agent; bh=obDdmOmNH7LeyFdjb0Q6mHYjd71IyTtYKgZCcrXkRj8=; b=A9Ig/rQurXfFWJ5vC7o2qSFiP0xHc8zZImbZf4mUiz/b2N5ImvlQI2BNlncTz3bExR s2wRwyumoYgMWa1PvuCC2Jf7wcw3Ixsc5n64BofSdDaYRNG1MItcOTfiG3x6PJqRtEIN R07HNXO2vM7y4ucKnpfkfmkWWh7KXHZHYmqLIQnB8sMdAoXnRLTkWbUuTeSfT74oY52a XGX3a9ZXoQJOESnflRUbPru5n2CPCwFy9bc+HZfuO+No+ksz2Re9tmS6L5AdQ6LALzPd eFvmoSkweU45ph0DucTXOd8ig+QIzMf8pi9RmodEfdSOoZTgauhYl16Fczz/yvWFcHqM SgZQ== X-Gm-Message-State: APjAAAVeKUsvhPvrhB40P17KcP9DLcnjeiQwU3It1ubzaqY8Ve95ci71 CGG3XvbnOnRm+oYvaazejQLHtQ== X-Google-Smtp-Source: APXvYqy2vfzpoLkbaQBFoGJ2LoOj5QIJgqGO5ZacTZFhBorP/1mSZghATdj8gqR6VX9CpVGm2SLNPQ== X-Received: by 2002:a5d:6b11:: with SMTP id v17mr20754356wrw.323.1562262419195; Thu, 04 Jul 2019 10:46:59 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id v67sm8359661wme.24.2019.07.04.10.46.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 10:46:56 -0700 (PDT) Date: Thu, 4 Jul 2019 19:46:54 +0200 From: Tomas Vondra To: Andrey Borodin Cc: Binguo Bao , Paul Ramsey , Pgsql Hackers Subject: Re: Optimize partial TOAST decompression Message-ID: <20190704174654.vnvkh7rusv25o6f5@development> References: <7B7E4A05-F404-4083-B7F2-267869EE2910@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jul 04, 2019 at 11:10:24AM +0200, Andrey Borodin wrote: > >> 3 июля 2019 г., в 18:06, Binguo Bao написал(а): >> >> Paul Ramsey 于2019年7月2日周二 下午10:46写道: >> This looks good to me. A little commentary around why >> pglz_maximum_compressed_size() returns a universally correct answer >> (there's no way the compressed size can ever be larger than this >> because...) would be nice for peasants like myself. >> ... >> >> Thanks for your comment. I've updated the patch. > > > Thanks Biguo and Paul! From my POV patch looks ready for committer, so I switched state on CF. > I've done a bit of testing and benchmaring on this patch today, and there's a bug somewhere, making it look like there are corrupted data. What I'm seeing is this: CREATE TABLE t (a text); -- attached is data for one row COPY t FROM '/tmp/t.data'; SELECT length(substr(a,1000)) from t; psql: ERROR: compressed data is corrupted SELECT length(substr(a,0,1000)) from t; length -------- 999 (1 row) SELECT length(substr(a,1000)) from t; psql: ERROR: invalid memory alloc request size 2018785106 That's quite bizarre behavior - it does work with a prefix, but not with suffix. And the exact ERROR changes after the prefix query. (Of course, on master it works in all cases.) The backtrace (with the patch applied) looks like this: #0 toast_decompress_datum (attr=0x12572e0) at tuptoaster.c:2291 #1 toast_decompress_datum (attr=0x12572e0) at tuptoaster.c:2277 #2 0x00000000004c3b08 in heap_tuple_untoast_attr_slice (attr=, sliceoffset=0, slicelength=-1) at tuptoaster.c:315 #3 0x000000000085c1e5 in pg_detoast_datum_slice (datum=, first=, count=) at fmgr.c:1767 #4 0x0000000000833b7a in text_substring (str=133761519127512, start=0, length=, length_not_specified=) at varlena.c:956 ... I've only observed this with a very small number of rows (the data is generated randomly with different compressibility etc.), so I'm only attaching one row that exhibits this issue. My guess is toast_fetch_datum_slice() gets confused by the headers or something, or something like that. FWIW the new code added to this function does not adhere to our code style, and would deserve some additional explanation of what it's doing/why. Same for the heap_tuple_untoast_attr_slice, BTW. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services