From bbac108247a2f723c8ae2bd4c740e4f6bc2fabf5 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Mon, 2 Mar 2020 23:16:33 -0500 Subject: [PATCH] sql: allow inverted indexes on mixed-case cols Previously, a bug prevented creation of inverted indexes on columns with mixed-case identifiers. Now, the bug is fixed. Release note (bug fix): it is now possible to create inverted indexes on columns whose names are mixed-case. --- pkg/sql/backfill.go | 2 +- .../testdata/logic_test/inverted_index | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/sql/backfill.go b/pkg/sql/backfill.go index ff7057b71621..cd76145e2b51 100644 --- a/pkg/sql/backfill.go +++ b/pkg/sql/backfill.go @@ -1243,7 +1243,7 @@ func (sc *SchemaChanger) validateInvertedIndexes( row, err := ie.QueryRowEx(ctx, "verify-inverted-idx-count", txn, sqlbase.InternalExecutorSessionDataOverride{}, fmt.Sprintf( - `SELECT coalesce(sum_int(crdb_internal.json_num_index_entries(%s)), 0) FROM [%d AS t]`, + `SELECT coalesce(sum_int(crdb_internal.json_num_index_entries(%q)), 0) FROM [%d AS t]`, col, tableDesc.ID, ), ) diff --git a/pkg/sql/logictest/testdata/logic_test/inverted_index b/pkg/sql/logictest/testdata/logic_test/inverted_index index 7fc265c272f0..704ea00cd022 100644 --- a/pkg/sql/logictest/testdata/logic_test/inverted_index +++ b/pkg/sql/logictest/testdata/logic_test/inverted_index @@ -26,10 +26,11 @@ statement ok CREATE TABLE c ( id INT PRIMARY KEY, foo JSON, - bar JSON, + "bAr" JSON, + "qUuX" JSON, INVERTED INDEX (foo), - INVERTED INDEX (bar), - FAMILY "primary" (id, foo, bar) + INVERTED INDEX ("bAr"), + FAMILY "primary" (id, foo, "bAr", "qUuX") ) query TT @@ -38,13 +39,19 @@ SHOW CREATE TABLE c c CREATE TABLE c ( id INT8 NOT NULL, foo JSONB NULL, - bar JSONB NULL, + "bAr" JSONB NULL, + "qUuX" JSONB NULL, CONSTRAINT "primary" PRIMARY KEY (id ASC), INVERTED INDEX c_foo_idx (foo), - INVERTED INDEX c_bar_idx (bar), - FAMILY "primary" (id, foo, bar) + INVERTED INDEX "c_bAr_idx" ("bAr"), + FAMILY "primary" (id, foo, "bAr", "qUuX") ) +# Regression test for #42944: make sure that mixed-case columns can be +# inverted indexed. +statement ok +CREATE INVERTED INDEX ON c("qUuX") + statement error indexing more than one column with an inverted index is not supported CREATE TABLE d ( id INT PRIMARY KEY,