From 16e5d55f64cf9e8c9a32f1335231870f76695eb4 Mon Sep 17 00:00:00 2001 From: Faizan Qazi Date: Mon, 8 Aug 2022 09:38:41 -0400 Subject: [PATCH] sql/randgen: avoid invalid inverted indexes in CREATE TABLE Previously, the create table made via the randgen component could create invalid CREATE TABLE statements where the last columns of an inverted index were descending. This could lead to unexpected failures in certain workloads, which expected valid statements from this components. To address this, this patch stops randgen from generating CREATE table statements with invalid inverted indexes. Release note: None --- pkg/sql/randgen/schema.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/sql/randgen/schema.go b/pkg/sql/randgen/schema.go index 2d6d2f6de08d..378f744e6b09 100644 --- a/pkg/sql/randgen/schema.go +++ b/pkg/sql/randgen/schema.go @@ -544,6 +544,11 @@ func randIndexTableDefFromCols( } } + // Last column for inverted indexes must always be ascending. + if i == nCols-1 && def.Inverted { + elem.Direction = tree.Ascending + } + if !stopPrefix { prefix = append(prefix, cols[i].Name) }