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 1h2Zlo-0000b5-4T for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Mar 2019 11:04:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h2Zlm-0002Ch-EQ for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Mar 2019 11:03:58 +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 1h2Zlm-0002Ca-5m for pgsql-bugs@lists.postgresql.org; Sat, 09 Mar 2019 11:03:58 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h2Zlk-0004Dd-20 for pgsql-bugs@lists.postgresql.org; Sat, 09 Mar 2019 11:03:57 +0000 Received: by mail-wm1-x32e.google.com with SMTP id g20so78864wmh.5 for ; Sat, 09 Mar 2019 03:03:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=xEblIgp+8ZTCiJl6np6p2vBqlnGe5TulFWudHBoVpUE=; b=UI6VT+CObsSys2GGtRZCHloA5UZxPwam9c78JTrSM+vKJY/dQWCH7zfl3HhHKtDL7v 9Vw2E6FB5iIwWGBAfYCnZhiTuvyZNrmZrCeuxraD1LOfzVdeWGJOzUcPrXQBzVEixVNo 7ndfShqV/2nw7IUrUjm4YktB1Vr1GtimdW433uW242ZhAe445czwuKRVh9QPSW3gT1hY ce38sOc7kOJuGph5R7Qa954yHNnpBgy4Y8AjTm/RyKN7q8f/WA2XTyHk1hwXtsyH2qsj HDhf7cvru4GZ4XKGpZjTvc6rChMcAyZMwhToKk3isbtw02ZXF4uTSVpYjk0JyQK5y8cr MR/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=xEblIgp+8ZTCiJl6np6p2vBqlnGe5TulFWudHBoVpUE=; b=YkaM1mX2soljzH2yfhEk7jTz4zPrOSMfoEUHmHgRa9a76upsf6j5f0DSLTUFE8qYFc Es+awVvPcK5PSnQcuCIIyk4U16s0rqTTvm2UyvicMjoj324VIHf1GbsiEF+i0te06j2w xCewTOh+nYNU5I1Ab2yVWyb6ZmLt4mJhZYSJqfWjZtTwzf237nqSR1vSM2ajjFtdNrTB ljA0iHl4SaEuEzwRyK3TzVSLnSW5Jt2ZR+mBI3yW7mAZ77/bxCSfuqu3ZyrMvkpAnpP2 METReLXzw4yQGE8oGiEQd+NEfMc0vTIC20bbteWTbQBZmb9TJ/6EcRVaf1z3VWcZCKRN JAZA== X-Gm-Message-State: APjAAAXCuBPUB2ooXHJ9VFhl4qaScFiwpmXEVws+mVi8vExMHpy9qFL/ ExXU4+jG1HW5cKiTZj6GvUL2baXe X-Google-Smtp-Source: APXvYqxWZTAf46i7AAvLsKMAmUzrdpl5/VJjpuZCYpT9oMpUbK45Vm9IHrcSAdxva0JBzYkme8TZkQ== X-Received: by 2002:a05:600c:210b:: with SMTP id u11mr11808520wml.11.1552129434515; Sat, 09 Mar 2019 03:03:54 -0800 (PST) Received: from [192.168.0.10] ([95.180.47.253]) by smtp.gmail.com with ESMTPSA id f13sm14166037wme.4.2019.03.09.03.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Mar 2019 03:03:54 -0800 (PST) Subject: Re: BUG #15653: pg_detoast_datum_packed problem From: =?UTF-8?Q?gmail_Vladimir_Kokovi=c4=87?= To: Andrew Gierth Cc: pgsql-bugs@lists.postgresql.org References: <15653-a9979a97bd11577d@postgresql.org> <8a0d54a5-1c94-aa00-7e22-7d16566839b4@gmail.com> <13b4fc8a-b790-ddec-bf02-fe99ed793a5b@gmail.com> <87a7i5b2ok.fsf@news-spur.riddles.org.uk> <5236e747-2107-35f8-6741-99298f0bd6a4@gmail.com> <87r2bg9yb2.fsf@news-spur.riddles.org.uk> Message-ID: <052d8d24-46de-e6ae-f1f2-5b12cc7ec6be@gmail.com> Date: Sat, 9 Mar 2019 12:03:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------7F73546F0F56AFD97DAD0F32" Content-Language: en-GB List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------7F73546F0F56AFD97DAD0F32 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Andrew, Definitely the problem is solved with the following version pg_bvarchar! /* SQL function: bvarchar(varchar) returns bytea */ PG_FUNCTION_INFO_V1(pg_bvarchar); Datum pg_bvarchar(PG_FUNCTION_ARGS) {   VarChar *arg = PG_GETARG_VARCHAR_PP(0);   unsigned len;   bytea *res;   len = VARSIZE_ANY_EXHDR(arg);   res = (text *) palloc(len + VARHDRSZ);   SET_VARSIZE(res, len + VARHDRSZ);   memcpy(VARDATA(res), VARDATA_ANY(arg), len);   PG_RETURN_BYTEA_P(res); } 'select' has passed and no more warnigs. Thanks again. Vladimir Koković, DP senior(69) Belgrade, Mar. 9 2019 On 9.3.19. 11:54, gmail Vladimir Koković wrote: > > Hi Andrew, > > I forgot to show the final version of pg_bvarchar. > > /* SQL function: bvarchar(varchar) returns bytea */ > > PG_FUNCTION_INFO_V1(pg_bvarchar); > Datum pg_bvarchar(PG_FUNCTION_ARGS) { >   VarChar *arg = PG_GETARG_VARCHAR_PP(0); >   unsigned len; >   bytea *res; > >   len = VARSIZE_ANY_EXHDR(arg); >   res = (text *) palloc(len); >   SET_VARSIZE(res, len + VARHDRSZ); >   memcpy(VARDATA(res), VARDATA_ANY(arg), len); >   PG_RETURN_BYTEA_P(res); > } > > On 9.3.19. 11:08, gmail Vladimir Koković wrote: >> >> Hi Andrew, >> >> You are absolutely right and "select ", OID from ispp_wmpl where >> (bvarchar (key))> = (bvarchar ('W' :: varchar)) and (bvarchar (key)) >> <= (bvarchar ~~~~~~~~ ':: varchar)) order by key" has passed! >> However, pg log file now has hundreds of warning message: 2019-03-09 >> 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: >> problem in allocation set ExprContext: detected write past chunk end >> block 0x55ccb0b36468, chunk 0x55ccb0b36490 2019-03-09 10:53:29 CET >> ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in >> allocation set ExprContext: detected write past chunk end in block >> 0x55ccb0b36468, chunk 0x55ccb0b36490 2019-03-09 10:53:29 CET >> ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in >> allocation set ExprContext: detected write past chunk end in block >> 0x55ccb0b36468, chunk 0x55ccb0b36490 ... Andrew, I have to thank you >> for this help because without this, my 'select' would never have passed. Vladimir Koković, DP senior(69) >> Belgrade, Mar. 9 2019 >> >> On 9.3.19. 10:48, Andrew Gierth wrote: > >> "gmail" == gmail Vladimir Koković writes: >>> gmail> Hi Andrew. >>> gmail> I changed VARSIZE to VARSIZE_ANY_EXHDR and VARDATA in >>> gmail> VARDATA_ANY as you said, but there is still a problem I can not >>> gmail> understand ! >>> >>> Your message formatting was all messed up, but I can see that you are >>> still subtracting VARHDRSZ - don't do that: VARSIZE_ANY_EXHDR already >>> has the header size subtracted (hence "EXHDR"), it returns only the data >>> size. (The header size is variable, 1 or 4 bytes, so it wouldn't make >>> sense to include it.) >>> --------------7F73546F0F56AFD97DAD0F32 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Andrew,

