Skip to content

sql/pgwire: Sync command should destroy named portals when outside of explicit txn #71665

@rafiss

Description

@rafiss

Describe the problem

According to https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY

If successfully created, a named portal object lasts till the end of the current transaction

In other words, after Sync is issued and there is no explicit transaction, the portal that was bound using Bind is destroyed. However, CRDB doesn't implement this behavior.

Indeed, if you try this test against Postgres, it results in portal "p8" does not exist

To Reproduce

The following pgwire test matches the Postgres behavior

send
Parse {"Name": "s8", "Query": "SELECT oid, relname FROM pg_class WHERE oid = $1::regclass;"}
Bind {"DestinationPortal": "p8", "PreparedStatement": "s8", "ResultFormatCodes": [0], "Parameters": [{"text":"t"}]}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Execute {"Portal": "p8"}
Sync
----

until
ErrorResponse
ReadyForQuery
----
{"Type":"ErrorResponse","Code":"34000"}
{"Type":"ReadyForQuery","TxStatus":"I"}

Running against CRDB with make test PKG=./pkg/sql/pgwire TESTS='TestPGTest fails

Expected behavior

The above test should pass

Additional context
I wonder if this is related to the OOM we saw in #69317

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sql-pgwirepgwire protocol issues.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions