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: internal error: no volatility for cast regtype::regclass #74784

Closed
cockroach-teamcity opened this issue Jan 13, 2022 · 11 comments · Fixed by #75112
Closed

sql: internal error: no volatility for cast regtype::regclass #74784

cockroach-teamcity opened this issue Jan 13, 2022 · 11 comments · Fixed by #75112
Assignees
Labels
branch-master Failures and bugs on the master branch. C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. T-sql-queries SQL Queries Team

Comments

@cockroach-teamcity
Copy link
Member

roachtest.sqlsmith/setup=rand-tables/setting=no-mutations failed with artifacts on master @ c3d71ac887844bef174abb6dab2a4e1ce9270ab7:

The test failed on branch=master, cloud=gce:
test artifacts and logs in: /home/agent/work/.go/src/github.com/cockroachdb/cockroach/artifacts/sqlsmith/setup=rand-tables/setting=no-mutations/run_1
	sqlsmith.go:259,sqlsmith.go:298,test_runner.go:780: error: pq: internal error: no volatility for cast regtype::regclass
		stmt:
		SELECT
			tab_33311.col2_4 AS col_75088,
			719253383:::OID AS col_75089,
			tab_33312.col3_5 AS col_75090,
			tab_33312.col3_9 AS col_75091,
			(-916813071153183.8625):::DECIMAL AS col_75092,
			tab_33312.tableoid AS col_75093
		FROM
			defaultdb.public.table2@[0] AS tab_33311,
			defaultdb.public.table3@table3_col3_4_col3_2_col3_7_col3_1_col3_3_col3_9_col3_5_idx AS tab_33312
		WHERE
			EXISTS(
				SELECT
					CASE WHEN false THEN tab_33311.col2_3 ELSE tab_33312.col3_1 END AS col_75087
				FROM
					defaultdb.public.table3@[0] AS tab_33313
				LIMIT
					49:::INT8
			)
		LIMIT
			89:::INT8;
Help

See: roachtest README

See: How To Investigate (internal)

Same failure on other branches

/cc @cockroachdb/sql-queries

This test on roachdash | Improve this report!

@cockroach-teamcity cockroach-teamcity added branch-master Failures and bugs on the master branch. C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. labels Jan 13, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jan 13, 2022
@cockroach-teamcity

This comment has been minimized.

@cockroach-teamcity
Copy link
Member Author

roachtest.sqlsmith/setup=rand-tables/setting=no-mutations failed with artifacts on master @ 78419450178335b31f542bd1b14fefdf4ecee0e8:

The test failed on branch=master, cloud=gce:
test artifacts and logs in: /home/agent/work/.go/src/github.com/cockroachdb/cockroach/artifacts/sqlsmith/setup=rand-tables/setting=no-mutations/run_1
	sqlsmith.go:278,sqlsmith.go:298,test_runner.go:780: ping node 1: dial tcp 35.231.70.30:26257: connect: connection refused
		previous sql:
		SELECT
			'whVHRa*':::STRING AS col_14553
		FROM
			defaultdb.public.table2 AS tab_6055
			JOIN defaultdb.public.table2 AS tab_6056 ON
					(tab_6055.col2_7) = (tab_6056.col2_7)
					AND (tab_6055.col2_5) = (tab_6056.col2_5)
					AND (tab_6055.col2_0) = (tab_6056.col2_0)
					AND (tab_6055.col2_2) = (tab_6056.col2_2)
			JOIN defaultdb.public.table1@[0] AS tab_6057 ON (tab_6055.col2_2) = (tab_6057.col1_4),
			defaultdb.public.table2@table2_col2_2_col2_7_expr_col2_1_col2_5_col2_0_idx AS tab_6058;
Help

See: roachtest README

See: How To Investigate (internal)

Same failure on other branches

This test on roachdash | Improve this report!

@cockroach-teamcity

This comment has been minimized.

@cockroach-teamcity

This comment has been minimized.

@cockroach-teamcity

This comment has been minimized.

@rytaft
Copy link
Collaborator

rytaft commented Jan 18, 2022

Oops I never actually posted this comment, ha. Well here it is:

There are 3 errors above that seem related to #70831, cc @mgartner:

no volatility for cast regtype::regclass
no volatility for cast regnamespace::regproc
no volatility for cast regclass::regtype

Note that I didn't look into the other failures.

@mgartner
Copy link
Collaborator

Simplified reproduction of the first 3:

CREATE TABLE t (rt REGTYPE, rg REGCLASS);

SELECT CASE WHEN false THEN rt ELSE rg END FROM t;

Up until 21.2 we allowed casts between any REG* types. The castMap does not contain entries for casts between all combinations of REG* types, which is consistent with Postgres. REG* types are all in the same family, and we allow each branch to be a different type as long as they are in the same family during type checking. But the lack of a castMap entry causes errors when we try fetch the volatility of the cast when building logical properties.

According to Postgres's type conversion rules for CASE, we should only allow branches to be different types if they can be implicitly cast to the first non-NULL branch. This seems like a much larger project, so I think the best course of action for now is to allow casts between any two REG* types by adding them to castMap. I'll put up a PR with the quick fix and create an issue for a better long term solution.

@mgartner mgartner changed the title roachtest: sqlsmith/setup=rand-tables/setting=no-mutations failed sql: internal error: no volatility for cast regtype::regclass Jan 18, 2022
@mgartner
Copy link
Collaborator

All the other failures are the same except for the connect: connection refused error which I'm assuming is a test flake.

@yuzefovich
Copy link
Member

That failure seems like an infinite recursion:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc025df2360 stack=[0xc025df2000, 0xc045df2000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x4b5dac4, 0xaeb4920})
	/usr/local/go/src/runtime/panic.go:1198 +0x71 fp=0x7f4a10bfdc38 sp=0x7f4a10bfdc08 pc=0x488af1
runtime.newstack()
	/usr/local/go/src/runtime/stack.go:1088 +0x5ac fp=0x7f4a10bfdde8 sp=0x7f4a10bfdc38 pc=0x4a282c
runtime.morestack()
	/usr/local/go/src/runtime/asm_amd64.s:461 +0x8b fp=0x7f4a10bfddf0 sp=0x7f4a10bfdde8 pc=0x4ba42b

goroutine 2501 [running]:
github.com/cockroachdb/cockroach/pkg/sql/opt/memo.(*InnerJoinExpr).Relational(0xc003888460)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/memo/expr.og.go:2217 +0x36 fp=0xc025df2370 sp=0xc025df2368 pc=0x1f2a1b6
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering.projectOrderingToInput({0x834f4b0, 0xc003888460}, 0xc025df2498)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/project.go:67 +0x62 fp=0xc025df2448 sp=0xc025df2370 pc=0x2df5aa2
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering.projectBuildChildReqOrdering({0x834fff0, 0xc0054806e0}, 0xc025df2570, 0x45e05d)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/project.go:55 +0x133 fp=0xc025df2538 sp=0xc025df2448 pc=0x2df5933
github.com/cockroachdb/cockroach/pkg/sql/opt/ordering.BuildChildRequired({0x834fff0, 0xc0054806e0}, 0xc003888460, 0x0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/ordering/ordering.go:40 +0xa2 fp=0xc025df25d8 sp=0xc025df2538 pc=0x2df3f22
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.BuildChildPhysicalProps(0xc001fe81a0, {0x834fff0, 0xc0054806e0}, 0xb2a21c0, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/physical_props.go:87 +0x407 fp=0xc025df2700 sp=0xc025df25d8 pc=0x2e32ba7
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroupMember(0xc001fe81a0, 0xc004f55500, {0x834fff0, 0xc0054806e0}, 0x0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:508 +0xcd fp=0xc025df2770 sp=0xc025df2700 pc=0x2e30b0d
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroup(0xc001fe81a0, {0x834f4b0, 0xc004c5dae0}, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:456 +0x325 fp=0xc025df2808 sp=0xc025df2770 pc=0x2e309c5
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeExpr(0xc001fe81a0, {0x82be038, 0xc004c5dae0}, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:256 +0x11e fp=0xc025df2880 sp=0xc025df2808 pc=0x2e305de
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroupMember(0xc001fe81a0, 0xc004f555e0, {0x834fa50, 0xc0050cf8c0}, 0x0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:511 +0x105 fp=0xc025df28f0 sp=0xc025df2880 pc=0x2e30b45
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroup(0xc001fe81a0, {0x834f4b0, 0xc003888460}, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:456 +0x325 fp=0xc025df2988 sp=0xc025df28f0 pc=0x2e309c5
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeExpr(0xc001fe81a0, {0x82be038, 0xc003888460}, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:256 +0x11e fp=0xc025df2a00 sp=0xc025df2988 pc=0x2e305de
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroupMember(0xc001fe81a0, 0xc004f55500, {0x834fff0, 0xc0054806e0}, 0x0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:511 +0x105 fp=0xc025df2a70 sp=0xc025df2a00 pc=0x2e30b45
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeGroup(0xc001fe81a0, {0x834f4b0, 0xc004c5dae0}, 0xb2a21c0)
	/home/agent/work/.go/src/github.com/cockroachdb/cockroach/pkg/sql/opt/xform/optimizer.go:456 +0x325 fp=0xc025df2b08 sp=0xc025df2a70 pc=0x2e309c5
github.com/cockroachdb/cockroach/pkg/sql/opt/xform.(*Optimizer).optimizeExpr(0xc001fe81a0, {0x82be038, 0xc004c5dae0}, 0xb2a21c0)
	/h
...

@yuzefovich
Copy link
Member

sqlsmith roachtest used to be somewhat flaky, but as of several months ago (#70280) it has been pretty reliable.

@mgartner
Copy link
Collaborator

I've created a separate issue to track the stack overflow: #75147.

craig bot pushed a commit that referenced this issue Jan 19, 2022
74863: import: check readability earlier r=benbardin a=benbardin

Release note (sql change): Import now checks readability earlier for multiple files, to fail sooner if e.g. permissions are invalid.

74914: opt,tree: fix bugs with Next(), Prev(), and histogram calculation for DTimeTZ r=rytaft a=rytaft

**sql/sem/tree: fix Next() and Prev() for DTimeTZ**

Prior to this commit, the `DTimeTZ` functions `Next()` and `Prev()`
could skip over valid values according to the ordering of `DTimeTZ`
values in an index (which matches the ordering defined by the
`TimeTZ` functions `After()` and `Before()`).

This commit fixes these functions so that `Next()` now returns the smallest
valid `DTimeTZ` that is greater than the receiver, and `Prev()` returns
the largest valid `DTimeTZ` that is less than the receiver. This is
an important invariant that the optimizer relies on when building index
constraints.

Fixes #74912

Release note (bug fix): Fixed a bug that could occur when a `TIMETZ`
column was indexed, and a query predicate constrained that column using
a `<` or `>` operator with a `timetz` constant. If the column contained values
with time zones that did not match the time zone of the `timetz` constant,
it was possible that not all matching values could be returned by the
query. Specifically, the results may not have included values within one
microsecond of the predicate's absolute time. This bug was introduced
when the timetz datatype was first added in 20.1. It exists on all
versions of 20.1, 20.2, 21.1, and 21.2 prior to this patch.

**opt: fix bug in histogram calculation for TimeTZ**

This commit fixes a bug in the histogram estimation code for `TimeTZ`
that made the faulty assumption that `TimeTZ` values are ordered by
`TimeOfDay`. This is incorrect since it does not take the `OffsetSecs`
into account. As a result, it was possible to estimate that the size
of a histogram bucket was negative, which caused problems in the
statistics estimation code. This commit fixes the problem by taking
into account both `TimeOfDay` and `OffsetSecs` when estimating the size of
a bucket in a `TimeTZ` histogram.

Fixes #74667

Release note (bug fix): Fixed an internal error, "estimated row count must
be non-zero", that could occur during planning for queries over a table
with a `TimeTZ` column. This error was due to a faulty assumption in the
statistics estimation code about ordering of `TimeTZ` values, which has now
been fixed. The error could occur when `TimeTZ` values used in the query had
a different time zone offset than the `TimeTZ` values stored in the table.

75112: sql: fix casts between REG* types r=mgartner a=mgartner

The newly introduced `castMap` does not contain entries for casts
between all combinations of REG* types, which is consistent with
Postgres, but inconsistent with behavior in versions up to 21.2 where
these casts are allowed.

The `castMap` changes result in more than just backward incompatibility.
We allow branches of CASE statements to be equivalent types (i.e., types
in the same family), like `REGCLASS` and `REGTYPE`, and we automatically
add casts to a query plan to support this. However, because these casts
don't exist in the `castMap`, internal errors are raised when we try to
fetch the volatility of the cast while building logical properties.

According to Postgres's type conversion rules for CASE, we should only
allow branches to be different types if they can be implicitly cast to
the first non-NULL branch. Implicit casts between REG* types are not
allowed, so CASE expressions with branches of different REG* types
should result in a user error like `CASE/WHEN could not convert type
regclass to regtype`. However, this is a much larger project and the
change will not be fully backward compatible. This work is tracked by
issue #75103.

For now, this commit adds casts between REG* types to the `castMap` to
maintain backward compatibility and prevent an internal error.

There is no release note because this bug does not exist in any
releases.

Fixes #74784

Release note: None

75119: sql: deflake TestPerfLogging r=rytaft a=rytaft

This commit deflakes `TestPerfLogging` by ensuring that test cases
that should not produce log entries do not match with unrelated log
entries and thus cause the test to fail. This is ensured by making
the regex more precise for the specific test case.

Fixes #74811

Release note: None

75146: backupccl: "skip" TestChangefeedRestartDuringBackfill.. r=irfansharif a=irfansharif

under span configs. This test flakes pretty reliably after span configs
were enabled (#73876). Investigating this further is being tracked in
\#75080; lets have this test use the old subsystem for now (only down in
KV; we've narrowed down the failure to having something to do with
concurrent range splits, within the tenant keyspace, while a changefeed
is declared).

Release note: None

Co-authored-by: Ben Bardin <bardin@cockroachlabs.com>
Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
Co-authored-by: irfan sharif <irfanmahmoudsharif@gmail.com>
@craig craig bot closed this as completed in d09d141 Jan 19, 2022
gtr pushed a commit to gtr/cockroach that referenced this issue Jan 24, 2022
The newly introduced `castMap` does not contain entries for casts
between all combinations of REG* types, which is consistent with
Postgres, but inconsistent with behavior in versions up to 21.2 where
these casts are allowed.

The `castMap` changes result in more than just backward incompatibility.
We allow branches of CASE statements to be equivalent types (i.e., types
in the same family), like `REGCLASS` and `REGTYPE`, and we automatically
add casts to a query plan to support this. However, because these casts
don't exist in the `castMap`, internal errors are raised when we try to
fetch the volatility of the cast while building logical properties.

According to Postgres's type conversion rules for CASE, we should only
allow branches to be different types if they can be implicitly cast to
the first non-NULL branch. Implicit casts between REG* types are not
allowed, so CASE expressions with branches of different REG* types
should result in a user error like `CASE/WHEN could not convert type
regclass to regtype`. However, this is a much larger project and the
change will not be fully backward compatible. This work is tracked by
issue cockroachdb#75103.

For now, this commit adds casts between REG* types to the `castMap` to
maintain backward compatibility and prevent an internal error.

There is no release note because this bug does not exist in any
releases.

Fixes cockroachdb#74784

Release note: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-master Failures and bugs on the master branch. C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants