Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgwire: multiple active result sets (portals) not supported #40195

Closed
jordanlewis opened this issue Aug 24, 2019 · 35 comments
Closed

pgwire: multiple active result sets (portals) not supported #40195

jordanlewis opened this issue Aug 24, 2019 · 35 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-pgwire pgwire protocol issues. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-anchored-telemetry The issue number is anchored by telemetry references.

Comments

@jordanlewis
Copy link
Member

jordanlewis commented Aug 24, 2019

CockroachDB does not currently support multiple active pgwire portals on the same session. This means that you can't perform the following sequence of events:

  1. open portal for query a, which will eventually return 1000 rows
  2. ask for 500 rows of query a
  3. open portal for query b
  4. ask for 500 rows of query b
  5. ask for 500 rows of query a

This sequence will fail at step 3, unless the user closes the portal for query a first, in which case this sequence will fail at step 5.

Jira issue: CRDB-5559
Epic: CRDB-17622

@jordanlewis jordanlewis added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-pgwire pgwire protocol issues. X-anchored-telemetry The issue number is anchored by telemetry references. labels Aug 24, 2019
craig bot pushed a commit that referenced this issue Aug 26, 2019
39778: exec: support comparisons between all numeric types r=rafiss a=rafiss

The vectorized engine now supports comparisons between floats, ints, and
decimals.

touches #39189

Release note: None

40197: pgwire: improve multiple portal error msgs r=jordanlewis a=jordanlewis

And relink to new issue (#40195).

Release note: None

40203: builtins: fix bug in aclexplode; add tests r=jordanlewis a=jordanlewis

Closes #39794.

Release note: None

Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
jordanlewis added a commit to jordanlewis/cockroach that referenced this issue Oct 2, 2019
The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep
up to date. If we write down blacklists in code, then we can use an approach
like this to always have an up to date aggregation.

So far it seems like there's just a lot of unknowns to categorize still.

The output today:

```
=== RUN   TestBlacklists
 648: unknown                                                (unknown)
 493: cockroachdb#5807   (sql: Add support for TEMP tables)
 151: cockroachdb#17511  (sql: support stored procedures)
  86: cockroachdb#26097  (sql: make TIMETZ more pg-compatible)
  56: cockroachdb#10735  (sql: support SQL savepoints)
  55: cockroachdb#32552  (multi-dim arrays)
  55: cockroachdb#26508  (sql: restricted DDL / DML inside transactions)
  52: cockroachdb#32565  (sql: support optional TIME precision)
  39: cockroachdb#243    (roadmap: Blob storage)
  33: cockroachdb#26725  (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea))
  31: cockroachdb#27793  (sql: support custom/user-defined base scalar (primitive) types)
  24: cockroachdb#12123  (sql: Can't drop and replace a table within a transaction)
  24: cockroachdb#26443  (sql: support user-defined schemas between database and table)
  20: cockroachdb#21286  (sql: Add support for geometric types)
  18: cockroachdb#6583   (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait}))
  17: cockroachdb#22329  (Support XA distributed transactions in CockroachDB)
  16: cockroachdb#24062  (sql: 32 bit SERIAL type)
  16: cockroachdb#30352  (roadmap:when CockroachDB  will support cursor?)
  12: cockroachdb#27791  (sql: support RANGE types)
   8: cockroachdb#40195  (pgwire: multiple active result sets (portals) not supported)
   8: cockroachdb#6130   (sql: add support for key watches with notifications of changes)
   5: Expected Failure                                       (unknown)
   5: cockroachdb#23468  (sql: support sql arrays of JSONB)
   5: cockroachdb#40854  (sql: set application_name from connection string)
   4: cockroachdb#35879  (sql: `default_transaction_read_only` should also accept 'on' and 'off')
   4: cockroachdb#32610  (sql: can't insert self reference)
   4: cockroachdb#40205  (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE)
   4: cockroachdb#35897  (sql: unknown function: pg_terminate_backend())
   4: cockroachdb#4035   (sql/pgwire: missing support for row count limits in pgwire)
   3: cockroachdb#27796  (sql: support user-defined DOMAIN types)
   3: cockroachdb#3781   (sql: Add Data Type Formatting Functions)
   3: cockroachdb#40476  (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`)
   3: cockroachdb#35882  (sql: support other character sets)
   2: cockroachdb#10028  (sql: Support view queries with star expansions)
   2: cockroachdb#35807  (sql: INTERVAL output doesn't match PG)
   2: cockroachdb#35902  (sql: large object support)
   2: cockroachdb#40474  (sql: support `SELECT ... FOR UPDATE OF` syntax)
   1: cockroachdb#18846  (sql: Support CIDR column type)
   1: cockroachdb#9682   (sql: implement computed indexes)
   1: cockroachdb#31632  (sql: FK options (deferrable, etc))
   1: cockroachdb#24897  (sql: CREATE OR REPLACE VIEW)
   1: pass?                                                  (unknown)
   1: cockroachdb#36215  (sql: enable setting standard_conforming_strings to off)
   1: cockroachdb#32562  (sql: support SET LOCAL and txn-scoped session variable changes)
   1: cockroachdb#36116  (sql: psychopg: investigate how `'infinity'::timestamp` is presented)
   1: cockroachdb#26732  (sql: support the binary operator: <int> / <float>)
   1: cockroachdb#23299  (sql: support coercing string literals to arrays)
   1: cockroachdb#36115  (sql: psychopg: investigate if datetimetz is being returned instead of datetime)
   1: cockroachdb#26925  (sql: make the CockroachDB integer types more compatible with postgres)
   1: cockroachdb#21085  (sql: WITH RECURSIVE (recursive common table expressions))
   1: cockroachdb#36179  (sql: implicity convert date to timestamp)
   1: cockroachdb#36118  (sql: Cannot parse '24:00' as type time)
   1: cockroachdb#31708  (sql: support current_time)
```

Release justification: non-production change
Release note: None
@rafiss
Copy link
Collaborator

rafiss commented Oct 7, 2019

The pgjcbc test org.postgresql.test.jdbc2.CursorFetchTest.testGetRow used to fail because of this lack of support, but that test started passing. I don't know why. #41366

jordanlewis added a commit to jordanlewis/cockroach that referenced this issue Oct 24, 2019
The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep
up to date. If we write down blacklists in code, then we can use an approach
like this to always have an up to date aggregation.

So far it seems like there's just a lot of unknowns to categorize still.

The output today:

```
=== RUN   TestBlacklists
 648: unknown                                                (unknown)
 493: cockroachdb#5807   (sql: Add support for TEMP tables)
 151: cockroachdb#17511  (sql: support stored procedures)
  86: cockroachdb#26097  (sql: make TIMETZ more pg-compatible)
  56: cockroachdb#10735  (sql: support SQL savepoints)
  55: cockroachdb#32552  (multi-dim arrays)
  55: cockroachdb#26508  (sql: restricted DDL / DML inside transactions)
  52: cockroachdb#32565  (sql: support optional TIME precision)
  39: cockroachdb#243    (roadmap: Blob storage)
  33: cockroachdb#26725  (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea))
  31: cockroachdb#27793  (sql: support custom/user-defined base scalar (primitive) types)
  24: cockroachdb#12123  (sql: Can't drop and replace a table within a transaction)
  24: cockroachdb#26443  (sql: support user-defined schemas between database and table)
  20: cockroachdb#21286  (sql: Add support for geometric types)
  18: cockroachdb#6583   (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait}))
  17: cockroachdb#22329  (Support XA distributed transactions in CockroachDB)
  16: cockroachdb#24062  (sql: 32 bit SERIAL type)
  16: cockroachdb#30352  (roadmap:when CockroachDB  will support cursor?)
  12: cockroachdb#27791  (sql: support RANGE types)
   8: cockroachdb#40195  (pgwire: multiple active result sets (portals) not supported)
   8: cockroachdb#6130   (sql: add support for key watches with notifications of changes)
   5: Expected Failure                                       (unknown)
   5: cockroachdb#23468  (sql: support sql arrays of JSONB)
   5: cockroachdb#40854  (sql: set application_name from connection string)
   4: cockroachdb#35879  (sql: `default_transaction_read_only` should also accept 'on' and 'off')
   4: cockroachdb#32610  (sql: can't insert self reference)
   4: cockroachdb#40205  (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE)
   4: cockroachdb#35897  (sql: unknown function: pg_terminate_backend())
   4: cockroachdb#4035   (sql/pgwire: missing support for row count limits in pgwire)
   3: cockroachdb#27796  (sql: support user-defined DOMAIN types)
   3: cockroachdb#3781   (sql: Add Data Type Formatting Functions)
   3: cockroachdb#40476  (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`)
   3: cockroachdb#35882  (sql: support other character sets)
   2: cockroachdb#10028  (sql: Support view queries with star expansions)
   2: cockroachdb#35807  (sql: INTERVAL output doesn't match PG)
   2: cockroachdb#35902  (sql: large object support)
   2: cockroachdb#40474  (sql: support `SELECT ... FOR UPDATE OF` syntax)
   1: cockroachdb#18846  (sql: Support CIDR column type)
   1: cockroachdb#9682   (sql: implement computed indexes)
   1: cockroachdb#31632  (sql: FK options (deferrable, etc))
   1: cockroachdb#24897  (sql: CREATE OR REPLACE VIEW)
   1: pass?                                                  (unknown)
   1: cockroachdb#36215  (sql: enable setting standard_conforming_strings to off)
   1: cockroachdb#32562  (sql: support SET LOCAL and txn-scoped session variable changes)
   1: cockroachdb#36116  (sql: psychopg: investigate how `'infinity'::timestamp` is presented)
   1: cockroachdb#26732  (sql: support the binary operator: <int> / <float>)
   1: cockroachdb#23299  (sql: support coercing string literals to arrays)
   1: cockroachdb#36115  (sql: psychopg: investigate if datetimetz is being returned instead of datetime)
   1: cockroachdb#26925  (sql: make the CockroachDB integer types more compatible with postgres)
   1: cockroachdb#21085  (sql: WITH RECURSIVE (recursive common table expressions))
   1: cockroachdb#36179  (sql: implicity convert date to timestamp)
   1: cockroachdb#36118  (sql: Cannot parse '24:00' as type time)
   1: cockroachdb#31708  (sql: support current_time)
```

Release justification: non-production change
Release note: None
craig bot pushed a commit that referenced this issue Nov 7, 2019
41252: roachtest: add test that aggregates orm blacklist failures r=jordanlewis a=jordanlewis

The spreadsheet we discussed is unwieldy - hard to edit and impossible to keep
up to date. If we write down blacklists in code, then we can use an approach
like this to always have an up to date aggregation.

So far it seems like there's just a lot of unknowns to categorize still.

The output today:

```
=== RUN   TestBlacklists
 648: unknown                                                (unknown)
 493: #5807   (sql: Add support for TEMP tables)
 151: #17511  (sql: support stored procedures)
  86: #26097  (sql: make TIMETZ more pg-compatible)
  56: #10735  (sql: support SQL savepoints)
  55: #32552  (multi-dim arrays)
  55: #26508  (sql: restricted DDL / DML inside transactions)
  52: #32565  (sql: support optional TIME precision)
  39: #243    (roadmap: Blob storage)
  33: #26725  (sql: support postgres' API to handle blob storage (incl lo_creat, lo_from_bytea))
  31: #27793  (sql: support custom/user-defined base scalar (primitive) types)
  24: #12123  (sql: Can't drop and replace a table within a transaction)
  24: #26443  (sql: support user-defined schemas between database and table)
  20: #21286  (sql: Add support for geometric types)
  18: #6583   (sql: explicit lock syntax (SELECT FOR {SHARE,UPDATE} {skip locked,nowait}))
  17: #22329  (Support XA distributed transactions in CockroachDB)
  16: #24062  (sql: 32 bit SERIAL type)
  16: #30352  (roadmap:when CockroachDB  will support cursor?)
  12: #27791  (sql: support RANGE types)
   8: #40195  (pgwire: multiple active result sets (portals) not supported)
   8: #6130   (sql: add support for key watches with notifications of changes)
   5: Expected Failure                                       (unknown)
   5: #23468  (sql: support sql arrays of JSONB)
   5: #40854  (sql: set application_name from connection string)
   4: #35879  (sql: `default_transaction_read_only` should also accept 'on' and 'off')
   4: #32610  (sql: can't insert self reference)
   4: #40205  (sql: add non-trivial implementations of FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, FOR NO KEY SHARE)
   4: #35897  (sql: unknown function: pg_terminate_backend())
   4: #4035   (sql/pgwire: missing support for row count limits in pgwire)
   3: #27796  (sql: support user-defined DOMAIN types)
   3: #3781   (sql: Add Data Type Formatting Functions)
   3: #40476  (sql: support `FOR {UPDATE,SHARE} {SKIP LOCKED,NOWAIT}`)
   3: #35882  (sql: support other character sets)
   2: #10028  (sql: Support view queries with star expansions)
   2: #35807  (sql: INTERVAL output doesn't match PG)
   2: #35902  (sql: large object support)
   2: #40474  (sql: support `SELECT ... FOR UPDATE OF` syntax)
   1: #18846  (sql: Support CIDR column type)
   1: #9682   (sql: implement computed indexes)
   1: #31632  (sql: FK options (deferrable, etc))
   1: #24897  (sql: CREATE OR REPLACE VIEW)
   1: pass?                                                  (unknown)
   1: #36215  (sql: enable setting standard_conforming_strings to off)
   1: #32562  (sql: support SET LOCAL and txn-scoped session variable changes)
   1: #36116  (sql: psychopg: investigate how `'infinity'::timestamp` is presented)
   1: #26732  (sql: support the binary operator: <int> / <float>)
   1: #23299  (sql: support coercing string literals to arrays)
   1: #36115  (sql: psychopg: investigate if datetimetz is being returned instead of datetime)
   1: #26925  (sql: make the CockroachDB integer types more compatible with postgres)
   1: #21085  (sql: WITH RECURSIVE (recursive common table expressions))
   1: #36179  (sql: implicity convert date to timestamp)
   1: #36118  (sql: Cannot parse '24:00' as type time)
   1: #31708  (sql: support current_time)
