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 1jo79X-0008Py-1K for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 15:17:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jo79U-0003sv-D5 for pgsql-general@arkaria.postgresql.org; Wed, 24 Jun 2020 15:17:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jo79U-0003sh-5C for pgsql-general@lists.postgresql.org; Wed, 24 Jun 2020 15:17:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jo79R-0007mi-GL for pgsql-general@postgresql.org; Wed, 24 Jun 2020 15:17:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05OFHKgx2206077; Wed, 24 Jun 2020 11:17:20 -0400 From: Tom Lane To: David Rowley cc: Jaime Soler , Fabien COELHO , PostgreSQL mailing lists Subject: Re: pgbench and timestamps In-reply-to: <2203820.1593008123@sss.pgh.pa.us> References: <2203820.1593008123@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 24 Jun 2020 10:15:23 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2206075.1593011840.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 24 Jun 2020 11:17:20 -0400 Message-ID: <2206076.1593011840@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > David Rowley writes: >> I don't often do much with pgbench and variables, but there are a few >> things that surprise me here. >> 1) That pgbench replaces variables within single quotes, and; >> 2) that we still think it's a variable name when it starts with a digit= , and; >> 3) We replace variables that are undefined. > Also (4) this only happens when in non-simple query mode --- the > example works fine without "-M prepared". After looking around in the code, it seems like the core of the issue is that pgbench.c's parseQuery() doesn't check whether a possible variable name is actually defined, unlike assignVariables() which is what does the same job in simple query mode. So that explains the behavioral difference. The reason for doing that probably was that parseQuery() is run when the input file is read, so that relevant variables might not be set yet. We could fix that by postponing the work to be done at first execution of the query, as is already the case for PQprepare'ing the query. Also, after further thought I realize that (1) absolutely is a bug in the non-simple query modes, whatever you think about it in simple mode. The non-simple modes are trying to pass the variable values as extended-query-protocol parameters, and the backend is not going to recognize $n inside a literal as being a parameter. If we fixed (1) and (3) I think there wouldn't be any great need to tighten up (2). regards, tom lane