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 1kFRXk-0004Bm-JV for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2020 00:31:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kFRXj-0006hG-8O for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2020 00:31:27 +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 1kFRXj-0006h8-1l for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2020 00:31:27 +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 1kFRXf-0000AO-Q8 for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2020 00:31:26 +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 0880VB5d1720049; Mon, 7 Sep 2020 20:31:12 -0400 From: Tom Lane To: Fabien COELHO cc: PostgreSQL Developers , David Rowley , Jaime Soler Subject: Re: pgbench and timestamps (bounced) In-reply-to: References: Comments: In-reply-to Fabien COELHO message dated "Mon, 29 Jun 2020 17:43:01 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1720047.1599525071.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 07 Sep 2020 20:31:11 -0400 Message-ID: <1720048.1599525071@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Fabien COELHO writes: > [Resent on hackers for CF registration, sorry for the noise] For the record, the original thread is at https://www.postgresql.org/message-id/flat/CAKVUGgQaZVAUi1Ex41H4wrru%3DFU%= 2BMfwgjG0aM1br6st7sz31Vw%40mail.gmail.com (I tried but failed to attach that thread to the CF entry, so we'll have to settle for leaving a breadcrumb in this thread.) > It requires a mutex around the commands, I tried to do some windows = > implementation which may or may not work. Ugh, I'd really rather not do that. Even disregarding the effects of a mutex, though, my initial idea for fixing this has a big problem: if we postpone PREPARE of the query until first execution, then it's happening during timed execution of the benchmark scenario and thus distorting the timing figures. (Maybe if we'd always done it like that, it'd be okay, but I'm quite against changing the behavior now that it's stood for a long time.) However, perhaps there's more than one way to fix this. Once we've scanned all of the script and seen all the \set commands, we know (in principle) the set of all variable names that are in use. So maybe we could fix this by (1) During the initial scan of the script, make variable-table entries for every \set argument, with the values shown as undefined for the moment. Do not try to parse SQL commands in this scan, just collect them. (2) Make another scan in which we identify variable references in the SQL commands and issue PREPAREs (if enabled). (3) Perform the timed run. This avoids any impact of this bug fix on the semantics or timing of the benchmark proper. I'm not sure offhand whether this approach makes any difference for the concerns you had about identifying/suppressing variable references inside quotes. regards, tom lane