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: non-nullable column with null value #70628

Closed
yuzefovich opened this issue Sep 23, 2021 · 13 comments · Fixed by #74180
Closed

sql: non-nullable column with null value #70628

yuzefovich opened this issue Sep 23, 2021 · 13 comments · Fixed by #74180
Assignees
Labels
branch-master Failures and bugs on the master branch. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team

Comments

@yuzefovich
Copy link
Member

yuzefovich commented Sep 23, 2021

CREATE TABLE table4 (
	col4_0
		INTERVAL,
	col4_5
		DECIMAL,
	col4_6
		JSONB NOT NULL,
	col4_7
		REGPROC,
	col4_9
		"char",
	col4_12
		STRING AS (lower(CAST(col4_0 AS STRING))) STORED,
	col4_13
		STRING AS (lower(col4_9)) VIRTUAL,
	UNIQUE (
		col4_12 DESC,
		col4_5,
		col4_9 ASC,
		col4_13 ASC
	)
		STORING(col4_0),
	FAMILY (col4_9, col4_5),
	FAMILY (col4_7),
	FAMILY (col4_6)
);

INSERT
INTO
	table4
		(
			col4_5,
			col4_9,
			col4_0,
			col4_6
		)
VALUES
	(
		0,
		'',
		'-49 years -9 mons -45 days -09:22:21.302525',
		e'[0.4320261707216839, {"+,+ic&L%<ue": [], "l&\\"8": [], "sy%bmo": {"*!rBt@Sat,": false}}, [[]]]'
	);

UPDATE table4 AS tab_653 SET col4_9 = tab_653.col4_12 WHERE true;

DELETE FROM table4 WHERE true;

UPDATE table4 SET col4_5 = 1 WHERE true;

SELECT tab_2236.col4_6 FROM table4 AS tab_2236;

results in

ERROR: internal error: unexpected error from the vectorized engine: null_value_error: non-nullable column "table4:col4_6" with no value! Index scanned was "primary" with the index key columns (rowid) and the values (?)
(1) attached stack trace
  -- stack trace:
  | github.com/cockroachdb/cockroach/pkg/sql/colfetcher.(*cFetcher).fillNulls
  | 	/Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/colfetcher/cfetcher.go:1495
  | github.com/cockroachdb/cockroach/pkg/sql/colfetcher.(*cFetcher).NextBatch
  | 	/Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/colfetcher/cfetcher.go:1107
  | github.com/cockroachdb/cockroach/pkg/sql/colfetcher.(*ColBatchScan).Next
  | 	/Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/colfetcher/colbatch_scan.go:109
  | github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecutils.(*CancelChecker).Next
  | 	/Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecutils/cancel_checker.go:59
  | github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecbase.(*simpleProjectOp).Next
  | 	/Users/yuzefovich/go/src/github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecbase/simple_project.go:125
...
@yuzefovich yuzefovich added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Sep 23, 2021
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Sep 23, 2021
@jordanlewis
Copy link
Member

Note this issue as well, which may or may not be related: #69867

@yuzefovich
Copy link
Member Author

I'm guessing it is not related because the repro here doesn't use CTAS (unless the queries used here use the same infrastructure as CTAS).

@yuzefovich
Copy link
Member Author

yuzefovich commented Sep 24, 2021

I've simplified the reproduction a bit, and it looks like it relies on several things: multiple column families, virtual/stored columns, char"char" type, so I'm wondering whether it is related to #69673.

@rafiss
Copy link
Collaborator

rafiss commented Sep 24, 2021

Just to clarify, does your repro rely on char or "char" (or either)? Annoyingly, they are different. see #69665 (comment)

@yuzefovich
Copy link
Member Author

yuzefovich commented Sep 24, 2021

I didn't investigate that, but in the schema above it is "char". Thanks for the callout though!

@yuzefovich
Copy link
Member Author

Adding a GA blocker label since it is a regression from 21.1.9.

@blathers-crl

This comment has been minimized.

@yuzefovich yuzefovich added branch-master Failures and bugs on the master branch. branch-release-21.2 labels Sep 28, 2021
@yuzefovich
Copy link
Member Author

cc @rytaft I think we should treat this as a GA-blocker for now.
cc @mgartner this could be related to #70811.

@mgartner
Copy link
Collaborator

mgartner commented Sep 28, 2021

There's a good chance it is related to #69327, which is basically the same as the issue you've linked (there's a handful of issues for the same underlying problem with assignment casts). If it is, #70722 should fix the issue. I'll assign(ment cast) myself to the issue for now.

@mgartner mgartner self-assigned this Sep 28, 2021
@yuzefovich
Copy link
Member Author

IIRC I did try running this on top of #70722 last week, and the problem was still present.

@mgartner
Copy link
Collaborator

Ahhh. That might be because #70722 only fixes assignment casts for INSERTs, not UPDATEs or UPSERTs. The repro above has some UPDATEs that could trigger the bug. I hope to have UPDATEs and UPSERTs fixed soon in another PR.

@mgartner
Copy link
Collaborator

mgartner commented Oct 4, 2021

This is reproducible in 21.1.7 by switching the "char" column to a CHAR column and inserting blank-character strings like ' ':

CREATE TABLE table4 (
	col4_0 STRING,
	col4_5 DECIMAL,
	col4_6 JSONB NOT NULL,
	col4_7 REGPROC,
	col4_9 CHAR,
	col4_12 STRING AS (lower(CAST(col4_0 AS STRING))) STORED,
	col4_13 STRING AS (lower(col4_9)) VIRTUAL,
	UNIQUE (
		col4_12 DESC,
		col4_5,
		col4_9 ASC,
		col4_13 ASC
	) STORING(col4_0),
	FAMILY (col4_9, col4_5),
	FAMILY (col4_7),
	FAMILY (col4_6)
);

INSERT
INTO
	table4
		(
			col4_5,
			col4_9,
			col4_0,
			col4_6
		)
VALUES
	(
		0,
		' ',
		' ',
		e'[0.4320261707216839, {"+,+ic&L%<ue": [], "l&\\"8": [], "sy%bmo": {"*!rBt@Sat,": false}}, [[]]]'
	);

UPDATE table4 AS tab_653 SET col4_9 = tab_653.col4_12 WHERE true;

DELETE FROM table4 WHERE true;

UPDATE table4 SET col4_5 = 1 WHERE true;

SELECT tab_2236.col4_6 FROM table4 AS tab_2236;

@rytaft rytaft removed the GA-blocker label Oct 4, 2021
@rytaft
Copy link
Collaborator

rytaft commented Oct 4, 2021

We've determined this is not a GA blocker

mgartner added a commit to mgartner/cockroach that referenced this issue Dec 22, 2021
mgartner added a commit to mgartner/cockroach that referenced this issue Dec 23, 2021
craig bot pushed a commit that referenced this issue Dec 31, 2021
74180: sql: add assignment cast for UPDATEs r=mgartner a=mgartner

#### opt: fix FK WithScan column type

Previously, the WithScan columns of cascade FK updates were given the
type of the child table's target column. This was incorrect when the
parent column type did not match. This commit fixes the issue by given
the WithScan columns the type of the buffered columns used to update the
parent relation.

This did not cause any known bugs, but it is required to implement
assignment casts with FK cascades.

Release note: None

#### sql: add assignment cast for UPDATEs

Fixes #70628

Release note: None

#### opt: give synthesized assignment cast columns descriptive names

Columns synthesized for assignment casts now have more descriptive
metadata names in the form `<target_column_name>_cast`. This is purely
an aesthetic change and has no effect on semantics.

Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
@craig craig bot closed this as completed in df7a7e8 Dec 31, 2021
gustasva pushed a commit to gustasva/cockroach that referenced this issue Jan 4, 2022
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
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-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants