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 1lwLDt-0002wf-D8 for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jun 2021 09:00:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lwLDq-0008Fy-8S for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jun 2021 09:00:30 +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 1lwLDp-0008Fq-W7 for pgsql-hackers@lists.postgresql.org; Thu, 24 Jun 2021 09:00:30 +0000 Received: from codesynthesis.com ([188.40.148.39]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwLDn-0002H1-RT for pgsql-hackers@lists.postgresql.org; Thu, 24 Jun 2021 09:00:29 +0000 Received: from brak.codesynthesis.com (unknown [105.225.47.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by codesynthesis.com (Postfix) with ESMTPSA id 3B6355FB23; Thu, 24 Jun 2021 09:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codesynthesis.com; s=mail1; t=1624525225; bh=jMTy3xCK9SL0hdcdUAjNBhmMbChNRKJ2L4zMJKcniXs=; h=Date:From:To:Subject:Message-ID:MIME-Version:From; b=vNZS+ks6ngrsDXTl3NJ61uFq7/dkO2+KTBWX2Eofrl9KSV0nhfRnJQJB3l52Gl1AE XUuO0iF/pom/IzUOonisimywgUZCo/S0ihiSFnpC4ouLKheJn1jZZt/e5BanHJ6f6z HFPGXvb+kZdWuYXPlbaRDC+PiudXiFmKw8x3uNzBBu7+yaxQia1IbWEgJt2ZPA1zhL qBJC6/yyhXB4qMrx5yw/7kBFSwKtyVtO2VclJzCSwTqIvwEgUllT+MfGCJ7TH7GR37 Av5iBtKxbA07hDd5lqw4B+U8NdedeG0ikb30tWnY20gpCjw5RHslIxczxu9BrBysqk yNq/fKGPoiKvQ== Received: by brak.codesynthesis.com (Postfix, from userid 1000) id 4C1681A802C0; Thu, 24 Jun 2021 11:00:20 +0200 (SAST) Date: Thu, 24 Jun 2021 11:00:20 +0200 From: Boris Kolpackov To: Alvaro Herrera Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Pipeline mode and PQpipelineSync() Message-ID: References: <202106222214.ptjfmstb23mu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Code Synthesis User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Boris Kolpackov writes: > What's strange here is that the first PQgetResult() call (marked with ???) > returns NULL instead of result for INSERT #1 as in the first call sequence. I've hit another similar case except now an unexpected NULL result is returned in the middle of PGRES_PIPELINE_ABORTED result sequence. The call sequence is as follows: PQsendQueryPrepared() # INSERT #1 PQflush() PQsendQueryPrepared() # INSERT #2 PQflush() ... PQsendQueryPrepared() # INSERT #251 -- insert duplicate PK PQflush() ... PQsendQueryPrepared() # INSERT #343 PQflush() PQconsumeInput() # At this point select() indicates we can read. PQgetResult() # NULL -- unexpected but skipped (see prev. email) PQgetResult() # INSERT #1 PQgetResult() # NULL PQgetResult() # INSERT #2 PQgetResult() # NULL ... PQgetResult() # INSERT #251 error result, SQLSTATE 23505 PQgetResult() # NULL PQgetResult() # INSERT #252 PGRES_PIPELINE_ABORTED PQgetResult() # NULL PQgetResult() # INSERT #253 PGRES_PIPELINE_ABORTED PQgetResult() # NULL ... PQgetResult() # INSERT #343 NULL (???) Notice that result #343 corresponds to the last PQsendQueryPrepared() call made before the socket became readable (it's not always 343 but around there). For completeness, the statement in question is: INSERT INTO pgsql_bulk_object (id, idata, sdata) VALUES ($1, $2, $3) The table: CREATE TABLE pgsql_bulk_object ( id BIGINT NOT NULL PRIMARY KEY, idata BIGINT NOT NULL, sdata TEXT NOT NULL); And the data inserted is in the form: 1, 1, "1" 2, 2, "2" ...