Definitely the problem is solved with the following version pg_bvarchar!

/* SQL function: bvarchar(varchar) returns bytea */

PG_FUNCTION_INFO_V1(pg_bvarchar);
Datum pg_bvarchar(PG_FUNCTION_ARGS) {
  VarChar *arg = PG_GETARG_VARCHAR_PP(0);
  unsigned len;
  bytea *res;

  len = VARSIZE_ANY_EXHDR(arg);
  res = (text *) palloc(len + VARHDRSZ);
  SET_VARSIZE(res, len + VARHDRSZ);
  memcpy(VARDATA(res), VARDATA_ANY(arg), len);
  PG_RETURN_BYTEA_P(res);
}

'select' has passed and no more warnigs.

Thanks again.

Vladimir Koković, DP senior(69)
Belgrade, Mar. 9 2019


On 9.3.19. 11:54, gmail Vladimir Koković wrote:

Hi Andrew,

I forgot to show the final version of pg_bvarchar.

/* SQL function: bvarchar(varchar) returns bytea */

PG_FUNCTION_INFO_V1(pg_bvarchar);
Datum pg_bvarchar(PG_FUNCTION_ARGS) {
  VarChar *arg = PG_GETARG_VARCHAR_PP(0);
  unsigned len;
  bytea *res;

  len = VARSIZE_ANY_EXHDR(arg);
  res = (text *) palloc(len);
  SET_VARSIZE(res, len + VARHDRSZ);
  memcpy(VARDATA(res), VARDATA_ANY(arg), len);
  PG_RETURN_BYTEA_P(res);
}


On 9.3.19. 11:08, gmail Vladimir Koković wrote:

Hi Andrew,

You are absolutely right and "select ", OID from ispp_wmpl where (bvarchar (key))> = (bvarchar ('W' :: varchar)) and (bvarchar (key)) <= (bvarchar ~~~~~~~~ ':: varchar)) order by key" has passed!

However, pg log file now has hundreds of warning message:
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end block 0x55ccb0b36468, chunk 0x55ccb0b36490
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end in block 0x55ccb0b36468, chunk 0x55ccb0b36490
2019-03-09 10:53:29 CET ispp-pionir-test :: 1 (53858) 14721 0 01000 WARNING: problem in allocation set ExprContext: detected write past chunk end in block 0x55ccb0b36468, chunk 0x55ccb0b36490 
...
Andrew, I have to thank you for this help because without this, my 'select' would never have passed.


Vladimir Koković, DP senior(69)
Belgrade, Mar. 9 2019

On 9.3.19. 10:48, Andrew Gierth wrote:

"gmail" == gmail Vladimir Koković <vladimir.kokovic@gmail.com> writes:
 gmail> Hi Andrew.
 gmail> I changed VARSIZE to VARSIZE_ANY_EXHDR and VARDATA in
 gmail> VARDATA_ANY as you said, but there is still a problem I can not
 gmail> understand !

Your message formatting was all messed up, but I can see that you are
still subtracting VARHDRSZ - don't do that: VARSIZE_ANY_EXHDR already
has the header size subtracted (hence "EXHDR"), it returns only the data
size. (The header size is variable, 1 or 4 bytes, so it wouldn't make
sense to include it.)

--------------7F73546F0F56AFD97DAD0F32--