```

Release justification: non-production change
Release note: None

Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
@imalsogreg
Copy link

We (myself and @robo-corg) hit an edge-case related to this issue. When we use the rust sqlx postgres bindings, queries run inside of transactions trigger the "multiple portals" issue. This happens even when we run just a single query, which we think creates just one portal.

wireshark_sqlx

Here's a wireshark/tcpdump of a session with sqlx that exhibits this behavior. We can attach the .pcap file if it's helpful.

@rafiss
Copy link
Collaborator

rafiss commented Dec 30, 2020

@imalsogreg Thanks for sharing this case! A wireshark .pcap would definitely be very helpful for us. We can use that to more easily write a test within our project.

@imalsogreg
Copy link

@rafiss Cool. Here's the .pcap from when I ran the minimal reproducing case. It corresponds to the left panel in the screenshot above.

packets4.pcap.zip

@bka9
Copy link

bka9 commented Apr 13, 2021

After upgrading from 20.1.12 to 20.2.7 our use of snaplogic to query data has failed with the following stack trace:

com.snaplogic.snap.api.SnapDataException: Failed to execute select query.
	at com.snaplogic.snaps.sql.SimpleSqlSnap.process(SimpleSqlSnap.java:399)
	at com.snaplogic.snap.api.ExecutionUtil.process(ExecutionUtil.java:106)
	at com.snaplogic.snap.api.ExecutionUtil.executeForDocument(ExecutionUtil.java:118)
	at com.snaplogic.snap.api.ExecutionUtil.execute(ExecutionUtil.java:81)
	at com.snaplogic.snap.api.SimpleSnap.execute(SimpleSnap.java:70)
	at com.snaplogic.cc.snap.common.SnapRunnableImpl.executeSnap(SnapRunnableImpl.java:770)
	at com.snaplogic.cc.snap.common.SnapRunnableImpl.execute(SnapRunnableImpl.java:552)
	at com.snaplogic.cc.snap.common.SnapRunnableImpl.doRun(SnapRunnableImpl.java:836)
	at com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:402)
	at com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:116)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: com.snaplogic.api.ExecutionException: Failed to execute select query.
	at com.snaplogic.snap.api.sql.operations.JdbcOperationsImpl.select(JdbcOperationsImpl.java:700)
	at com.snaplogic.snaps.sql.SimpleSqlSelectSnap.selectAndSpoolResults(SimpleSqlSelectSnap.java:714)
	at com.snaplogic.snaps.sql.SimpleSqlSelectSnap.lambda$select$5(SimpleSqlSelectSnap.java:699)
	at net.jodah.failsafe.Functions$12.call(Functions.java:274)
	at net.jodah.failsafe.SyncFailsafe.call(SyncFailsafe.java:145)
	at net.jodah.failsafe.SyncFailsafe.run(SyncFailsafe.java:93)
	at com.snaplogic.snaps.sql.SimpleSqlSelectSnap.select(SimpleSqlSelectSnap.java:696)
	at com.snaplogic.snaps.sql.SimpleSqlSelectSnap.processDocument(SimpleSqlSelectSnap.java:678)
	at com.snaplogic.snaps.sql.SimpleSqlSnap.process(SimpleSqlSnap.java:390)
	... 15 more
	Suppressed: org.jooq.exception.DataAccessException: SQL [null]; ERROR: current transaction is aborted, commands ignored until end of transaction block
		at org.jooq_3.9.1.POSTGRES.debug(Unknown Source)
		at org.jooq.impl.Tools.translate(Tools.java:1983)
		at org.jooq.impl.MetaDataFieldProvider.init(MetaDataFieldProvider.java:158)
		at org.jooq.impl.MetaDataFieldProvider.<init>(MetaDataFieldProvider.java:83)
		at org.jooq.impl.SelectQueryImpl.getFields(SelectQueryImpl.java:407)
		at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:285)
		at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:349)
		at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:368)
		at com.snaplogic.snap.api.sql.operations.JdbcOperationsImpl.fetchLazy(JdbcOperationsImpl.java:841)
		at com.snaplogic.snap.api.sql.operations.JdbcOperationsImpl.select(JdbcOperationsImpl.java:694)
		... 23 more
	Caused by: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block
		at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2468)
		at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2211)
		at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:309)
		at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)
		at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)
		at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:311)
		at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:297)
		at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:274)
		at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:225)
		at org.postgresql.jdbc.PgResultSetMetaData.fetchFieldMetaData(PgResultSetMetaData.java:245)
		at org.postgresql.jdbc.PgResultSetMetaData.isAutoIncrement(PgResultSetMetaData.java:57)
		at org.postgresql.jdbc.PgResultSetMetaData.getColumnTypeName(PgResultSetMetaData.java:318)
		at org.jooq.impl.MetaDataFieldProvider.init(MetaDataFieldProvider.java:129)
		... 30 more
	Caused by: org.postgresql.util.PSQLException: ERROR: unimplemented: multiple active portals not supported
  Hint: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/40195/v20.2
		at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2468)
		at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2211)
		at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:309)
		at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)
		at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)
		at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:311)
		at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:297)
		at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:274)
		at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:225)
		at org.postgresql.jdbc.PgResultSetMetaData.fetchFieldMetaData(PgResultSetMetaData.java:245)
		at org.postgresql.jdbc.PgResultSetMetaData.getBaseTableName(PgResultSetMetaData.java:289)
		at org.postgresql.jdbc.PgResultSetMetaData.getTableName(PgResultSetMetaData.java:285)
		at org.jooq.impl.MetaDataFieldProvider.init(MetaDataFieldProvider.java:112)
		... 30 more
Reason: SQL [null]; ERROR: current transaction is aborted, commands ignored until end of transaction block
Resolution: Please check sql query.

The query is a simple select statement.

@rafiss
Copy link
Collaborator

rafiss commented Apr 13, 2021

I'm coming back to this now. It seems like the error message is incorrectly used if you execute a statement with a row count limit within a transaction. Here's a test case that can be put in pkg/sql/pgwire/testdata/pgtest/ that reproduces.

send
Query {"String": "BEGIN"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"BEGIN"}
{"Type":"ReadyForQuery","TxStatus":"T"}

# 83 = ASCII 'S' for Statement
# 50 = ASCII '2'
# ParameterFormatCodes = [0] for text format
send
Parse {"Name": "s6", "Query": "select $1::int8", "ParameterOIDs": [20]}
Describe {"ObjectType": 83, "Name": "s6"}
Bind {"DestinationPortal": "p6", "PreparedStatement": "s6", "ParameterFormatCodes": [0], "ResultFormatCodes": [0], "Parameters": [[50]]}
Execute {"Portal": "p6", "MaxRows": 1}
Sync
----

until
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"ParameterDescription","ParameterOIDs":[20]}
{"Type":"RowDescription","Fields":[{"Name":"int8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
{"Type":"BindComplete"}
{"Type":"DataRow","Values":[{"text":"2"}]}
{"Type":"PortalSuspended"}
{"Type":"ReadyForQuery","TxStatus":"T"}

send
Query {"String": "COMMIT"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"COMMIT"}
{"Type":"ReadyForQuery","TxStatus":"I"}

It works against Postgres using make test PKG=./pkg/sql/pgwire TESTS=TestPGTest TESTFLAGS="-addr=localhost:5432 -user=rafiss"

But it fails against CockroachDB make test PKG=./pkg/sql/pgwire TESTS=TestPGTest

got &pgproto3.ErrorResponse{Severity:"ERROR", SeverityUnlocalized:"", Code:"0A000", Message:"unimplemented: multiple active portals not supported", Detail:"", Hint:"You have attempted to use a feature that is not yet implemented.\nSee: https://go.crdb.dev/issue-v/40195/v21.1", Position:0, InternalPosition:0, InternalQuery:"", Where:"", SchemaName:"", TableName:"", ColumnName:"", DataTypeName:"", ConstraintName:"", File:"distsql_running.go", Line:775, Routine:"init", UnknownFields:map[uint8]string(nil)}

@rafiss
Copy link
Collaborator

rafiss commented Apr 14, 2021

I see that this limitation is described here: #42912 (comment) -- I'll see if we can address this now

craig bot pushed a commit that referenced this issue Apr 27, 2021
63677: sql/pgwire: implicitly destroy portal on txn finish  r=jordanlewis a=rafiss

fixes #42912
touches #40195 

This also includes a commit to fix an error message hint that seems to be
accidentally using `WithSafeDetails`, which is meant for sentry reporting.
(Originally added in #40197.)

Release note (sql change): Previously, committing a transaction when a
portal was suspended would cause a "multiple active portals not
supported" error. Now, the portal is automatically destroyed.

Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
craig bot pushed a commit that referenced this issue Apr 27, 2021
63677: sql/pgwire: implicitly destroy portal on txn finish  r=jordanlewis a=rafiss

fixes #42912
touches #40195 

This also includes a commit to fix an error message hint that seems to be
accidentally using `WithSafeDetails`, which is meant for sentry reporting.
(Originally added in #40197.)

Release note (sql change): Previously, committing a transaction when a
portal was suspended would cause a "multiple active portals not
supported" error. Now, the portal is automatically destroyed.

64252: opt: disallow fast path for cascading deletes with subqueries r=mgartner a=mgartner

Previously, the optimizer would attempt to build a fast path cascading
delete for `DELETE`s with a subquery. This caused errors when copying
the original filters for the fast path query. The cascade query is built
using a separate memo with metadata that does not include tables in the
original memo's metadata. As a result, a Scan in a cascade fast path
subquery could reference a table ID that did not exist in the metadata.

This commit prevents building fast path cascading deletes if the
delete has any subqueries.

Fixes #64179

Release note (bug fix): Cascading `DELETE`s with subqueries no longer
error. This bug was present since v21.1.0-alpha.1.

64277: logictest: temporarily disable vectorized flow assertion r=yuzefovich a=yuzefovich

Informs: #64248.

Release note: None


Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
@lacasaprivata2
Copy link

lacasaprivata2 commented May 25, 2021

+1

@rafiss
Copy link
Collaborator

rafiss commented Dec 22, 2021

@rathboma Thanks for those instructions. I am getting a different error. (Also I had to switch to node14 since it wouldn't work with node16). To keep this issue more focused, let's move the conversation here: #74187

@mcanalesmayo
Copy link

Are there any plans to fix this? We are running into this issue as well with a very simple scenario where we are reading and updating rows inside a transaction, using Vertx streaming API (batches).

@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 4, 2022
@jordanlewis jordanlewis mentioned this issue Jun 17, 2022
3 tasks
@markddrake
Copy link

I am getting this error attempting to process a table with 107 rows in it using node pg and node pg QueryStream. As far as I am aware I have no other active queries..

brianc/node-postgres#2767

@rafiss
Copy link
Collaborator

rafiss commented Jun 29, 2022

Thanks for linking that issue. It looks like node-pg is using the Flush message. We should be able to handle that in a portal, even without adding full support for multiple active portals.

@markddrake
Copy link

markddrake commented Jun 29, 2022

If you guys are going to fix this, do you want me to open a new issue on cockroach with the tetscase

@rafiss
Copy link
Collaborator

rafiss commented Jun 29, 2022

Yes, filing another issue with that would be helpful, thanks.

@wb14123
Copy link

wb14123 commented Oct 13, 2022

I got this error when read a table with 1000 rows per batch and update them in the same transaction. But if I read the table with 100 rows per time, there is no error. This is kind of a strange behavior and is very confusing.

@lukaseder
Copy link

@bka9 regarding the jOOQ specific issue from your comment here: #40195 (comment)

It's likely you ran into this because of using a plain SQL query without explicitly specifying the projection, given this line in your stack trace:

at org.jooq.impl.MetaDataFieldProvider.init(MetaDataFieldProvider.java:112)

It's always good to provide explicit projections (SELECT clause) rather than running SELECT * queries for other performance reasons. This issue shows that fetching column meta data in a separate query causes additional performance problems. A more detailed description of the jOOQ related problem can be seen here: jOOQ/jOOQ#14392

@GoulartNogueira
Copy link

I'm building a serverless application, where a lot of threads can run in parallel, but through different instances.
Can it be accomplished with current CockroachDB version?
Or is it limited by this portals issue?

@rafiss
Copy link
Collaborator

rafiss commented Apr 10, 2023

I'm building a serverless application, where a lot of threads can run in parallel, but through different instances.
Can it be accomplished with current CockroachDB version?

Based on your description, it sounds like each thread is using a different SQL connection. If that's the case, then yes, this should work in existing CockroachDB versions.


Also an update: in v23.1 CockroachDB will support multiple active portals as a preview feature. The feature will be off by default, and can be enabled by setting the session variable multiple_active_portals_enabled to true. This will be available in v23.1.0-beta.2.

We encourage everyone to try it out for their use cases, with the caveat that there are still known issues and incomplete performance testing. The list of known issues can be found with the A-pausable-portals label, and we always welcome new bug reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-pgwire pgwire protocol issues. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-anchored-telemetry The issue number is anchored by telemetry references.
Projects
None yet
Development

No branches or pull requests