cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.97k stars 3.79k forks source link

cli: DDL breaks subsequent use of the USE statement #68458

Closed hand-crdb closed 1 year ago

hand-crdb commented 3 years ago

Describe the problem

After executing extensive DDL from a file via the \i command in cockroach sql, the USE statement does not work.

I reproduced this on both my laptop (Mac) and GCE.

To Reproduce

  1. Set up laptop 3-node insecure cluster per doc at https://www.cockroachlabs.com/docs/stable/start-a-local-cluster.html

  2. Establish a session with client

$ cockroach sql --insecure

  1. Use the \i directive to read a sql file
root@:26257/defaultdb> \i path/file.sql
  1. Attempt to USE the defaultdb database.
use defaultdb;
SET

Time: 1ms total (execution 0ms / network 0ms)

> root@:26257/defaultdb> show tables;
ERROR: no database or schema specified
SQLSTATE: 42602
  1. Create a new database and attempt to USE it.
root@:26257/defaultdb> create database sth;
CREATE DATABASE

Time: 331ms total (execution 330ms / network 0ms)

root@:26257/defaultdb> use sth;
SET

Time: 83ms total (execution 83ms / network 0ms)

root@:26257/sth> create table test (id uuid default gen_random_uuid() primary key, i int, c character);
ERROR: no database or schema specified
SQLSTATE: 42602

root@:26257/sth> create table sth.test (id uuid default gen_random_uuid() primary key, i int, c character);
CREATE TABLE

Time: 294ms total (execution 294ms / network 0ms)

root@:26257/sth> show tables;
ERROR: no database or schema specified
SQLSTATE: 42602

root@:26257/sth> select * from test;
ERROR: relation "test" does not exist
SQLSTATE: 42P01

root@:26257/sth> select * from sth.test;
  id | i | c
-----+---+----
(0 rows)

Time: 2ms total (execution 2ms / network 0ms)

I can create the above database and create a table within it, but I cannot set it to be my current database via USE. I can reference the table in the database with a qualified name.

A different session connecting to the same database server at this same time CAN successfully set both defaultdb and sth to be the current database, via USE. Just the session on which I did all the DDL seems to be affected.

Expected behavior

The USE statement should let me change the current database.

Additional data / screenshots

The DDL I executed via the .sql file is private. I can provide it offline.

I can also provide client shell logs (both from MacOS and from GCP).

I also captured debug.zip on both MacOS and GCP.

The session parameters are all defaults except for the database:

root@:26257/sth> show session all;
                        variable                       |                                         value
-------------------------------------------------------+----------------------------------------------------------------------------------------
  application_name                                     | $ cockroach sql
  bytea_output                                         | hex
  client_encoding                                      | UTF8
  client_min_messages                                  | warning
  crdb_version                                         | CockroachDB CCL v21.1.6 (x86_64-apple-darwin19, built 2021/07/20 15:33:43, go1.15.11)
  database                                             | sth
  datestyle                                            | ISO, MDY
  default_int_size                                     | 8
  default_tablespace                                   |
  default_transaction_isolation                        | serializable
  default_transaction_priority                         | normal
  default_transaction_read_only                        | off
  default_transaction_use_follower_reads               | off
  disable_partially_distributed_plans                  | off
  disallow_full_table_scans                            | off
  distsql                                              | auto
  enable_drop_enum_value                               | off
  enable_experimental_alter_column_type_general        | off
  enable_experimental_stream_replication               | off
  enable_implicit_select_for_update                    | on
  enable_insert_fast_path                              | on
  enable_seqscan                                       | on
  enable_zigzag_join                                   | on
  escape_string_warning                                | on
  experimental_distsql_planning                        | off
  experimental_enable_hash_sharded_indexes             | off
  experimental_enable_implicit_column_partitioning     | off
  experimental_enable_temp_tables                      | off
  experimental_enable_unique_without_index_constraints | off
  experimental_use_new_schema_changer                  | off
  extra_float_digits                                   | 2
  force_savepoint_restart                              | off
  foreign_key_cascades_limit                           | 10000
  idle_in_session_timeout                              | 0
  idle_in_transaction_session_timeout                  | 0
  integer_datetimes                                    | on
  intervalstyle                                        | postgres
  locality                                             |
  locality_optimized_partitioned_index_scan            | on
  lock_timeout                                         | 0
  max_identifier_length                                | 128
  max_index_keys                                       | 32
  node_id                                              | 1
  optimizer                                            | on
  optimizer_use_histograms                             | on
  optimizer_use_multicol_stats                         | on
  override_multi_region_zone_config                    | off
  prefer_lookup_joins_for_fks                          | off
  reorder_joins_limit                                  | 8
  require_explicit_primary_keys                        | off
  results_buffer_size                                  | 16384
  row_security                                         | off
  search_path                                          |
  serial_normalization                                 | rowid
  server_encoding                                      | UTF8
  server_version                                       | 13.0.0
  server_version_num                                   | 130000
  session_id                                           | 169821bb1a9816100000000000000001
  session_user                                         | root
  sql_safe_updates                                     | on
  standard_conforming_strings                          | on
  statement_timeout                                    | 0
  stub_catalog_tables                                  | on
  synchronize_seqscans                                 | on
  synchronous_commit                                   | on
  testing_vectorize_inject_panics                      | off
  timezone                                             | UTC
  tracing                                              | off
  transaction_isolation                                | serializable
  transaction_priority                                 | normal
  transaction_read_only                                | off
  transaction_status                                   | NoTxn
  vectorize                                            | on
  vectorize_row_count_threshold                        | 0
(74 rows)

Environment:

Additional context What was the impact?

I could not fully use the session after USE stopped working. I had to qualify table references with the database name. This was not a big deal in itself but it may point to a more serious issue. I don't know whether this is a client issue or a server issue.

Jira issue: CRDB-9039

github-actions[bot] commented 1 year ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!