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

sql: CREATE AS [SHOW <show_subcmd> <table>] job fails #106260

Closed
ecwall opened this issue Jul 6, 2023 · 0 comments · Fixed by #107099
Closed

sql: CREATE AS [SHOW <show_subcmd> <table>] job fails #106260

ecwall opened this issue Jul 6, 2023 · 0 comments · Fixed by #107099
Assignees
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. db-cy-23 T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@ecwall
Copy link
Contributor

ecwall commented Jul 6, 2023

Setup

CREATE TABLE tbl (id int PRIMARY KEY);

Statements causing failing jobs

  1. CREATE TABLE t AS SELECT * FROM [SHOW CREATE TABLE tbl];
  2. CREATE TABLE t AS SELECT * FROM [SHOW INDEXES FROM tbl];
  3. CREATE TABLE t AS SELECT * FROM [SHOW COLUMNS FROM tbl];
  4. CREATE TABLE t AS SELECT * FROM [SHOW CONSTRAINTS FROM tbl];
  5. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM TABLE tbl];
  6. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM INDEX tbl@tbl_pkey];

Job Failure Error
Error message is slightly different for CREATE MATERIALIZED VIEW and for each statement, but all jobs fail with

relation "tbl" does not exist

Example for CREATE TABLE t AS SELECT * FROM [SHOW CREATE TABLE tbl];:

SELECT job_id, status, error, description 
FROM [SHOW JOBS] 
WHERE job_type IN ('SCHEMA CHANGE', 'NEW SCHEMA CHANGE')
AND status != 'succeeded';

880070398090477569, failed, relation "tbl" does not exist, CREATE TABLE defaultdb.public.t (table_name STRING, create_statement STRING) AS SELECT * FROM [SHOW CREATE tbl]

Jira issue: CRDB-29468

Epic CRDB-27601

@ecwall ecwall added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-schema-changes T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Jul 6, 2023
@ecwall ecwall self-assigned this Jul 6, 2023
@ecwall ecwall changed the title sql: CREATE AS [SHOW CREATE] ... job fails sql: CREATE AS [SHOW CREATE TABLE] ... job fails Jul 6, 2023
@ecwall ecwall changed the title sql: CREATE AS [SHOW CREATE TABLE] ... job fails sql: CREATE AS [SHOW CREATE TABLE] job fails Jul 6, 2023
@ecwall ecwall removed their assignment Jul 6, 2023
@ecwall ecwall changed the title sql: CREATE AS [SHOW CREATE TABLE] job fails sql: CREATE AS [SHOW <show_sub_cmd> <table>] job fails Jul 18, 2023
@ecwall ecwall changed the title sql: CREATE AS [SHOW <show_sub_cmd> <table>] job fails sql: CREATE AS [SHOW <show_subcmd> <table>] job fails Jul 18, 2023
craig bot pushed a commit that referenced this issue Jul 19, 2023
106860: ssmemstorage: improve lock contention on RecordStatement r=j82w a=j82w

1. The stats object lock was being held even during the insights event
creation and insert which has it's own lock. The insights logic is now
moved above the stats lock.
2. Moved latency calculation outside the stats lock.
3. Moved error code calculation outside the stats lock.
4. ss_mem_storage converted to use a RWMutex. Each object in the map
has it's own lock. Read lock allows mulitple threads to read from the
map at the same time which is the common case. Writes are only done the
first time a statement is seen.

Fixes: #106789, Fixes: #55285

```
./dev bench pkg/sql/sqlstats/sslocal -f BenchmarkRecordStatement  --ignore-cache --verbose  --test-args='-test.mutexprofile=mutex_pr.out -test.cpuprofile=cpu_pr.out -test.benchtime=30s' --timeout "10m"
```

