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

rowenc: fix splitting lookup rows into family spans in some cases #76563

Merged
merged 1 commit into from
Feb 15, 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
30 changes: 30 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/select_index
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,33 @@ SELECT k FROM t47976 WHERE
(a > 4 OR b <= 5.23 OR c IN (1, 2, 3)) AND
(a = 12 OR b = 15.23 OR c = 14) AND
(a > 58 OR b < 0 OR c >= 13)

# Regression test for incorrectly splitting a lookup row (with NULL values not
# in the lookup key) into family spans (#76289).
statement ok
CREATE TABLE t76289_1 (
pk1 DECIMAL NOT NULL, pk2 INT8 NOT NULL, c1 INT8, c2 INT8,
PRIMARY KEY (pk1, pk2),
UNIQUE (pk2),
FAMILY fam_c1 (c1), FAMILY fam_c2 (pk1, pk2, c2)
);
INSERT INTO t76289_1 (pk1, pk2, c1) VALUES (1:::DECIMAL, 0:::INT8, 0:::INT8);

query I
SELECT c2 FROM t76289_1 WHERE pk2 = 0;
----
NULL

statement ok
CREATE TABLE t76289_2 (
pk1 DECIMAL NOT NULL, pk2 INT8 NOT NULL, c1 INT8, c2 INT8,
PRIMARY KEY (pk1, pk2),
INDEX (pk2),
FAMILY fam_c1 (c1), FAMILY fam_c2 (pk1, pk2, c2)
);
INSERT INTO t76289_2 (pk1, pk2, c1) VALUES (1:::DECIMAL, 0:::INT8, 0:::INT8);

query I
SELECT c2 FROM t76289_2@t76289_2_pk2_idx WHERE pk2 = 0;
----
NULL
12 changes: 5 additions & 7 deletions pkg/sql/rowenc/index_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,16 @@ func NeededColumnFamilyIDs(
if nc.Contains(columnOrdinal) {
needed = true
}
if !columns[columnOrdinal].IsNullable() && (!indexedCols.Contains(columnOrdinal) ||
compositeCols.Contains(columnOrdinal) && !hasSecondaryEncoding) {
// The column is non-nullable and cannot be decoded from a different
// family, so this column family must have a KV entry for every row.
if !columns[columnOrdinal].IsNullable() && !indexedCols.Contains(columnOrdinal) {
// This column is non-nullable and is not indexed, thus, it must
// be stored in the value part of the KV entry. As a result,
// this column family is non-nullable too.
nullable = false
}
}
if needed {
neededFamilyIDs = append(neededFamilyIDs, family.ID)
if !nullable {
allFamiliesNullable = false
}
allFamiliesNullable = allFamiliesNullable && nullable
}
return nil
})
Expand Down