cockroachdb / cockroachdb/cockroach

sql/pgwire: disallow dropping objects with active portals relying on them

Open
#98,176 0 comments 0 reactions 0 assignees View on GitHub
C-bug T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

We send the following pgwire messages to create a table and have an active portal bound to a statement querying it

```
send
Query {"String": "BEGIN"}
Query {"String": "CREATE TABLE mytable (x int)"}
Query {"String": "INSERT INTO mytable VALUES (1),(2),(3)"}
Parse {"Name": "q8", "Query": "SELECT * FROM mytable"}
Bind {"DestinationPortal": "p8", "PreparedStatement": "q8"}
Execute {"Portal": "p8", "MaxRows": 1}
Sync
----
```

And then we attempt to drop the table :

```
send
Query {"String": "DROP TABLE mytable"}
----
```

In PG it would error out with `cannot DROP TABLE \"mytable\" because it is being used by active queries in this session`. We should support the same check for portals when dropping an object.

Jira issue: CRDB-25117

Epic CRDB-25183

Contributor guide

Open the contributing guide

Research direction

Start by tracing the pgwire handling for Parse, Bind, Execute, and DROP TABLE, focusing on how active portals retain dependencies on queried objects. Reproduce the sequence in the issue and compare the result with PostgreSQL's error. Done means dropping an object used by an active portal is rejected with the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.