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: fix COPY internal error in optimizer #87175

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/copyfrom
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,40 @@ SELECT id, data AS got, array[chr(id)] AS want FROM test_copy_array WHERE data !
----

subtest end

# Regression test for #87011
statement ok
CREATE TABLE tab (
col1 STRING,
col2 STRING,
col3 STRING,
col4 STRING,
col5 STRING,
col6 STRING NOT NULL, index(col5) where col3 like '%ride%', index ((col2 || col3)),
PRIMARY KEY (col1, col2, col3, col4, col5) using hash,
UNIQUE (col5, col6)
);
CREATE TABLE tab_child (
col1 STRING,
col2 STRING,
col3 STRING,
col4 STRING,
col5 STRING,
col6 STRING NOT NULL, index(col5) where col3 like '%ride%', index ((col2 || col3)),
PRIMARY KEY (col1, col2, col3, col4, col5) using hash,
FOREIGN KEY (col5, col6) REFERENCES tab (col5, col6)
)

copy-error
COPY tab_child FROM STDIN

'high' 'straight' 'writer' 'develop' 'shells' 'bean'
'basic' 'tent' 'compound' 'it' 'future' 'held'
'bite' 'bring' 'taught' 'world' 'themselves' 'airplane'
'island' 'number' 'has' 'blow' 'prize' 'cookies'
'hole' 'wear' 'way' 'troops' 'eye' 'sure'
'thick' 'joy' 'impossible' 'area' 'ordinary' 'piano'
'grabbed' 'reader' 'number' 'serve' 'fill' 'wonderful'
'tower' 'former' 'mainly' 'point' 'class' 'idea'
----
insert on table "tab_child" violates foreign key constraint "tab_child_col5_col6_fkey"
8 changes: 4 additions & 4 deletions pkg/sql/opt/memo/statistics_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,13 +2134,13 @@ func (sb *statisticsBuilder) colStatLiteralValues(
// Determine null count by looking at tuples that have only NullOps in them.
nullCount := 0

for i := 0; i < values.Len(); i++ {
for rowIndex := 0; rowIndex < values.Len(); rowIndex++ {
var h hasher
h.Init()
hasNonNull := false
for j := 0; j < len(values.Cols); j++ {
if colSet.Contains(values.Cols[i]) {
elem := values.Rows.Rows.Get(i, j).(tree.Datum)
for colIndex, col := range values.Cols {
if colSet.Contains(col) {
elem := values.Rows.Rows.Get(rowIndex, colIndex).(tree.Datum)
if elem.ResolvedType().Family() == types.UnknownFamily {
hasNonNull = true
}
Expand Down