```
// Master no changes
BenchmarkRecordStatement/RecordStatement:_Parallelism_10-10         	64775088	       558.8 ns/op
    sql_stats_test.go:655: -- test log scope end --
PASS
================================================================================
INFO: Elapsed time: 37.529s, Critical Path: 37.26s
INFO: 2 processes: 1 internal, 1 darwin-sandbox.
INFO: Build completed successfully, 2 total actions
//pkg/sql/sqlstats/sslocal:sslocal_test                                  PASSED in 37.2s
```
```
// Changes after the PR
BenchmarkRecordStatement/RecordStatement:_Parallelism_10-10         	67960656	       523.8 ns/op
    sql_stats_test.go:655: -- test log scope end --
PASS
================================================================================
INFO: Elapsed time: 37.031s, Critical Path: 36.69s
INFO: 2 processes: 1 internal, 1 darwin-sandbox.
INFO: Build completed successfully, 2 total actions
//pkg/sql/sqlstats/sslocal:sslocal_test                                  PASSED in 36.7s
```

Release note (performance improvement): Reduced lock contention on `ssmemstorage.RecordStatement`. This is useful for workloads that execute the same statement concurrently on the same SQL instance.

106912: telemetryccl: Split `TestTelemetry` into smaller sub-tests r=Santamaura a=Santamaura

This change breaks up `TestTelemetry` and the `multiregion` test into four tests due to the test being quite large. The tests are: `multiregion`, `multiregion_db`, `multiregion_table`, and `multiregion_row`.

Informs: #103004

Release note: None

107099: sql: fix `CREATE TABLE AS` sourcing `SHOW <show_subcmd> <table>` job failures r=chengxiong-ruan a=ecwall

Fixes #106260

Previously `CREATE TABLE AS`/`CREATE MATERIALIZED VIEW AS` sourcing from `SHOW <show_subcmd> <table>` generated a failing schema change job with a `relation "tbl" does not exist error` because the SHOW source table was not fully qualified.

This PR fixes this by respecting the `Builder.qualifyDataSourceNamesInAST` flag in `delegate.TryDelegate()` which implements the failing SHOW commands.

Release note (bug fix): Fix failing schema change job when CREATE TABLE AS or CREATE MATERAILIZED VIEW AS sources from a SHOW command:
1. CREATE TABLE t AS SELECT * FROM [SHOW CREATE TABLE tbl];
2. CREATE TABLE t AS SELECT * FROM [SHOW INDEXES FROM tbl];
3. CREATE TABLE t AS SELECT * FROM [SHOW COLUMNS FROM tbl];
4. CREATE TABLE t AS SELECT * FROM [SHOW CONSTRAINTS FROM tbl];
5. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM TABLE tbl];
6. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM INDEX tbl@tbl_pkey];

107170: ui: fix creation index syntax on console r=maryliag a=maryliag

With an update to make the table name fully qualified, the index name was also using the fully qualified name, which contains ".", and that causes an invalid syntax since index name can't have periods.
Having the qualified name is not important for the index name itself, so this commit fixes by ignoring that part and using just the table name, how it was doing previously. It also fixes an invalid syntax when there were spaces on the name generate.

It also add a little more observability into indexes being created with STORING clause, adding that to the suffix of the index creation.

Fixes #107168

Before
<img width="583" alt="Screenshot 2023-07-19 at 10 23 21 AM" src="https://github.com/cockroachdb/cockroach/assets/1017486/e5792419-31af-4e5f-994e-13ddb716009c">


After
https://www.loom.com/share/33da8b46fc9e4f72944c1d0ab943dea0

Release note (bug fix): Index recommendation on the UI no longer uses the full qualified name of a table to create an index name, allowing the creating of indexes directly from the Console to work.

107189: tests: fix stories files r=maryliag a=maryliag

Stories files used for testing were missing some fixtures. This commit adds all missing parameters.

Epic: none

Release note: None

107197: schemachanger: skip flakey test r=rafiss a=DrewKimball

Skips `TestConcurrentDeclarativeSchemaChanges`.

Informs #106732

Release note: None

107207: bazel: make `fastbuild` the default `-c` again; never strip for `dev` builds r=rail a=rickystewart

This is a partial revert of `60e8bcec61269c6648dc40c8094fbf303b8a02aa`.

In that commit I made a change to make un-stripped binaries the default by making `dbg` the default `--compilation_mode`. This had unexpected consequences as this actually disables inlining and optimization, thereby breaking some tests, and overall it is surprising that a Go binary built by Bazel would be un-optimized by default since this is the opposite of `go build`'s default behavior.

Instead, we make `fastbuild` the default (again), and to solve the problem of binaries being unstripped we set `--strip never` for `dev` builds. (`dev doctor` makes you clarify that your build is a `dev` build on setup so no one can miss this.)

Now we have the following behavior for each `compilation_mode`:

* `dbg`: disable optimizations and inlining.
* `fastbuild` and `opt`: will produce the same binary, except `fastbuild` defaults to stripping in non-`dev` configurations.

If you want an un-optimized binary for some reason, it still works to build with `-c dbg`.

Epic: CRDB-17171
Release note: None

Co-authored-by: j82w <[email protected]>
Co-authored-by: Alex Santamaura <[email protected]>
Co-authored-by: Evan Wall <[email protected]>
Co-authored-by: maryliag <[email protected]>
Co-authored-by: Drew Kimball <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
@craig craig bot closed this as completed in 8e4578b Jul 19, 2023
blathers-crl bot pushed a commit that referenced this issue Jul 19, 2023
…failures

Fixes #106260

Previously `CREATE TABLE AS`/`CREATE MATERIALIZED VIEW AS` sourcing from
`SHOW <show_subcmd> <table>` generated a failing schema change job with a
`relation "tbl" does not exist error` because the SHOW source table was not
fully qualified.

This PR fixes this by respecting the `Builder.qualifyDataSourceNamesInAST` flag
in `delegate.TryDelegate()` which implements the failing SHOW commands.

Release note (bug fix): Fix failing schema change job when CREATE TABLE AS or
CREATE MATERAILIZED VIEW AS sources from a SHOW command:
1. CREATE TABLE t AS SELECT * FROM [SHOW CREATE TABLE tbl];
2. CREATE TABLE t AS SELECT * FROM [SHOW INDEXES FROM tbl];
3. CREATE TABLE t AS SELECT * FROM [SHOW COLUMNS FROM tbl];
4. CREATE TABLE t AS SELECT * FROM [SHOW CONSTRAINTS FROM tbl];
5. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM TABLE tbl];
6. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM INDEX tbl@tbl_pkey];
blathers-crl bot pushed a commit that referenced this issue Jul 19, 2023
…failures

Fixes #106260

Previously `CREATE TABLE AS`/`CREATE MATERIALIZED VIEW AS` sourcing from
`SHOW <show_subcmd> <table>` generated a failing schema change job with a
`relation "tbl" does not exist error` because the SHOW source table was not
fully qualified.

This PR fixes this by respecting the `Builder.qualifyDataSourceNamesInAST` flag
in `delegate.TryDelegate()` which implements the failing SHOW commands.

Release note (bug fix): Fix failing schema change job when CREATE TABLE AS or
CREATE MATERAILIZED VIEW AS sources from a SHOW command:
1. CREATE TABLE t AS SELECT * FROM [SHOW CREATE TABLE tbl];
2. CREATE TABLE t AS SELECT * FROM [SHOW INDEXES FROM tbl];
3. CREATE TABLE t AS SELECT * FROM [SHOW COLUMNS FROM tbl];
4. CREATE TABLE t AS SELECT * FROM [SHOW CONSTRAINTS FROM tbl];
5. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM TABLE tbl];
6. CREATE TABLE t AS SELECT * FROM [SHOW PARTITIONS FROM INDEX tbl@tbl_pkey];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. db-cy-23 T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant