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 1o1eVm-0007mi-SS for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jun 2022 01:41:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o1eVl-0006L6-MS for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jun 2022 01:41:29 +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 1o1eVl-0006Kx-BA for pgsql-hackers@lists.postgresql.org; Thu, 16 Jun 2022 01:41:29 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o1eVi-0000UL-79 for pgsql-hackers@lists.postgresql.org; Thu, 16 Jun 2022 01:41:28 +0000 Received: by mail-pj1-x1036.google.com with SMTP id v11-20020a17090a4ecb00b001e2c5b837ccso433034pjl.3 for ; Wed, 15 Jun 2022 18:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=CntuaHafadl3woA6ln1Aheznd0LjTMSPi2EXeoIe56k=; b=KrGebRZE5gXDeXn+HdST/zFPH3QiipRIu8RmePmGmWSAJEAXCrgAPM2yH4Df/FMKFs 6QffvnIKuRTqeYa79nX1GTSJkTZIOxjea0VQSGqMvu/83bNRrUccq4Yg+aJMjlvPrY/H X5fpnZXVslPk22/bv7fHaiqhSX0i6Z93CJhNjG6nu4E+tWEx2qsKHTK3Ums01b7HiFcr 75Zg+u7Vx/tJWt2GsenHQLWDwEAbtIQOu/ZUG0iGFmYnbuT17qJ6MbsM8u+ZJOVA6VpI NBTKIPJvYTQYizYf8Ploae2DeDo9Uty+2tHsdHQqEvDctctaaYqDec2FJS0pqAkApf12 YEvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=CntuaHafadl3woA6ln1Aheznd0LjTMSPi2EXeoIe56k=; b=YNAU4ZJaEocDpgUsKHRZ5mKPr+ZBndvynkE5TW3RTl6Z1aLRPdQ3e2EGZNJ6hhrLcJ FY9pOoXsjVKLtJe+Y8pqFNO5GV29aM44hZEcsOVWvgYKdyfsXduKoOcp8SJF+RE5tYfL xul2bnjxfqtLB6riqFvY/LD32yvDmcl6mygvm3QQScHFGenQ9P82RDCHJvvik6vnB+Lt bbB/3UU1+I+Nil6HKgxXUhJjh0qs6/yrXXoW5hYLfN5Gh6keLQ/3bIX625EYzwS5saU/ uPCKmRLBu6I9u0lFc5ENi6IJMK/GIPkPSF64dG9hUvYi8KiaKVOwGvBD39UunU7TbUgS rGMg== X-Gm-Message-State: AJIora/l4E4IHme4L4FqUvqGgVv14lwB/ROXCkla6Txv9PRrJmFFAM8V dBrL6hF8hQtbvMFUV0FpdaA= X-Google-Smtp-Source: AGRyM1sQuRqXsnj4iTWOI7ZEw4UrWicIkpaQ7iUWRgK9z4kYk/6oRdNx+YHE8hvDm8ZFSfVdPggMAg== X-Received: by 2002:a17:90b:1bd0:b0:1e8:9ac9:c3ec with SMTP id oa16-20020a17090b1bd000b001e89ac9c3ecmr2413267pjb.117.1655343685147; Wed, 15 Jun 2022 18:41:25 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id g15-20020a62e30f000000b0051c0fe8fb8csm304126pfh.95.2022.06.15.18.41.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Jun 2022 18:41:24 -0700 (PDT) Date: Thu, 16 Jun 2022 10:41:21 +0900 (JST) Message-Id: <20220616.104121.1499221777899715.horikyota.ntt@gmail.com> To: tgl@sss.pgh.pa.us Cc: alvherre@alvh.no-ip.org, daniele.varrazzo@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: Using PQexecQuery in pipeline mode produces unexpected Close messages From: Kyotaro Horiguchi In-Reply-To: <20220616.103422.2111499217922924771.horikyota.ntt@gmail.com> References: <20220615182633.ztcoloh7xbicggot@alvherre.pgsql> <532816.1655319402@sss.pgh.pa.us> <20220616.103422.2111499217922924771.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Thu, 16 Jun 2022 10:34:22 +0900 (JST), Kyotaro Horiguchi wrote in > At Wed, 15 Jun 2022 14:56:42 -0400, Tom Lane wrote in > > Alvaro Herrera writes: > > > So, git archaeology led me to this thread > > > https://postgr.es/m/202106072107.d4i55hdscxqj@alvherre.pgsql > > > which is why we added that message in the first place. > > > > Um. Good thing you looked. I doubt we want to revert that change now. > > > > > Alternatives: > > > - Have the client not complain if it gets CloseComplete in idle state. > > > (After all, it's a pretty useless message, since we already do nothing > > > with it if we get it in BUSY state.) > > > > ISTM the actual problem here is that we're reverting to IDLE state too > > soon. I didn't try to trace down exactly where that's happening, but > > Yes. I once visited that fact but also I thought that in the > comparison with non-pipelined PQsendQuery, the three messages look > extra. Thus I concluded (at the time) that removing Close is enough > here. > > > I notice that in the non-pipeline case we don't go to IDLE till we've > > seen 'Z' (Sync). Something in the pipeline logic must be jumping the > > gun on that state transition. > - PQgetResult() resets the state to IDLE when not in pipeline mode. D... the "not" should not be there. + PQgetResult() resets the state to IDLE while in pipeline mode. > fe-exec.c:2171 > > > if (conn->pipelineStatus != PQ_PIPELINE_OFF) > > { > > /* > > * We're about to send the results of the current query. Set > > * us idle now, and ... > > */ > > conn->asyncStatus = PGASYNC_IDLE; > > And actually that code let the connection state enter to IDLE before > CloseComplete. In the test case I posted, the following happens. > > PQsendQuery(conn, "SELECT 1;"); > PQsendFlushRequest(conn); > PQgetResult(conn); // state enters IDLE, reads down to > PQgetResult(conn); // reads > PQpipelineSync(conn); // sync too late > > Pipeline feature seems intending to allow PQgetResult called before > PQpipelineSync. And also seems allowing to call QPpipelineSync() after > PQgetResult(). > > I haven't come up with a valid *fix* of this flow.. regards. -- Kyotaro Horiguchi NTT Open Source Software Center