cockroachdb / cockroachdb/cockroach

cli: copy-pasting multi-stmt snippet seems to be broken

Open
#100,892 1 comment 0 reactions 0 assignees View on GitHub
C-bug O-qa regression
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Running on current master with
```
./cockroach demo movr --global --nodes 9 --multitenant=false --insecure
```
and then copy-pasting this whole snippet to convert the `movr` database into MR (courtesy of @michae2):

```sql
ALTER DATABASE movr PRIMARY REGION "us-east1";
ALTER DATABASE movr ADD REGION "europe-west1";
ALTER DATABASE movr ADD REGION "us-west1";

ALTER TABLE promo_codes SET LOCALITY GLOBAL;

ALTER TABLE rides ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE rides ALTER COLUMN region SET NOT NULL;
ALTER TABLE rides SET LOCALITY REGIONAL BY ROW AS "region";

ALTER TABLE user_promo_codes
ADD CONSTRAINT user_promo_codes_code_fk
FOREIGN KEY (code)
REFERENCES promo_codes (code)
ON UPDATE CASCADE;
ALTER TABLE user_promo_codes ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE user_promo_codes ALTER COLUMN region SET NOT NULL;
ALTER TABLE user_promo_codes SET LOCALITY REGIONAL BY ROW AS "region";

ALTER TABLE users ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE users ALTER COLUMN region SET NOT NULL;
ALTER TABLE users SET LOCALITY REGIONAL BY ROW AS "region";

ALTER TABLE vehicle_location_histories ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE vehicle_location_histories ALTER COLUMN region SET NOT NULL;
ALTER TABLE vehicle_location_histories SET LOCALITY REGIONAL BY ROW AS "region";

ALTER TABLE vehicles ADD COLUMN region crdb_internal_region AS (
CASE WHEN city = 'amsterdam' THEN 'europe-west1'
WHEN city = 'paris' THEN 'europe-west1'
WHEN city = 'rome' THEN 'europe-west1'
WHEN city = 'new york' THEN 'us-east1'
WHEN city = 'boston' THEN 'us-east1'
WHEN city = 'washington dc' THEN 'us-east1'
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THEN 'us-west1'
WHEN city = 'los angeles' THEN 'us-west1'
END
) STORED;
ALTER TABLE vehicles ALTER COLUMN region SET NOT NULL;
ALTER TABLE vehicles SET LOCALITY REGIONAL BY ROW AS "region";

SELECT ' done';
```

seems to break the updated CLI.

First, I see this
```
...
WHEN city = 'san francisco' THEN 'us-west1'
WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'sALTER DATABASE PRIMARY REGION

Time: 1.350s total (execution 1.340s / network 0.010s)
```
and then
```
root@127.0.0.1:26257/movr> NOT NULL;
invalid syntax: statement ignored: at or near "not": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
NOT NULL
^
root@127.0.0.1:26257/movr> ty = 'rome' THEN 'europe-west1'
-> WHEN city = 'new york' THEN 'us-east1'
-> WHEN city = 'boston' THEN 'us-east1'
-> WHEN city = 'washington dc' THEN 'us-east1'
-> WHEN city = 'san francisco' THEN 'us-west1'
-> WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE
-> WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE
-> WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE
-> WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE WHEN city = 'seattle' THE
-> WHEN city = 'seattle' T WHEN city = 'washington dc' THEN 'us-east1'
-> WHEN city = 'san francisco' THEN 'us-west1'
-> WHEN city = 'seattle' THEN 'us-west1'
-> WHEN city = 'los angeles' THEN 'us-west1'
-> END
-> ) STORED;
invalid syntax: statement ignored: at or near "ty": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
ty = 'rome' THEN 'europe-west1'
^
root@127.0.0.1:26257/movr> UMN region SET NOT NULL;
invalid syntax: statement ignored: at or near "umn": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
UMN region SET NOT NULL
^
```
Doing the same on 22.2.6 works. cc @knz

Jira issue: CRDB-26676

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure by running the provided ./cockroach demo movr command and pasting the SQL snippet, then compare it with 22.2.6. Trace the CLI's multi-statement paste handling from that entry point; done means the complete snippet executes without duplicated or corrupted input.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.