From 65f70b726904aefbb871f98e30124180b1401bd9 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Thu, 23 Dec 2021 19:52:41 -0800 Subject: [PATCH 1/5] colfetcher: minor optimization when decoding the value part Release note: None --- pkg/sql/colfetcher/cfetcher.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/sql/colfetcher/cfetcher.go b/pkg/sql/colfetcher/cfetcher.go index 6614e588a889..34aed32c43c3 100644 --- a/pkg/sql/colfetcher/cfetcher.go +++ b/pkg/sql/colfetcher/cfetcher.go @@ -1278,6 +1278,9 @@ func (rf *cFetcher) processValueBytes( nextID := table.orderedColIdxMap.vals[lastColIDIndex] if nextID == colID { vecIdx = table.orderedColIdxMap.ords[lastColIDIndex] + // Since the next value part (if it exists) will belong to the + // column after the current one, we can advance the index. + lastColIDIndex++ break } else if nextID > colID { break From a519265872c58fcfc2cc815c9dc58660534f9cd1 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Thu, 23 Dec 2021 19:50:57 -0800 Subject: [PATCH 2/5] colfetcher: fix recent bug of using wrong column with tracing in some cases A couple of months ago when we taught the cFetcher to operate only on needed columns, we refactored the meaning of `ColIdxMap` - now it returns for the given ColumnID the ordinal of the column among all needed columns whereas previously it would return the ordinal among all columns in the table. In tracing we were relying on the old behavior to append the column name to the key part, and we mistakenly used the "needed" ordinal when accesing the "whole table" columns. This is now fixed. I noticed it while working on the next commit. Release note: None --- pkg/sql/colfetcher/cfetcher.go | 4 ++-- pkg/sql/colfetcher/cfetcher_setup.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/sql/colfetcher/cfetcher.go b/pkg/sql/colfetcher/cfetcher.go index 34aed32c43c3..1858514bc61b 100644 --- a/pkg/sql/colfetcher/cfetcher.go +++ b/pkg/sql/colfetcher/cfetcher.go @@ -1203,7 +1203,7 @@ func (rf *cFetcher) processValueSingle( if idx, ok := table.ColIdxMap.Get(colID); ok { if rf.traceKV { - prettyKey = fmt.Sprintf("%s/%s", prettyKey, table.desc.DeletableColumns()[idx].GetName()) + prettyKey = fmt.Sprintf("%s/%s", prettyKey, table.cols[idx].GetName()) } val := rf.machine.nextKV.Value if len(val.RawBytes) == 0 { @@ -1300,7 +1300,7 @@ func (rf *cFetcher) processValueBytes( } if rf.traceKV { - prettyKey = fmt.Sprintf("%s/%s", prettyKey, table.desc.DeletableColumns()[vecIdx].GetName()) + prettyKey = fmt.Sprintf("%s/%s", prettyKey, table.cols[vecIdx].GetName()) } valueBytes, err = colencoding.DecodeTableValueToCol( diff --git a/pkg/sql/colfetcher/cfetcher_setup.go b/pkg/sql/colfetcher/cfetcher_setup.go index b5b23fbeb352..7140319c50d5 100644 --- a/pkg/sql/colfetcher/cfetcher_setup.go +++ b/pkg/sql/colfetcher/cfetcher_setup.go @@ -29,8 +29,8 @@ import ( type cFetcherTableArgs struct { desc catalog.TableDescriptor index catalog.Index - // ColIdxMap is a mapping from ColumnID of each column to its ordinal. Only - // needed columns are present. + // ColIdxMap is a mapping from ColumnID to the ordinal of the corresponding + // column within the cols field. Only needed columns are present. ColIdxMap catalog.TableColMap isSecondaryIndex bool // cols are all needed columns of the table that are present in the index. From 7c72806876ce573bff1e3b90902ef40182bf9ada Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 22 Dec 2021 22:09:54 -0800 Subject: [PATCH 3/5] colfetcher,row: decode only needed columns when tracing is enabled In a recent change we made it so that the cFetcher would treat all columns present in the index as "needed" when the KV tracing is enabled. This led to some bugs (like reading of a virtual column that doesn't exist in the index) but is also not very meaningful since the goal of the tracing is to show what the cFetcher is doing without tracing. This commit starts treating the KV tracing as the request to log all needed operations without doing anything extra (like decoding unnecessary columns). A similar change is applied to the `row.Fetcher` as well. Release note (sql change): The KV tracing of SQL queries (that could be obtained with `\set auto_trace=on,kv`) has been adjusted slightly. Previously, we would fully decode the key part of each key-value pair even if some part of the key would not be decoded when tracing is enabled. Now, we won't perform any extra decoding, and parts of the key that aren't decoded are replaced with `?`. --- .../logic_test/regional_by_row_query_behavior | 46 ++++++------- pkg/sql/colfetcher/cfetcher.go | 66 +++++++++---------- pkg/sql/colfetcher/cfetcher_setup.go | 9 +-- pkg/sql/opt/exec/execbuilder/testdata/ddl | 2 +- pkg/sql/opt/exec/execbuilder/testdata/orderby | 16 ++--- ...ndary_index_column_families_nonmetamorphic | 4 +- pkg/sql/opt/exec/execbuilder/testdata/select | 6 +- .../exec/execbuilder/testdata/select_index | 14 ++-- .../testdata/select_index_vectorize_off | 40 +++++------ .../testdata/update_nonmetamorphic | 2 +- .../exec/execbuilder/testdata/virtual_columns | 15 +++++ pkg/sql/opt/exec/execbuilder/testdata/window | 22 +++---- pkg/sql/row/fetcher.go | 14 ++-- 13 files changed, 131 insertions(+), 125 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior index 5e4afc0d4023..593dfda9e84a 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior +++ b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior @@ -383,7 +383,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/60/1/"\xc0"/1/0 Scan /Table/60/1/"@"/1/0 Scan /Table/60/1/"\x80"/1/0 -fetched: /regional_by_row_table/regional_by_row_table_pkey/'ap-southeast-2'/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' +fetched: /regional_by_row_table/regional_by_row_table_pkey/?/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' output row: [1 1 2 3 '{"a": "b"}'] statement ok @@ -449,7 +449,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/60/1/"@"/1/0 -fetched: /regional_by_row_table/regional_by_row_table_pkey/'ap-southeast-2'/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' +fetched: /regional_by_row_table/regional_by_row_table_pkey/?/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' output row: [1 1 2 3 '{"a": "b"}'] statement ok @@ -469,7 +469,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- Scan /Table/60/1/"@"/10/0 Scan /Table/60/1/"\x80"/10/0 -fetched: /regional_by_row_table/regional_by_row_table_pkey/'ca-central-1'/10/pk2/a/b -> /10/11/12 +fetched: /regional_by_row_table/regional_by_row_table_pkey/?/10/pk2/a/b -> /10/11/12 output row: [10 10 11 12 NULL] statement ok @@ -544,9 +544,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/60/1/"@"/1/0, /Table/60/1/"@"/4/0 -fetched: /regional_by_row_table/regional_by_row_table_pkey/'ap-southeast-2'/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' +fetched: /regional_by_row_table/regional_by_row_table_pkey/?/1/pk2/a/b/j -> /1/2/3/'{"a": "b"}' output row: [1 1 2 3 '{"a": "b"}'] -fetched: /regional_by_row_table/regional_by_row_table_pkey/'ap-southeast-2'/4/pk2/a/b/j -> /4/5/6/'{"c": "d"}' +fetched: /regional_by_row_table/regional_by_row_table_pkey/?/4/pk2/a/b/j -> /4/5/6/'{"c": "d"}' output row: [4 4 5 6 '{"c": "d"}'] # Tests using locality optimized search for lookup joins (including foreign @@ -616,9 +616,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL # Semi join with locality optimized search disabled. query T @@ -646,9 +646,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL output row: [10 10] # Inner join with locality optimized search disabled. @@ -677,7 +677,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL output row: [10 10 10] @@ -708,7 +708,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL output row: [10 10 10] @@ -775,9 +775,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL statement ok SET tracing = on,kv,results; SELECT * FROM child WHERE NOT EXISTS (SELECT * FROM parent WHERE p_id = c_p_id) AND c_id = 20; SET tracing = off @@ -792,10 +792,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- Scan /Table/62/1/"@"/20/0 Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 -fetched: /child/child_pkey/'ca-central-1'/20/c_p_id -> /20 +fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL # Semi join with locality optimized search enabled. query T @@ -851,9 +851,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL output row: [10 10] statement ok @@ -869,10 +869,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- Scan /Table/62/1/"@"/20/0 Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 -fetched: /child/child_pkey/'ca-central-1'/20/c_p_id -> /20 +fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL +fetched: /parent/parent_pkey/?/? -> NULL output row: [20 20] # Inner join with locality optimized search enabled. @@ -929,7 +929,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL output row: [10 10 10] @@ -947,7 +947,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- Scan /Table/62/1/"@"/20/0 Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 -fetched: /child/child_pkey/'ca-central-1'/20/c_p_id -> /20 +fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL @@ -1007,7 +1007,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY ordinality ASC ---- Scan /Table/62/1/"@"/10/0 -fetched: /child/child_pkey/'ap-southeast-2'/10/c_p_id -> /10 +fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL output row: [10 10 10] @@ -1025,7 +1025,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- Scan /Table/62/1/"@"/20/0 Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 -fetched: /child/child_pkey/'ca-central-1'/20/c_p_id -> /20 +fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL diff --git a/pkg/sql/colfetcher/cfetcher.go b/pkg/sql/colfetcher/cfetcher.go index 1858514bc61b..d8a7ed9f7953 100644 --- a/pkg/sql/colfetcher/cfetcher.go +++ b/pkg/sql/colfetcher/cfetcher.go @@ -64,10 +64,6 @@ type cTableInfo struct { // One value per column that is part of the key; each value is a column // ordinal among only needed columns; -1 if we don't need the value for // that column. - // - // Note that if the tracing is enabled on the cFetcher (traceKV == true), - // then values for all columns are needed and, thus, there will be no -1 in - // indexColOrdinals. indexColOrdinals []int // The set of column ordinals which are both composite and part of the index @@ -84,10 +80,6 @@ type cTableInfo struct { // - for unique indexes, these columns are stored in the value (unless the // key contains a NULL value: then the extra columns are appended to the key // to unique-ify it). - // - // Note that if the tracing is enabled on the cFetcher (traceKV == true), - // then values for all columns are needed and, thus, there will be no -1 in - // extraValColOrdinals. extraValColOrdinals []int // invertedColOrdinal is a column ordinal among only needed columns, @@ -251,7 +243,7 @@ type cFetcher struct { maxKeysPerRow int // True if the index key must be decoded. This is only false if there are no - // needed columns and the tracing is not enabled. + // needed columns. mustDecodeIndexKey bool // mvccDecodeStrategy controls whether or not MVCC timestamps should @@ -1046,6 +1038,24 @@ func (rf *cFetcher) getDatumAt(colIdx int, rowIdx int) tree.Datum { return res[0] } +// writeDecodedCols writes the stringified representation of the decoded columns +// specified by colOrdinals. -1 in colOrdinals indicates that a column wasn't +// actually decoded (this is represented as "?" in the result). separator is +// inserted between each two subsequent decoded column values (but not before +// the first one). +func (rf *cFetcher) writeDecodedCols(buf *strings.Builder, colOrdinals []int, separator byte) { + for i, idx := range colOrdinals { + if i > 0 { + buf.WriteByte(separator) + } + if idx != -1 { + buf.WriteString(rf.getDatumAt(idx, rf.machine.rowIdx).String()) + } else { + buf.WriteByte('?') + } + } +} + // processValue processes the state machine's current value component, setting // columns in the rowIdx'th tuple in the current batch depending on what data // is found in the current value component. @@ -1065,19 +1075,13 @@ func (rf *cFetcher) processValue(ctx context.Context, familyID descpb.FamilyID) buf.WriteString(rf.table.desc.GetName()) buf.WriteByte('/') buf.WriteString(rf.table.index.GetName()) - // Note that because rf.traceKV is true, rf.table.indexColOrdinals will - // not include any -1, so idx values will all be valid. - for _, idx := range rf.table.indexColOrdinals { - buf.WriteByte('/') - buf.WriteString(rf.getDatumAt(idx, rf.machine.rowIdx).String()) - } + buf.WriteByte('/') + rf.writeDecodedCols(&buf, rf.table.indexColOrdinals, '/') prettyKey = buf.String() } if len(table.cols) == 0 { - // We don't need to decode any values. Note that this branch can only be - // executed if the tracing is disabled (if it was enabled, we would - // decode values from all columns). + // We don't need to decode any values. return nil } @@ -1147,12 +1151,10 @@ func (rf *cFetcher) processValue(ctx context.Context, familyID descpb.FamilyID) if err != nil { return scrub.WrapError(scrub.SecondaryIndexKeyExtraValueDecodingError, err) } - if rf.traceKV { + if rf.traceKV && len(table.extraValColOrdinals) > 0 { var buf strings.Builder - for _, idx := range table.extraValColOrdinals { - buf.WriteByte('/') - buf.WriteString(rf.getDatumAt(idx, rf.machine.rowIdx).String()) - } + buf.WriteByte('/') + rf.writeDecodedCols(&buf, table.extraValColOrdinals, '/') prettyValue = buf.String() } } @@ -1181,8 +1183,8 @@ func (rf *cFetcher) processValue(ctx context.Context, familyID descpb.FamilyID) } // processValueSingle processes the given value (of column -// family.DefaultColumnID), setting values in table.row accordingly. The key is -// only used for logging. +// family.DefaultColumnID), setting values in rf.machine.colvecs accordingly. +// The key is only used for logging. func (rf *cFetcher) processValueSingle( ctx context.Context, table *cTableInfo, @@ -1232,7 +1234,7 @@ func (rf *cFetcher) processValueSingle( if row.DebugRowFetch { log.Infof(ctx, "Scan %s -> [%d] (skipped)", rf.machine.nextKV.Key, colID) } - return "", "", nil + return prettyKey, prettyValue, nil } func (rf *cFetcher) processValueBytes( @@ -1336,18 +1338,12 @@ func (rf *cFetcher) fillNulls() error { continue } if !table.cols[i].IsNullable() { - var indexColValues []string - for _, idx := range table.indexColOrdinals { - if idx != -1 { - indexColValues = append(indexColValues, rf.getDatumAt(idx, rf.machine.rowIdx).String()) - } else { - indexColValues = append(indexColValues, "?") - } - } + var indexColValues strings.Builder + rf.writeDecodedCols(&indexColValues, table.indexColOrdinals, ',') return scrub.WrapError(scrub.UnexpectedNullValueError, errors.Errorf( "non-nullable column \"%s:%s\" with no value! Index scanned was %q with the index key columns (%s) and the values (%s)", table.desc.GetName(), table.cols[i].GetName(), table.index.GetName(), - strings.Join(table.index.IndexDesc().KeyColumnNames, ","), strings.Join(indexColValues, ","))) + strings.Join(table.index.IndexDesc().KeyColumnNames, ","), indexColValues.String())) } rf.machine.colvecs.Nulls[i].SetNull(rf.machine.rowIdx) } diff --git a/pkg/sql/colfetcher/cfetcher_setup.go b/pkg/sql/colfetcher/cfetcher_setup.go index 7140319c50d5..54be42f9428e 100644 --- a/pkg/sql/colfetcher/cfetcher_setup.go +++ b/pkg/sql/colfetcher/cfetcher_setup.go @@ -180,9 +180,6 @@ func populateTableArgs( // remapping that needs to be used for column ordinals from neededColumns. // post is updated accordingly to refer to new ordinals of columns. The method // also populates tableArgs.ColIdxMap. -// -// If traceKV is true, then all columns are considered as needed, and -// neededColumns is ignored. func keepOnlyNeededColumns( flowCtx *execinfra.FlowCtx, tableArgs *cFetcherTableArgs, @@ -191,9 +188,9 @@ func keepOnlyNeededColumns( post *execinfrapb.PostProcessSpec, helper *colexecargs.ExprHelper, ) error { - if !flowCtx.TraceKV && len(neededColumns) < len(tableArgs.cols) { - // If the tracing is not enabled and we don't need all of the available - // columns, we will prune all of the not needed columns away. + if len(neededColumns) < len(tableArgs.cols) { + // If we don't need all of the available columns, we will prune all of + // the not needed columns away. // First, populate a set of needed columns. var neededColumnsSet util.FastIntSet diff --git a/pkg/sql/opt/exec/execbuilder/testdata/ddl b/pkg/sql/opt/exec/execbuilder/testdata/ddl index c1bd125e5a47..8e36c79c155e 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/ddl +++ b/pkg/sql/opt/exec/execbuilder/testdata/ddl @@ -40,7 +40,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/foo/NULL -> /1 +fetched: /t/foo/NULL -> /? output row: [NULL] statement ok diff --git a/pkg/sql/opt/exec/execbuilder/testdata/orderby b/pkg/sql/opt/exec/execbuilder/testdata/orderby index fbf0f40a9ad3..2f746f3e6c1e 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/orderby +++ b/pkg/sql/opt/exec/execbuilder/testdata/orderby @@ -317,8 +317,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/ba/2/1/3 -> NULL -fetched: /abc/ba/5/4/6 -> NULL +fetched: /abc/ba/2/1/? -> NULL +fetched: /abc/ba/5/4/? -> NULL output row: [1 2] output row: [4 5] @@ -464,8 +464,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/bc/2/3 -> /1 -fetched: /abc/bc/5/6 -> /4 +fetched: /abc/bc/2/3 -> /? +fetched: /abc/bc/5/6 -> /? output row: [2 3] output row: [5 6] @@ -490,10 +490,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/abc_pkey/4/5/6/d -> 'Two' -fetched: /abc/abc_pkey/4/5/6 -> NULL -fetched: /abc/abc_pkey/1/2/3/d -> 'one' -fetched: /abc/abc_pkey/1/2/3 -> NULL +fetched: /abc/abc_pkey/4/?/? -> NULL +fetched: /abc/abc_pkey/4/?/? -> NULL +fetched: /abc/abc_pkey/1/?/? -> NULL +fetched: /abc/abc_pkey/1/?/? -> NULL output row: [4] output row: [1] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic index cf4ecdbcbd01..b1757917cd17 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic +++ b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic @@ -59,7 +59,7 @@ query T SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched: /t1/nonuniqueidx/%' ---- -fetched: /t1/nonuniqueidx/1/1 -> NULL +fetched: /t1/nonuniqueidx/1/? -> NULL query I SET TRACING=on,kv,results; @@ -72,7 +72,7 @@ query T SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched: /t1/uniqueidx/%' ---- -fetched: /t1/uniqueidx/1 -> /1 +fetched: /t1/uniqueidx/1 -> /? query IIIII SET TRACING=on,kv,results; diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select b/pkg/sql/opt/exec/execbuilder/testdata/select index ad26adeb6fe4..8c25a35d8403 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select +++ b/pkg/sql/opt/exec/execbuilder/testdata/select @@ -839,7 +839,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /dt/dt_b_key/'2015-08-25' -> /'2015-08-25 04:45:45.53453' +fetched: /dt/dt_b_key/'2015-08-25' -> /? output row: ['2015-08-25'] statement ok @@ -850,8 +850,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /dt/dt_c_key/'02:45:02.234' -> /'2015-08-25 04:45:45.53453' -fetched: /dt/dt_c_key/'34:00:02' -> /'2015-08-30 03:34:45.34567' +fetched: /dt/dt_c_key/'02:45:02.234' -> /? +fetched: /dt/dt_c_key/'34:00:02' -> /? output row: ['02:45:02.234'] output row: ['34:00:02'] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select_index b/pkg/sql/opt/exec/execbuilder/testdata/select_index index b3e5492ff6be..4a64057d307d 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select_index +++ b/pkg/sql/opt/exec/execbuilder/testdata/select_index @@ -126,8 +126,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/bc/'three'/33/3 -> NULL -fetched: /t/bc/'two'/22/2 -> NULL +fetched: /t/bc/'three'/?/3 -> NULL +fetched: /t/bc/'two'/?/2 -> NULL output row: [3 'three'] output row: [2 'two'] @@ -170,9 +170,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/a_desc/3/'three' -> NULL -fetched: /t/a_desc/2/'two' -> NULL -fetched: /t/a_desc/1/'one' -> NULL +fetched: /t/a_desc/3/? -> NULL +fetched: /t/a_desc/2/? -> NULL +fetched: /t/a_desc/1/? -> NULL output row: [3] output row: [2] output row: [1] @@ -186,8 +186,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/a_desc/3/'three' -> NULL -fetched: /t/a_desc/2/'two' -> NULL +fetched: /t/a_desc/3/? -> NULL +fetched: /t/a_desc/2/? -> NULL output row: [3] output row: [2] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select_index_vectorize_off b/pkg/sql/opt/exec/execbuilder/testdata/select_index_vectorize_off index c7a626d4feed..e5899ccc5b5d 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select_index_vectorize_off +++ b/pkg/sql/opt/exec/execbuilder/testdata/select_index_vectorize_off @@ -35,26 +35,26 @@ SELECT regexp_replace(message, '\d\d\d\d\d+', '...PK...') FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched:%' ---- -fetched: /test2/test2_k_key/'030' -> /...PK... -fetched: /test2/test2_k_key/'029' -> /...PK... -fetched: /test2/test2_k_key/'028' -> /...PK... -fetched: /test2/test2_k_key/'027' -> /...PK... -fetched: /test2/test2_k_key/'026' -> /...PK... -fetched: /test2/test2_k_key/'025' -> /...PK... -fetched: /test2/test2_k_key/'024' -> /...PK... -fetched: /test2/test2_k_key/'023' -> /...PK... -fetched: /test2/test2_k_key/'022' -> /...PK... -fetched: /test2/test2_k_key/'021' -> /...PK... -fetched: /test2/test2_k_key/'020' -> /...PK... -fetched: /test2/test2_k_key/'019' -> /...PK... -fetched: /test2/test2_k_key/'018' -> /...PK... -fetched: /test2/test2_k_key/'017' -> /...PK... -fetched: /test2/test2_k_key/'016' -> /...PK... -fetched: /test2/test2_k_key/'015' -> /...PK... -fetched: /test2/test2_k_key/'014' -> /...PK... -fetched: /test2/test2_k_key/'013' -> /...PK... -fetched: /test2/test2_k_key/'012' -> /...PK... -fetched: /test2/test2_k_key/'011' -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... +fetched: /test2/test2_k_key/? -> /...PK... fetched: /test2/test2_pkey/...PK.../k/v -> /'030'/42 fetched: /test2/test2_pkey/...PK.../k/v -> /'029'/42 fetched: /test2/test2_pkey/...PK.../k/v -> /'028'/42 diff --git a/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic b/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic index d41cf13877f9..c7059feb1373 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic +++ b/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic @@ -45,7 +45,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] ---- Scan /Table/56/{1-2} fetched: /tu/tu_pkey/1 -> NULL -fetched: /tu/tu_pkey/1/b -> 2 +fetched: /tu/tu_pkey/1 -> NULL fetched: /tu/tu_pkey/1/c/d -> /3/4 Put /Table/56/1/1/2/1 -> /TUPLE/3:3:Int/4/1:4:Int/4 fast path completed diff --git a/pkg/sql/opt/exec/execbuilder/testdata/virtual_columns b/pkg/sql/opt/exec/execbuilder/testdata/virtual_columns index 5aaa8493fdbe..590056b48410 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/virtual_columns +++ b/pkg/sql/opt/exec/execbuilder/testdata/virtual_columns @@ -1566,3 +1566,18 @@ vectorized: true missing stats table: t65343@t65343_c_idx spans: [/'foo' COLLATE en_US - /'foo' COLLATE en_US] + +# Regression test for #73745. The cFetcher should not fetch virtual computed +# columns from a primary index. +statement ok +CREATE TABLE t73745 ( + i INT PRIMARY KEY, + v INT NOT NULL AS ((i * 2)) VIRTUAL +); +INSERT INTO t73745 VALUES (1), (2), (3); + +# Use kvtrace to simulate \set auto_trace=on,kv. +query T kvtrace +SELECT * FROM t73745 +---- +Scan /Table/61/{1-2} diff --git a/pkg/sql/opt/exec/execbuilder/testdata/window b/pkg/sql/opt/exec/execbuilder/testdata/window index e9450dff6b85..6b70745ecb0a 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/window +++ b/pkg/sql/opt/exec/execbuilder/testdata/window @@ -31,23 +31,23 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv/kv_pkey/1/v/w/f/b -> /2/3/1.0/true +fetched: /kv/kv_pkey/1/v -> /2 fetched: /kv/kv_pkey/1/d -> 1 -fetched: /kv/kv_pkey/1/s -> 'a' -fetched: /kv/kv_pkey/3/v/w/f/b -> /4/5/2.0/true +fetched: /kv/kv_pkey/1 -> NULL +fetched: /kv/kv_pkey/3/v -> /4 fetched: /kv/kv_pkey/3/d -> 8 -fetched: /kv/kv_pkey/3/s -> 'a' -fetched: /kv/kv_pkey/5/w/f/b -> /5/9.9/false +fetched: /kv/kv_pkey/3 -> NULL +fetched: /kv/kv_pkey/5 -> NULL fetched: /kv/kv_pkey/5/d -> -321 -fetched: /kv/kv_pkey/6/v/w/f/b -> /2/3/4.4/true +fetched: /kv/kv_pkey/6/v -> /2 fetched: /kv/kv_pkey/6/d -> 4.4 -fetched: /kv/kv_pkey/6/s -> 'b' -fetched: /kv/kv_pkey/7/v/w/f/b -> /2/2/6.0/true +fetched: /kv/kv_pkey/6 -> NULL +fetched: /kv/kv_pkey/7/v -> /2 fetched: /kv/kv_pkey/7/d -> 7.9 -fetched: /kv/kv_pkey/7/s -> 'b' -fetched: /kv/kv_pkey/8/v/w/f/b -> /4/2/3.0/false +fetched: /kv/kv_pkey/7 -> NULL +fetched: /kv/kv_pkey/8/v -> /4 fetched: /kv/kv_pkey/8/d -> 3 -fetched: /kv/kv_pkey/8/s -> 'A' +fetched: /kv/kv_pkey/8 -> NULL output row: [5 NULL] output row: [1 3.4501207708330056852] output row: [6 3.4501207708330056852] diff --git a/pkg/sql/row/fetcher.go b/pkg/sql/row/fetcher.go index ea6e88d25469..0a34de20cc01 100644 --- a/pkg/sql/row/fetcher.go +++ b/pkg/sql/row/fetcher.go @@ -694,7 +694,7 @@ func (rf *Fetcher) NextKey(ctx context.Context) (rowDone bool, _ error) { if unchangedPrefix { // Skip decoding! rf.keyRemainingBytes = rf.kv.Key[len(rf.indexKey):] - } else if rf.mustDecodeIndexKey || rf.traceKV { + } else if rf.mustDecodeIndexKey { rf.keyRemainingBytes, moreKVs, foundNull, err = rf.ReadIndexKey(rf.kv.Key) if err != nil { return false, err @@ -767,14 +767,12 @@ func (rf *Fetcher) NextKey(ctx context.Context) (rowDone bool, _ error) { func (rf *Fetcher) prettyEncDatums(types []*types.T, vals []rowenc.EncDatum) string { var buf strings.Builder for i, v := range vals { + buf.WriteByte('/') if err := v.EnsureDecoded(types[i], rf.alloc); err != nil { - buf.WriteString("/{error decoding: ") - buf.WriteString(err.Error()) - buf.WriteByte('}') - continue + buf.WriteByte('?') + } else { + buf.WriteString(v.Datum.String()) } - buf.WriteByte('/') - buf.WriteString(v.Datum.String()) } return buf.String() } @@ -1008,7 +1006,7 @@ func (rf *Fetcher) processValueSingle( return "", "", errors.Errorf("single entry value with no default column id") } - if rf.traceKV || table.neededCols.Contains(int(colID)) { + if table.neededCols.Contains(int(colID)) { if idx, ok := table.colIdxMap.Get(colID); ok { if rf.traceKV { prettyKey = fmt.Sprintf("%s/%s", prettyKey, table.desc.DeletableColumns()[idx].GetName()) From 2c23b809afb3bcbca3838490fcb0443cae16a1b8 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Mon, 27 Dec 2021 15:32:59 -0800 Subject: [PATCH 4/5] colfetcher: find needed columns upfront Previously, the two users of the `cFetcher` (`ColBatchScan` and `ColIndexJoin`) had different ways of figuring out which columns are actually needed to be fetched (that information is needed to not decode parts of the KV pairs unnecessarily). In one case we explicitly propagated the information through the spec, and in another we did some pre-processing to find the information. This overall was more complicated than necessary (because we had complex code path for pruning "unaccessible" columns from the secondary index while keeping track of the ordinal mapping) as well as suboptimal (in some cases `TableReaderSpec.NeededColumns` contained ordinals of the columns that weren't actually needed by the post-processing stage), so this commit unifies both ways into one addressing both of these shortcomings. Now, in order to find the set of needed columns, we examine the post-processing spec all the time, but we do it in an efficient manner: - we make sure to deserialize render expressions early - we use a `tree.Visitor` rather than a heavy-weight `ExprHelper`. As a result, we can remove `TableReaderSpec.NeededColumns` field as well as not decode some columns in a handful of cases. Release note: None --- pkg/sql/colexec/colbuilder/execplan_test.go | 5 +- pkg/sql/colexec/colexecargs/BUILD.bazel | 1 - pkg/sql/colexec/colexecargs/expr.go | 53 ---- pkg/sql/colfetcher/BUILD.bazel | 1 + pkg/sql/colfetcher/cfetcher_setup.go | 258 +++++++----------- pkg/sql/colfetcher/colbatch_scan.go | 8 +- pkg/sql/colfetcher/index_join.go | 38 +-- pkg/sql/colflow/colbatch_scan_test.go | 4 +- pkg/sql/distsql_physical_planner.go | 1 - pkg/sql/distsql_spec_exec_factory.go | 1 - pkg/sql/execinfra/version.go | 9 +- pkg/sql/execinfrapb/processors_sql.proto | 10 +- pkg/sql/flowinfra/cluster_test.go | 21 +- pkg/sql/flowinfra/server_test.go | 9 +- .../opt/exec/execbuilder/testdata/aggregate | 2 +- pkg/sql/opt/exec/execbuilder/testdata/ddl | 4 +- .../exec/execbuilder/testdata/select_index | 20 +- pkg/sql/physicalplan/aggregator_funcs_test.go | 5 +- 18 files changed, 144 insertions(+), 306 deletions(-) diff --git a/pkg/sql/colexec/colbuilder/execplan_test.go b/pkg/sql/colexec/colbuilder/execplan_test.go index d59ce72fb0c5..d2623c15f78c 100644 --- a/pkg/sql/colexec/colbuilder/execplan_test.go +++ b/pkg/sql/colexec/colbuilder/execplan_test.go @@ -84,9 +84,8 @@ func TestNewColOperatorExpectedTypeSchema(t *testing.T) { desc := catalogkv.TestingGetTableDescriptor(kvDB, keys.SystemSQLCodec, "test", "t") tr := execinfrapb.TableReaderSpec{ - Table: *desc.TableDesc(), - Spans: make([]roachpb.Span, 1), - NeededColumns: []uint32{0}, + Table: *desc.TableDesc(), + Spans: make([]roachpb.Span, 1), } var err error tr.Spans[0].Key, err = randgen.TestingMakePrimaryIndexKey(desc, 0) diff --git a/pkg/sql/colexec/colexecargs/BUILD.bazel b/pkg/sql/colexec/colexecargs/BUILD.bazel index 1c16d03209c5..34047e3c0b59 100644 --- a/pkg/sql/colexec/colexecargs/BUILD.bazel +++ b/pkg/sql/colexec/colexecargs/BUILD.bazel @@ -16,7 +16,6 @@ go_library( "//pkg/sql/colexecop", "//pkg/sql/execinfra", "//pkg/sql/execinfrapb", - "//pkg/sql/parser", "//pkg/sql/sem/tree", "//pkg/sql/types", "//pkg/util/mon", diff --git a/pkg/sql/colexec/colexecargs/expr.go b/pkg/sql/colexec/colexecargs/expr.go index b14d0396de27..f524715e045e 100644 --- a/pkg/sql/colexec/colexecargs/expr.go +++ b/pkg/sql/colexec/colexecargs/expr.go @@ -14,7 +14,6 @@ import ( "sync" "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" - "github.com/cockroachdb/cockroach/pkg/sql/parser" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" ) @@ -51,55 +50,3 @@ func (h *ExprHelper) ProcessExpr( tempVars := tree.MakeIndexedVarHelper(&h.helper, len(typs)) return execinfrapb.DeserializeExpr(expr.Expr, h.SemaCtx, evalCtx, &tempVars) } - -// Remove unused warning. -var _ = findIVarsInRange - -// findIVarsInRange searches Expr for presence of tree.IndexedVars with indices -// in range [start, end). It returns a slice containing all such indices. -func findIVarsInRange(expr execinfrapb.Expression, start int, end int) ([]uint32, error) { - res := make([]uint32, 0) - if start >= end { - return res, nil - } - var exprToWalk tree.Expr - if expr.LocalExpr != nil { - exprToWalk = expr.LocalExpr - } else { - e, err := parser.ParseExpr(expr.Expr) - if err != nil { - return nil, err - } - exprToWalk = e - } - visitor := ivarExpressionVisitor{ivarSeen: make([]bool, end)} - _, _ = tree.WalkExpr(visitor, exprToWalk) - for i := start; i < end; i++ { - if visitor.ivarSeen[i] { - res = append(res, uint32(i)) - } - } - return res, nil -} - -type ivarExpressionVisitor struct { - ivarSeen []bool -} - -var _ tree.Visitor = &ivarExpressionVisitor{} - -// VisitPre is a part of tree.Visitor interface. -func (i ivarExpressionVisitor) VisitPre(expr tree.Expr) (bool, tree.Expr) { - switch e := expr.(type) { - case *tree.IndexedVar: - if e.Idx < len(i.ivarSeen) { - i.ivarSeen[e.Idx] = true - } - return false, expr - default: - return true, expr - } -} - -// VisitPost is a part of tree.Visitor interface. -func (i ivarExpressionVisitor) VisitPost(expr tree.Expr) tree.Expr { return expr } diff --git a/pkg/sql/colfetcher/BUILD.bazel b/pkg/sql/colfetcher/BUILD.bazel index a4cb289bbc1c..3ab245fefc10 100644 --- a/pkg/sql/colfetcher/BUILD.bazel +++ b/pkg/sql/colfetcher/BUILD.bazel @@ -26,6 +26,7 @@ go_library( "//pkg/sql/colencoding", "//pkg/sql/colexec/colexecargs", "//pkg/sql/colexec/colexecspan", + "//pkg/sql/colexec/colexecutils", "//pkg/sql/colexecerror", "//pkg/sql/colexecop", "//pkg/sql/colmem", diff --git a/pkg/sql/colfetcher/cfetcher_setup.go b/pkg/sql/colfetcher/cfetcher_setup.go index 54be42f9428e..d1e59cea6ca8 100644 --- a/pkg/sql/colfetcher/cfetcher_setup.go +++ b/pkg/sql/colfetcher/cfetcher_setup.go @@ -16,9 +16,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecargs" + "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecutils" "github.com/cockroachdb/cockroach/pkg/sql/execinfra" "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" "github.com/cockroachdb/cockroach/pkg/sql/physicalplan" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util" ) @@ -71,26 +73,12 @@ func (a *cFetcherTableArgs) populateTypes(cols []catalog.Column) { } } -// populateTableArgs fills all fields of the cFetcherTableArgs except for -// ColIdxMap. Note that all columns accessible from the index (i.e. present in -// the key or value part) will be included in the result. In order to prune -// the unnecessary columns away, use keepOnlyNeededColumns. -// -// If index is a secondary index, then all inaccessible columns are pruned away. -// In such a scenario a non-nil idxMap is returned that allows to remap ordinals -// referring to columns from the whole table to the correct positions among only -// accessible columns. post will be adjusted automatically. Columns that are -// not accessible from the secondary index have an undefined value corresponding -// to them if idxMap is non-nil. -// -// For example, say the table has 4 columns (@1, @2, @3, @4), but only 2 columns -// are present in the index we're reading from (@3, @1). In this case, the -// returned table args only contains columns (@1, @3) and we get an index map as -// idxMap = [0, x, 1, x] (where 'x' indicates an undefined value). -// Note that although @3 appears earlier than @1 in the index, because we -// iterate over all columns of the table according to their column ordinals, we -// will see @1 first, so it gets the 0th slot, and @3 second, so it gets the 1st -// slot. +// populateTableArgs fills all fields of the cFetcherTableArgs. It examines the +// given post-processing spec to find the set of the needed columns, and only +// these columns are added into the table args while post is adjusted +// accordingly. +// - neededColumns is a set containing the ordinals of all columns that need to +// be fetched. func populateTableArgs( ctx context.Context, flowCtx *execinfra.FlowCtx, @@ -101,7 +89,7 @@ func populateTableArgs( hasSystemColumns bool, post *execinfrapb.PostProcessSpec, helper *colexecargs.ExprHelper, -) (_ *cFetcherTableArgs, idxMap []int, _ error) { +) (_ *cFetcherTableArgs, neededColumns util.FastIntSet, _ error) { args := cFetcherTableArgsPool.Get().(*cFetcherTableArgs) // First, find all columns present in the table and possibly include the // system columns (when requested). @@ -119,44 +107,44 @@ func populateTableArgs( } } } - numSystemCols := 0 if hasSystemColumns { - systemCols := table.SystemColumns() - numSystemCols = len(systemCols) - cols = append(cols, systemCols...) + cols = append(cols, table.SystemColumns()...) } - if !index.Primary() { - // If we have a secondary index, not all columns might be available from - // the index, so we'll prune the unavailable columns away. - colIDs := index.CollectKeyColumnIDs() - colIDs.UnionWith(index.CollectSecondaryStoredColumnIDs()) - colIDs.UnionWith(index.CollectKeySuffixColumnIDs()) - if colIDs.Len() < len(cols)-numSystemCols { - needTypesBeforeRemapping := post.RenderExprs != nil - if needTypesBeforeRemapping { - args.populateTypes(cols) - } - idxMap = make([]int, len(cols)) - colIdx := 0 - for i := range cols { - //gcassert:bce - id := cols[i].GetID() - if colIDs.Contains(id) || (hasSystemColumns && i >= len(cols)-numSystemCols) { - idxMap[i] = colIdx - cols[colIdx] = cols[i] - colIdx++ - } - } - cols = cols[:colIdx] - if err := remapPostProcessSpec( - flowCtx, post, idxMap, helper, args.typs, - ); err != nil { - return nil, nil, err + var err error + // Make sure that render expressions are deserialized right away so that we + // don't have to re-parse them multiple times. + if post.RenderExprs != nil { + args.populateTypes(cols) + for i := range post.RenderExprs { + // It is ok to use the evalCtx of the flowCtx since it won't be + // mutated (we are not evaluating the expressions). It's also ok to + // update post in-place even if flowCtx.PreserveFlowSpecs is true + // since we're not really mutating the render expressions. + post.RenderExprs[i].LocalExpr, err = helper.ProcessExpr(post.RenderExprs[i], flowCtx.EvalCtx, args.typs) + if err != nil { + return args, neededColumns, err } } } + // Now find the set of columns that are actually needed based on the + // post-processing spec. + neededColumns = getNeededColumns(post, len(cols)) + + // Prune away columns that aren't needed. + if neededColumns.Len() != len(cols) { + idxMap := make([]int, len(cols)) + keepColIdx := 0 + for idx, ok := neededColumns.Next(0); ok; idx, ok = neededColumns.Next(idx + 1) { + cols[keepColIdx] = cols[idx] + idxMap[idx] = keepColIdx + keepColIdx++ + } + cols = cols[:keepColIdx] + remapPostProcessSpec(post, idxMap, flowCtx.PreserveFlowSpecs) + } + *args = cFetcherTableArgs{ desc: table, index: index, @@ -165,114 +153,59 @@ func populateTableArgs( typs: args.typs, } args.populateTypes(cols) + for i := range cols { + args.ColIdxMap.Set(cols[i].GetID(), i) + } // Before we can safely use types from the table descriptor, we need to // make sure they are hydrated. In row execution engine it is done during // the processor initialization, but neither ColBatchScan nor cFetcher are // processors, so we need to do the hydration ourselves. resolver := flowCtx.TypeResolverFactory.NewTypeResolver(flowCtx.Txn) - return args, idxMap, resolver.HydrateTypeSlice(ctx, args.typs) + return args, neededColumns, resolver.HydrateTypeSlice(ctx, args.typs) } -// keepOnlyNeededColumns updates the tableArgs to prune all unnecessary columns -// away based on neededColumns slice. If we're reading of the secondary index -// that is not covering all columns, idxMap must be non-nil describing the -// remapping that needs to be used for column ordinals from neededColumns. -// post is updated accordingly to refer to new ordinals of columns. The method -// also populates tableArgs.ColIdxMap. -func keepOnlyNeededColumns( - flowCtx *execinfra.FlowCtx, - tableArgs *cFetcherTableArgs, - idxMap []int, - neededColumns []uint32, - post *execinfrapb.PostProcessSpec, - helper *colexecargs.ExprHelper, -) error { - if len(neededColumns) < len(tableArgs.cols) { - // If we don't need all of the available columns, we will prune all of - // the not needed columns away. - - // First, populate a set of needed columns. - var neededColumnsSet util.FastIntSet - for _, neededColumn := range neededColumns { - neededColIdx := int(neededColumn) - if idxMap != nil { - neededColIdx = idxMap[neededColIdx] - } - neededColumnsSet.Add(neededColIdx) - } - - // When idxMap is non-nil, we can reuse that. Note that in this case - // the length of idxMap is equal to the number of columns in the - // whole table, and we are reading from the secondary index, so the - // slice will have the sufficient size. We also don't need to reset - // it since we'll update the needed positions below. - if idxMap == nil { - idxMap = make([]int, len(tableArgs.typs)) - } - - // Iterate over all needed columns, populate the idxMap, and adjust - // the post-processing spec to refer only to the needed columns - // directly. - // - // If non-nil idxMap was passed into this method, we have to update it - // by essentially applying a projection on top of the already present - // projection. Consider the following example: - // idxMap = [0, x, 1, x] (where 'x' indicates an undefined value) - // and - // neededColumns = [2]. - // Such a setup means that only columns with ordinals @1 and @3 are - // present in the secondary index while only @3 is actually needed. - // Above, we have already remapped neededColIdx = 2 to be 1, so now - // neededColumnsSet only contains 1. The post-processing already refers - // to this column as having index 1. - // However, since we are pruning the column with index 0 away, the - // post-processing stage will see a single column. Thus, we have to - // update the index map to be - // idxMap = [x, 0, x, x] - // and then remap the post-processing spec below so that it refers to - // the single needed column with the correct ordinal. - neededColIdx := 0 - for idx, ok := neededColumnsSet.Next(0); ok; idx, ok = neededColumnsSet.Next(idx + 1) { - idxMap[idx] = neededColIdx - neededColIdx++ - } - if err := remapPostProcessSpec( - flowCtx, post, idxMap, helper, tableArgs.typs, - ); err != nil { - return err +// getNeededColumns returns the set of needed columns that a processor core must +// output because these columns are used by the post-processing stage. It is +// assumed that the render expressions, if any, have already been deserialized. +func getNeededColumns(post *execinfrapb.PostProcessSpec, numColumns int) util.FastIntSet { + var neededColumns util.FastIntSet + if !post.Projection && len(post.RenderExprs) == 0 { + // All columns are needed. + neededColumns.AddRange(0, numColumns-1) + } else if post.Projection { + for _, neededColOrd := range post.OutputColumns { + neededColumns.Add(int(neededColOrd)) } - - // Now we have to actually prune out the unnecessary columns. - neededColIdx = 0 - for idx, ok := neededColumnsSet.Next(0); ok; idx, ok = neededColumnsSet.Next(idx + 1) { - tableArgs.cols[neededColIdx] = tableArgs.cols[idx] - tableArgs.typs[neededColIdx] = tableArgs.typs[idx] - neededColIdx++ + } else { + var visitor ivarExpressionVisitor + for _, expr := range post.RenderExprs { + visitor.ivarSeen = colexecutils.MaybeAllocateBoolArray(visitor.ivarSeen, numColumns) + _, _ = tree.WalkExpr(visitor, expr.LocalExpr) + for i, seen := range visitor.ivarSeen { + if seen { + neededColumns.Add(i) + } + } + if neededColumns.Len() == numColumns { + // All columns are needed, so we can stop processing the + // subsequent render expressions. + break + } } - tableArgs.cols = tableArgs.cols[:neededColIdx] - tableArgs.typs = tableArgs.typs[:neededColIdx] } - - // Populate the ColIdxMap. - for i := range tableArgs.cols { - tableArgs.ColIdxMap.Set(tableArgs.cols[i].GetID(), i) - } - return nil + return neededColumns } // remapPostProcessSpec updates post so that all IndexedVars refer to the new -// ordinals according to idxMap. +// ordinals according to idxMap. It is assumed that the render expressions, if +// any, have already been deserialized. // // For example, say we have idxMap = [0, 0, 1, 2, 0, 0] and a render expression // like '(@1 + @4) / @3`, then it'll be updated into '(@1 + @3) / @2'. Such an // idxMap indicates that the table has 6 columns and only 3 of them (0th, 2nd, // 3rd) are needed. // -// typsBeforeRemapping need to contain all the types of columns before the -// mapping of idxMap was applied. These will only be used if post.RenderExprs is -// not nil. -// // If preserveFlowSpecs is true, then this method updates post to store the // original output columns or render expressions. Notably, in order to not // corrupt the flow specs that have been scheduled to run on the remote nodes, @@ -283,16 +216,10 @@ func keepOnlyNeededColumns( // which occurs **after** we have sent out SetupFlowRequest RPCs. In other // words, every node must have gotten the unmodified version of the spec and is // now free to modify it as it pleases. -func remapPostProcessSpec( - flowCtx *execinfra.FlowCtx, - post *execinfrapb.PostProcessSpec, - idxMap []int, - helper *colexecargs.ExprHelper, - typsBeforeRemapping []*types.T, -) error { +func remapPostProcessSpec(post *execinfrapb.PostProcessSpec, idxMap []int, preserveFlowSpecs bool) { if post.Projection { outputColumns := post.OutputColumns - if flowCtx.PreserveFlowSpecs && post.OriginalOutputColumns == nil { + if preserveFlowSpecs && post.OriginalOutputColumns == nil { // This is the first time we're modifying this PostProcessSpec, but // we've been asked to preserve the specs, so we have to set the // original output columns. We are also careful to allocate a new @@ -305,7 +232,7 @@ func remapPostProcessSpec( } } else if post.RenderExprs != nil { renderExprs := post.RenderExprs - if flowCtx.PreserveFlowSpecs && post.OriginalRenderExprs == nil { + if preserveFlowSpecs && post.OriginalRenderExprs == nil { // This is the first time we're modifying this PostProcessSpec, but // we've been asked to preserve the specs, so we have to set the // original render expressions. We are also careful to allocate a @@ -313,19 +240,30 @@ func remapPostProcessSpec( post.OriginalRenderExprs = renderExprs post.RenderExprs = make([]execinfrapb.Expression, len(renderExprs)) } - var err error for i := range renderExprs { - // Make sure that the render expression is deserialized if we - // are on the remote node. - // - // It is ok to use the evalCtx of the flowCtx since it won't be - // mutated (we are not evaluating the expressions). - post.RenderExprs[i].LocalExpr, err = helper.ProcessExpr(renderExprs[i], flowCtx.EvalCtx, typsBeforeRemapping) - if err != nil { - return err - } post.RenderExprs[i].LocalExpr = physicalplan.RemapIVarsInTypedExpr(renderExprs[i].LocalExpr, idxMap) } } - return nil } + +type ivarExpressionVisitor struct { + ivarSeen []bool +} + +var _ tree.Visitor = &ivarExpressionVisitor{} + +// VisitPre is a part of tree.Visitor interface. +func (i ivarExpressionVisitor) VisitPre(expr tree.Expr) (bool, tree.Expr) { + switch e := expr.(type) { + case *tree.IndexedVar: + if e.Idx < len(i.ivarSeen) { + i.ivarSeen[e.Idx] = true + } + return false, expr + default: + return true, expr + } +} + +// VisitPost is a part of tree.Visitor interface. +func (i ivarExpressionVisitor) VisitPost(expr tree.Expr) tree.Expr { return expr } diff --git a/pkg/sql/colfetcher/colbatch_scan.go b/pkg/sql/colfetcher/colbatch_scan.go index 97b265fb92e2..2988b80b5db8 100644 --- a/pkg/sql/colfetcher/colbatch_scan.go +++ b/pkg/sql/colfetcher/colbatch_scan.go @@ -206,7 +206,7 @@ func NewColBatchScan( // retrieving the hydrated immutable from cache. table := spec.BuildTableDescriptor() invertedColumn := tabledesc.FindInvertedColumn(table, spec.InvertedColumn) - tableArgs, idxMap, err := populateTableArgs( + tableArgs, _, err := populateTableArgs( ctx, flowCtx, table, table.ActiveIndexes()[spec.IndexIdx], invertedColumn, spec.Visibility, spec.HasSystemColumns, post, helper, ) @@ -214,12 +214,6 @@ func NewColBatchScan( return nil, err } - if err = keepOnlyNeededColumns( - flowCtx, tableArgs, idxMap, spec.NeededColumns, post, helper, - ); err != nil { - return nil, err - } - fetcher := cFetcherPool.Get().(*cFetcher) fetcher.cFetcherArgs = cFetcherArgs{ spec.LockingStrength, diff --git a/pkg/sql/colfetcher/index_join.go b/pkg/sql/colfetcher/index_join.go index 41d011eaaf35..bb2a948b9710 100644 --- a/pkg/sql/colfetcher/index_join.go +++ b/pkg/sql/colfetcher/index_join.go @@ -412,47 +412,13 @@ func NewColIndexJoin( // retrieving the hydrated immutable from cache. table := spec.BuildTableDescriptor() index := table.ActiveIndexes()[spec.IndexIdx] - tableArgs, idxMap, err := populateTableArgs( + tableArgs, neededColumns, err := populateTableArgs( ctx, flowCtx, table, index, nil, /* invertedCol */ spec.Visibility, spec.HasSystemColumns, post, helper, ) if err != nil { return nil, err } - if idxMap != nil { - // The index join is fetching from the primary index, so there should be - // no mapping needed. - return nil, errors.AssertionFailedf("unexpectedly non-nil idx map for the index join") - } - - // Retrieve the set of columns that the index join needs to fetch. - var neededColumns []uint32 - var neededColOrdsInWholeTable util.FastIntSet - if post.OutputColumns != nil { - neededColumns = post.OutputColumns - for _, neededColOrd := range neededColumns { - neededColOrdsInWholeTable.Add(int(neededColOrd)) - } - } else { - proc := &execinfra.ProcOutputHelper{} - // It is ok to use the evalCtx of the flowCtx here since we only use the - // ProcOutputHelper to get a set of the needed columns and will not be - // evaluating any expressions. - if err = proc.Init(post, tableArgs.typs, helper.SemaCtx, flowCtx.EvalCtx); err != nil { - return nil, err - } - neededColOrdsInWholeTable = proc.NeededColumns() - neededColumns = make([]uint32, 0, neededColOrdsInWholeTable.Len()) - for i, ok := neededColOrdsInWholeTable.Next(0); ok; i, ok = neededColOrdsInWholeTable.Next(i + 1) { - neededColumns = append(neededColumns, uint32(i)) - } - } - - if err = keepOnlyNeededColumns( - flowCtx, tableArgs, idxMap, neededColumns, post, helper, - ); err != nil { - return nil, err - } fetcher := cFetcherPool.Get().(*cFetcher) fetcher.cFetcherArgs = cFetcherArgs{ @@ -472,7 +438,7 @@ func NewColIndexJoin( } spanAssembler := colexecspan.NewColSpanAssembler( - flowCtx.Codec(), allocator, table, index, inputTypes, neededColOrdsInWholeTable, + flowCtx.Codec(), allocator, table, index, inputTypes, neededColumns, ) op := &ColIndexJoin{ diff --git a/pkg/sql/colflow/colbatch_scan_test.go b/pkg/sql/colflow/colbatch_scan_test.go index a40504a5456a..315387b04ffc 100644 --- a/pkg/sql/colflow/colbatch_scan_test.go +++ b/pkg/sql/colflow/colbatch_scan_test.go @@ -77,8 +77,7 @@ func TestColBatchScanMeta(t *testing.T) { Spans: []roachpb.Span{ td.PrimaryIndexSpan(keys.SystemSQLCodec), }, - NeededColumns: []uint32{0}, - Table: *td.TableDesc(), + Table: *td.TableDesc(), }}, ResultTypes: types.OneIntCol, } @@ -134,7 +133,6 @@ func BenchmarkColBatchScan(b *testing.B) { TableReader: &execinfrapb.TableReaderSpec{ Table: *tableDesc.TableDesc(), // Spans will be set below. - NeededColumns: []uint32{0, 1}, }}, ResultTypes: types.TwoIntCols, } diff --git a/pkg/sql/distsql_physical_planner.go b/pkg/sql/distsql_physical_planner.go index 5233131c2fc4..3ae1e633b7a6 100644 --- a/pkg/sql/distsql_physical_planner.go +++ b/pkg/sql/distsql_physical_planner.go @@ -1111,7 +1111,6 @@ func initTableReaderSpec( LockingStrength: n.lockingStrength, LockingWaitPolicy: n.lockingWaitPolicy, HasSystemColumns: n.containsSystemColumns, - NeededColumns: n.colCfg.wantedColumnsOrdinals, } if vc := getInvertedColumn(n.colCfg.invertedColumn, n.cols); vc != nil { s.InvertedColumn = vc.ColumnDesc() diff --git a/pkg/sql/distsql_spec_exec_factory.go b/pkg/sql/distsql_spec_exec_factory.go index 57a247cc170c..69292fdcd356 100644 --- a/pkg/sql/distsql_spec_exec_factory.go +++ b/pkg/sql/distsql_spec_exec_factory.go @@ -238,7 +238,6 @@ func (e *distSQLSpecExecFactory) ConstructScan( IsCheck: false, Visibility: colCfg.visibility, HasSystemColumns: scanContainsSystemColumns(&colCfg), - NeededColumns: colCfg.wantedColumnsOrdinals, } if vc := getInvertedColumn(colCfg.invertedColumn, cols); vc != nil { trSpec.InvertedColumn = vc.ColumnDesc() diff --git a/pkg/sql/execinfra/version.go b/pkg/sql/execinfra/version.go index da472445c035..774a182bf970 100644 --- a/pkg/sql/execinfra/version.go +++ b/pkg/sql/execinfra/version.go @@ -39,7 +39,7 @@ import "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" // // ATTENTION: When updating these fields, add a brief description of what // changed to the version history below. -const Version execinfrapb.DistSQLVersion = 53 +const Version execinfrapb.DistSQLVersion = 54 // MinAcceptedVersion is the oldest version that the server is compatible with. // A server will not accept flows with older versions. @@ -51,6 +51,13 @@ const MinAcceptedVersion execinfrapb.DistSQLVersion = 52 Please add new entries at the top. +- Version: 54 (MinAcceptedVersion: 52) + - Field NeededColumns has been removed from the TableReaderSpec. It was being + used for the setup of the vectorized ColBatchScans, but now the + PostProcessSpec is examined instead. This means that older gateways still + produce specs that newer remote nodes understand, thus there is no bump in + the MinAcceptedVersion. + - Version: 53 (MinAcceptedVersion: 52) - FINAL_STDDEV_POP and FINAL_VAR_POP aggregate functions were introduced to support local and final aggregation of the builtin function STDDEV_POP. It diff --git a/pkg/sql/execinfrapb/processors_sql.proto b/pkg/sql/execinfrapb/processors_sql.proto index 38202d666f1b..5c3042cfac6a 100644 --- a/pkg/sql/execinfrapb/processors_sql.proto +++ b/pkg/sql/execinfrapb/processors_sql.proto @@ -57,9 +57,8 @@ enum ScanVisibility { // columns of the rows that pass a filter expression. // // The "internal columns" of a TableReader (see ProcessorSpec) are all the -// columns of the table. Internally, only the values for the columns specified -// by needed_columns are to be populated. If is_check is set, the TableReader -// will run additional data checking procedures and the "internal columns" are: +// columns of the table. If is_check is set, the TableReader will run additional +// data checking procedures and the "internal columns" are: // - Error type (string). // - Primary key as a string, if it was obtainable. // - JSON of all decoded column values. @@ -147,10 +146,7 @@ message TableReaderSpec { // system columns in its output. optional bool has_system_columns = 14 [(gogoproto.nullable) = false]; - // Indicates the ordinals of the columns values for which are needed by the - // post-processing stage and, therefore, are to be populated. It is ignored - // if is_check is true. - repeated uint32 needed_columns = 15; + reserved 15; // Indicates an inverted column which may have a different type than the // column stored in the table descriptor. For example, the inverted column in diff --git a/pkg/sql/flowinfra/cluster_test.go b/pkg/sql/flowinfra/cluster_test.go index 236ddeafe17c..889b9b807db4 100644 --- a/pkg/sql/flowinfra/cluster_test.go +++ b/pkg/sql/flowinfra/cluster_test.go @@ -104,24 +104,21 @@ func TestClusterFlow(t *testing.T) { leafInputState := txn.GetLeafTxnInputState(ctx) tr1 := execinfrapb.TableReaderSpec{ - Table: *desc.TableDesc(), - IndexIdx: 1, - Spans: []roachpb.Span{makeIndexSpan(0, 8)}, - NeededColumns: []uint32{0, 1}, + Table: *desc.TableDesc(), + IndexIdx: 1, + Spans: []roachpb.Span{makeIndexSpan(0, 8)}, } tr2 := execinfrapb.TableReaderSpec{ - Table: *desc.TableDesc(), - IndexIdx: 1, - Spans: []roachpb.Span{makeIndexSpan(8, 12)}, - NeededColumns: []uint32{0, 1}, + Table: *desc.TableDesc(), + IndexIdx: 1, + Spans: []roachpb.Span{makeIndexSpan(8, 12)}, } tr3 := execinfrapb.TableReaderSpec{ - Table: *desc.TableDesc(), - IndexIdx: 1, - Spans: []roachpb.Span{makeIndexSpan(12, 100)}, - NeededColumns: []uint32{0, 1}, + Table: *desc.TableDesc(), + IndexIdx: 1, + Spans: []roachpb.Span{makeIndexSpan(12, 100)}, } fid := execinfrapb.FlowID{UUID: uuid.MakeV4()} diff --git a/pkg/sql/flowinfra/server_test.go b/pkg/sql/flowinfra/server_test.go index be67f7e9af29..46acac439ebf 100644 --- a/pkg/sql/flowinfra/server_test.go +++ b/pkg/sql/flowinfra/server_test.go @@ -59,11 +59,10 @@ func TestServer(t *testing.T) { td := catalogkv.TestingGetTableDescriptor(kvDB, keys.SystemSQLCodec, "test", "t") ts := execinfrapb.TableReaderSpec{ - Table: *td.TableDesc(), - IndexIdx: 0, - Reverse: false, - Spans: []roachpb.Span{td.PrimaryIndexSpan(keys.SystemSQLCodec)}, - NeededColumns: []uint32{0, 1}, + Table: *td.TableDesc(), + IndexIdx: 0, + Reverse: false, + Spans: []roachpb.Span{td.PrimaryIndexSpan(keys.SystemSQLCodec)}, } post := execinfrapb.PostProcessSpec{ Projection: true, diff --git a/pkg/sql/opt/exec/execbuilder/testdata/aggregate b/pkg/sql/opt/exec/execbuilder/testdata/aggregate index 028d2f65b536..755c141489ee 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/aggregate +++ b/pkg/sql/opt/exec/execbuilder/testdata/aggregate @@ -727,7 +727,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /xyz/zyx/3.0/2/1 -> NULL +fetched: /xyz/zyx/?/?/1 -> NULL output row: [1] query T diff --git a/pkg/sql/opt/exec/execbuilder/testdata/ddl b/pkg/sql/opt/exec/execbuilder/testdata/ddl index 8e36c79c155e..86753e91474f 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/ddl +++ b/pkg/sql/opt/exec/execbuilder/testdata/ddl @@ -213,8 +213,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/b_desc/2/2 -> NULL -fetched: /t/b_desc/1/1 -> NULL +fetched: /t/b_desc/?/2 -> NULL +fetched: /t/b_desc/?/1 -> NULL fetched: /t/t_pkey/1/b/c -> /1/1 fetched: /t/t_pkey/2/b/c -> /2/2 output row: [1 1 1] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select_index b/pkg/sql/opt/exec/execbuilder/testdata/select_index index 4a64057d307d..886850993bf3 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select_index +++ b/pkg/sql/opt/exec/execbuilder/testdata/select_index @@ -1318,7 +1318,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /noncover/b/2/1 -> NULL +fetched: /noncover/b/?/1 -> NULL fetched: /noncover/noncover_pkey/1 -> NULL fetched: /noncover/noncover_pkey/1/b -> 2 fetched: /noncover/noncover_pkey/1/c -> 3 @@ -1355,7 +1355,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /noncover/c/7 -> /5 +fetched: /noncover/c/? -> /5 fetched: /noncover/noncover_pkey/5 -> NULL fetched: /noncover/noncover_pkey/5/b -> 6 fetched: /noncover/noncover_pkey/5/c -> 7 @@ -1635,8 +1635,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/bc/2/1/4 -> NULL -fetched: /t2/bc/2/3/6 -> NULL +fetched: /t2/bc/?/?/4 -> NULL +fetched: /t2/bc/?/?/6 -> NULL fetched: /t2/t2_pkey/4 -> NULL fetched: /t2/t2_pkey/4/b -> 2 fetched: /t2/t2_pkey/4/c -> 1 @@ -1657,8 +1657,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/bc/2/1/4 -> NULL -fetched: /t2/bc/2/3/6 -> NULL +fetched: /t2/bc/?/?/4 -> NULL +fetched: /t2/bc/?/?/6 -> NULL fetched: /t2/t2_pkey/4 -> NULL fetched: /t2/t2_pkey/4/b -> 2 fetched: /t2/t2_pkey/4/c -> 1 @@ -1806,8 +1806,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t4/t4_pkey/10/20 -> NULL -fetched: /t4/t4_pkey/10/20/c -> 30 +fetched: /t4/t4_pkey/?/? -> NULL +fetched: /t4/t4_pkey/?/?/c -> 30 output row: [30] # Point lookup on d does not touch the c or e families. @@ -1830,8 +1830,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t4/t4_pkey/10/20 -> NULL -fetched: /t4/t4_pkey/10/20/d -> 40 +fetched: /t4/t4_pkey/?/? -> NULL +fetched: /t4/t4_pkey/?/?/d -> 40 output row: [40] # Point lookup on both d and e uses a single span for the two adjacent column diff --git a/pkg/sql/physicalplan/aggregator_funcs_test.go b/pkg/sql/physicalplan/aggregator_funcs_test.go index 36683920d54d..a2534499c930 100644 --- a/pkg/sql/physicalplan/aggregator_funcs_test.go +++ b/pkg/sql/physicalplan/aggregator_funcs_test.go @@ -127,9 +127,8 @@ func checkDistAggregationInfo( makeTableReader := func(startPK, endPK int, streamID int) execinfrapb.ProcessorSpec { tr := execinfrapb.TableReaderSpec{ - Table: *tableDesc.TableDesc(), - Spans: make([]roachpb.Span, 1), - NeededColumns: []uint32{uint32(colIdx)}, + Table: *tableDesc.TableDesc(), + Spans: make([]roachpb.Span, 1), } var err error From 58609b8d83bb57b4bd4256aca9096515ff682883 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Fri, 7 Jan 2022 10:30:06 -0800 Subject: [PATCH 5/5] sql: log undecoded values as in tracing Previously, if the value part of a key-value pair wasn't needed, we would log it as `NULL`. However, that can be confusing whether an actual `NULL` value was decoded or not. This commit replaces the undecoded values with `` reducing the confusion (given that the likelihood of the value actually being equal to `` is negligible). Release note: None --- .../logic_test/regional_by_row_query_behavior | 24 +-- pkg/sql/colfetcher/cfetcher.go | 2 +- .../opt/exec/execbuilder/testdata/aggregate | 8 +- pkg/sql/opt/exec/execbuilder/testdata/ddl | 12 +- pkg/sql/opt/exec/execbuilder/testdata/insert | 78 +++++----- pkg/sql/opt/exec/execbuilder/testdata/orderby | 16 +- ...ndary_index_column_families_nonmetamorphic | 10 +- pkg/sql/opt/exec/execbuilder/testdata/select | 10 +- .../exec/execbuilder/testdata/select_index | 140 +++++++++--------- pkg/sql/opt/exec/execbuilder/testdata/update | 18 +-- .../testdata/update_nonmetamorphic | 6 +- pkg/sql/opt/exec/execbuilder/testdata/window | 12 +- pkg/sql/row/fetcher.go | 4 +- pkg/sql/schema_changer_test.go | 2 +- 14 files changed, 171 insertions(+), 171 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior index 593dfda9e84a..93a1c77ba8ac 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior +++ b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior @@ -618,7 +618,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> # Semi join with locality optimized search disabled. query T @@ -648,7 +648,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> output row: [10 10] # Inner join with locality optimized search disabled. @@ -679,7 +679,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> output row: [10 10 10] # Left join with locality optimized search disabled. @@ -710,7 +710,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0, /Table/62/1/"\x80"/10/0, /Table/62/1/"\xc0"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0, /Table/61/1/"\x80"/10/0, /Table/61/1/"\xc0"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> output row: [10 10 10] statement ok @@ -777,7 +777,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> statement ok SET tracing = on,kv,results; SELECT * FROM child WHERE NOT EXISTS (SELECT * FROM parent WHERE p_id = c_p_id) AND c_id = 20; SET tracing = off @@ -795,7 +795,7 @@ Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> # Semi join with locality optimized search enabled. query T @@ -853,7 +853,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> output row: [10 10] statement ok @@ -872,7 +872,7 @@ Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/?/? -> NULL +fetched: /parent/parent_pkey/?/? -> output row: [20 20] # Inner join with locality optimized search enabled. @@ -931,7 +931,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> output row: [10 10 10] statement ok @@ -950,7 +950,7 @@ Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL +fetched: /parent/parent_pkey/'ca-central-1'/20 -> output row: [20 20 20] # Left join with locality optimized search enabled. @@ -1009,7 +1009,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY Scan /Table/62/1/"@"/10/0 fetched: /child/child_pkey/?/10/c_p_id -> /10 Scan /Table/61/1/"@"/10/0 -fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> NULL +fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> output row: [10 10 10] statement ok @@ -1028,7 +1028,7 @@ Scan /Table/62/1/"\x80"/20/0, /Table/62/1/"\xc0"/20/0 fetched: /child/child_pkey/?/20/c_p_id -> /20 Scan /Table/61/1/"@"/20/0 Scan /Table/61/1/"\x80"/20/0, /Table/61/1/"\xc0"/20/0 -fetched: /parent/parent_pkey/'ca-central-1'/20 -> NULL +fetched: /parent/parent_pkey/'ca-central-1'/20 -> output row: [20 20 20] query T diff --git a/pkg/sql/colfetcher/cfetcher.go b/pkg/sql/colfetcher/cfetcher.go index d8a7ed9f7953..05a0898c7a88 100644 --- a/pkg/sql/colfetcher/cfetcher.go +++ b/pkg/sql/colfetcher/cfetcher.go @@ -1176,7 +1176,7 @@ func (rf *cFetcher) processValue(ctx context.Context, familyID descpb.FamilyID) } if rf.traceKV && prettyValue == "" { - prettyValue = tree.DNull.String() + prettyValue = "" } return nil diff --git a/pkg/sql/opt/exec/execbuilder/testdata/aggregate b/pkg/sql/opt/exec/execbuilder/testdata/aggregate index 755c141489ee..c71fc86a7baa 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/aggregate +++ b/pkg/sql/opt/exec/execbuilder/testdata/aggregate @@ -727,7 +727,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /xyz/zyx/?/?/1 -> NULL +fetched: /xyz/zyx/?/?/1 -> output row: [1] query T @@ -1082,13 +1082,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /xyz/xyz_pkey/1 -> NULL +fetched: /xyz/xyz_pkey/1 -> fetched: /xyz/xyz_pkey/1/y -> 2 fetched: /xyz/xyz_pkey/1/z -> 3.0 -fetched: /xyz/xyz_pkey/4 -> NULL +fetched: /xyz/xyz_pkey/4 -> fetched: /xyz/xyz_pkey/4/y -> 5 fetched: /xyz/xyz_pkey/4/z -> 6.0 -fetched: /xyz/xyz_pkey/7 -> NULL +fetched: /xyz/xyz_pkey/7 -> fetched: /xyz/xyz_pkey/7/z -> 8.0 output row: [9 4.5 6.33333333333333] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/ddl b/pkg/sql/opt/exec/execbuilder/testdata/ddl index 86753e91474f..10842170d161 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/ddl +++ b/pkg/sql/opt/exec/execbuilder/testdata/ddl @@ -137,7 +137,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1 -> NULL +fetched: /t/t_pkey/1 -> fetched: /t/t_pkey/1/b -> 1 output row: [1 1] @@ -163,7 +163,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/foo/1/1 -> NULL +fetched: /t/foo/1/1 -> output row: [1 1] statement ok @@ -177,8 +177,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/foo/1/1 -> NULL -fetched: /t/foo/1/2 -> NULL +fetched: /t/foo/1/1 -> +fetched: /t/foo/1/2 -> output row: [1 1] output row: [2 1] @@ -213,8 +213,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/b_desc/?/2 -> NULL -fetched: /t/b_desc/?/1 -> NULL +fetched: /t/b_desc/?/2 -> +fetched: /t/b_desc/?/1 -> fetched: /t/t_pkey/1/b/c -> /1/1 fetched: /t/t_pkey/2/b/c -> /2/2 output row: [1 1 1] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/insert b/pkg/sql/opt/exec/execbuilder/testdata/insert index e6a31b806566..4dccd1721921 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/insert +++ b/pkg/sql/opt/exec/execbuilder/testdata/insert @@ -31,19 +31,19 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv/kv_pkey/'A' -> NULL -fetched: /kv/kv_pkey/'a' -> NULL +fetched: /kv/kv_pkey/'A' -> +fetched: /kv/kv_pkey/'a' -> fetched: /kv/kv_pkey/'a'/v -> 'b' -fetched: /kv/kv_pkey/'c' -> NULL +fetched: /kv/kv_pkey/'c' -> fetched: /kv/kv_pkey/'c'/v -> 'd' -fetched: /kv/kv_pkey/'e' -> NULL +fetched: /kv/kv_pkey/'e' -> fetched: /kv/kv_pkey/'e'/v -> 'f' -fetched: /kv/kv_pkey/'g' -> NULL +fetched: /kv/kv_pkey/'g' -> fetched: /kv/kv_pkey/'g'/v -> '' -fetched: /kv/kv_pkey/'nil1' -> NULL -fetched: /kv/kv_pkey/'nil2' -> NULL -fetched: /kv/kv_pkey/'nil3' -> NULL -fetched: /kv/kv_pkey/'nil4' -> NULL +fetched: /kv/kv_pkey/'nil1' -> +fetched: /kv/kv_pkey/'nil2' -> +fetched: /kv/kv_pkey/'nil3' -> +fetched: /kv/kv_pkey/'nil4' -> output row: ['A' NULL] output row: ['a' 'b'] output row: ['c' 'd'] @@ -92,19 +92,19 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv/kv_pkey/'A' -> NULL -fetched: /kv/kv_pkey/'a' -> NULL +fetched: /kv/kv_pkey/'A' -> +fetched: /kv/kv_pkey/'a' -> fetched: /kv/kv_pkey/'a'/v -> 'b' -fetched: /kv/kv_pkey/'c' -> NULL +fetched: /kv/kv_pkey/'c' -> fetched: /kv/kv_pkey/'c'/v -> 'd' -fetched: /kv/kv_pkey/'e' -> NULL +fetched: /kv/kv_pkey/'e' -> fetched: /kv/kv_pkey/'e'/v -> 'f' -fetched: /kv/kv_pkey/'g' -> NULL +fetched: /kv/kv_pkey/'g' -> fetched: /kv/kv_pkey/'g'/v -> '' -fetched: /kv/kv_pkey/'nil1' -> NULL -fetched: /kv/kv_pkey/'nil2' -> NULL -fetched: /kv/kv_pkey/'nil3' -> NULL -fetched: /kv/kv_pkey/'nil4' -> NULL +fetched: /kv/kv_pkey/'nil1' -> +fetched: /kv/kv_pkey/'nil2' -> +fetched: /kv/kv_pkey/'nil3' -> +fetched: /kv/kv_pkey/'nil4' -> output row: ['A' NULL] output row: ['a' 'b'] output row: ['c' 'd'] @@ -153,21 +153,21 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv/kv_pkey/'A' -> NULL -fetched: /kv/kv_pkey/'a' -> NULL +fetched: /kv/kv_pkey/'A' -> +fetched: /kv/kv_pkey/'a' -> fetched: /kv/kv_pkey/'a'/v -> 'b' -fetched: /kv/kv_pkey/'c' -> NULL +fetched: /kv/kv_pkey/'c' -> fetched: /kv/kv_pkey/'c'/v -> 'd' -fetched: /kv/kv_pkey/'e' -> NULL +fetched: /kv/kv_pkey/'e' -> fetched: /kv/kv_pkey/'e'/v -> 'f' -fetched: /kv/kv_pkey/'f' -> NULL +fetched: /kv/kv_pkey/'f' -> fetched: /kv/kv_pkey/'f'/v -> 'g' -fetched: /kv/kv_pkey/'g' -> NULL +fetched: /kv/kv_pkey/'g' -> fetched: /kv/kv_pkey/'g'/v -> '' -fetched: /kv/kv_pkey/'nil1' -> NULL -fetched: /kv/kv_pkey/'nil2' -> NULL -fetched: /kv/kv_pkey/'nil3' -> NULL -fetched: /kv/kv_pkey/'nil4' -> NULL +fetched: /kv/kv_pkey/'nil1' -> +fetched: /kv/kv_pkey/'nil2' -> +fetched: /kv/kv_pkey/'nil3' -> +fetched: /kv/kv_pkey/'nil4' -> output row: ['A' NULL] output row: ['a' 'b'] output row: ['c' 'd'] @@ -219,21 +219,21 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv/kv_pkey/'A' -> NULL -fetched: /kv/kv_pkey/'a' -> NULL +fetched: /kv/kv_pkey/'A' -> +fetched: /kv/kv_pkey/'a' -> fetched: /kv/kv_pkey/'a'/v -> 'b' -fetched: /kv/kv_pkey/'c' -> NULL +fetched: /kv/kv_pkey/'c' -> fetched: /kv/kv_pkey/'c'/v -> 'd' -fetched: /kv/kv_pkey/'e' -> NULL +fetched: /kv/kv_pkey/'e' -> fetched: /kv/kv_pkey/'e'/v -> 'f' -fetched: /kv/kv_pkey/'f' -> NULL +fetched: /kv/kv_pkey/'f' -> fetched: /kv/kv_pkey/'f'/v -> 'g' -fetched: /kv/kv_pkey/'g' -> NULL +fetched: /kv/kv_pkey/'g' -> fetched: /kv/kv_pkey/'g'/v -> '' -fetched: /kv/kv_pkey/'nil1' -> NULL -fetched: /kv/kv_pkey/'nil2' -> NULL -fetched: /kv/kv_pkey/'nil3' -> NULL -fetched: /kv/kv_pkey/'nil4' -> NULL +fetched: /kv/kv_pkey/'nil1' -> +fetched: /kv/kv_pkey/'nil2' -> +fetched: /kv/kv_pkey/'nil3' -> +fetched: /kv/kv_pkey/'nil4' -> output row: ['A' NULL] output row: ['a' 'b'] output row: ['c' 'd'] @@ -292,7 +292,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv5/a/NULL/'a' -> NULL +fetched: /kv5/a/NULL/'a' -> output row: ['a' NULL] statement ok diff --git a/pkg/sql/opt/exec/execbuilder/testdata/orderby b/pkg/sql/opt/exec/execbuilder/testdata/orderby index 2f746f3e6c1e..d6efd042a732 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/orderby +++ b/pkg/sql/opt/exec/execbuilder/testdata/orderby @@ -302,9 +302,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/abc_pkey/1/2/3 -> NULL +fetched: /abc/abc_pkey/1/2/3 -> fetched: /abc/abc_pkey/1/2/3/d -> 'one' -fetched: /abc/abc_pkey/4/5/6 -> NULL +fetched: /abc/abc_pkey/4/5/6 -> fetched: /abc/abc_pkey/4/5/6/d -> 'Two' output row: [1 2 3 'one'] output row: [4 5 6 'Two'] @@ -317,8 +317,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/ba/2/1/? -> NULL -fetched: /abc/ba/5/4/? -> NULL +fetched: /abc/ba/2/1/? -> +fetched: /abc/ba/5/4/? -> output row: [1 2] output row: [4 5] @@ -490,10 +490,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /abc/abc_pkey/4/?/? -> NULL -fetched: /abc/abc_pkey/4/?/? -> NULL -fetched: /abc/abc_pkey/1/?/? -> NULL -fetched: /abc/abc_pkey/1/?/? -> NULL +fetched: /abc/abc_pkey/4/?/? -> +fetched: /abc/abc_pkey/4/?/? -> +fetched: /abc/abc_pkey/1/?/? -> +fetched: /abc/abc_pkey/1/?/? -> output row: [4] output row: [1] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic index b1757917cd17..0b444422d03f 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic +++ b/pkg/sql/opt/exec/execbuilder/testdata/secondary_index_column_families_nonmetamorphic @@ -59,7 +59,7 @@ query T SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched: /t1/nonuniqueidx/%' ---- -fetched: /t1/nonuniqueidx/1/? -> NULL +fetched: /t1/nonuniqueidx/1/? -> query I SET TRACING=on,kv,results; @@ -85,7 +85,7 @@ query T SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched: /t1/nonuniqueidxstoring/%' ---- -fetched: /t1/nonuniqueidxstoring/1/1 -> NULL +fetched: /t1/nonuniqueidxstoring/1/1 -> fetched: /t1/nonuniqueidxstoring/1/1/z -> /1 fetched: /t1/nonuniqueidxstoring/1/1/a/b -> /1/1 @@ -319,11 +319,11 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE message LIKE 'fetched%' ORDER BY message ---- -fetched: /t/i/2/1 -> NULL +fetched: /t/i/2/1 -> fetched: /t/i/2/1/w -> /3 -fetched: /t/i/5/4 -> NULL +fetched: /t/i/5/4 -> fetched: /t/i/5/4/z -> /6 -fetched: /t/i/9/8 -> NULL +fetched: /t/i/9/8 -> statement ok DROP TABLE IF EXISTS t; diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select b/pkg/sql/opt/exec/execbuilder/testdata/select index 8c25a35d8403..0d9da29764aa 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select +++ b/pkg/sql/opt/exec/execbuilder/testdata/select @@ -609,8 +609,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/b_idx/NULL/2 -> NULL -fetched: /t/b_idx/NULL/3 -> NULL +fetched: /t/b_idx/NULL/2 -> +fetched: /t/b_idx/NULL/3 -> fetched: /t/b_idx/2/1/c/d -> /3/4 output row: [2 NULL NULL NULL] output row: [3 NULL NULL NULL] @@ -826,7 +826,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /dt/dt_pkey/'2015-08-25 04:45:45.53453' -> NULL +fetched: /dt/dt_pkey/'2015-08-25 04:45:45.53453' -> fetched: /dt/dt_pkey/'2015-08-25 04:45:45.53453'/b -> '2015-08-25' fetched: /dt/dt_pkey/'2015-08-25 04:45:45.53453'/c -> '02:45:02.234' output row: ['2015-08-25 04:45:45.53453' '2015-08-25' '02:45:02.234'] @@ -947,8 +947,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /c/b_idx/NULL/2 -> NULL -fetched: /c/b_idx/NULL/3 -> NULL +fetched: /c/b_idx/NULL/2 -> +fetched: /c/b_idx/NULL/3 -> fetched: /c/b_idx/0.4/1/b -> /0.40 output row: [2 NULL] output row: [3 NULL] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/select_index b/pkg/sql/opt/exec/execbuilder/testdata/select_index index 886850993bf3..7764cfaa8626 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/select_index +++ b/pkg/sql/opt/exec/execbuilder/testdata/select_index @@ -29,7 +29,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/2/'two' -> NULL +fetched: /t/t_pkey/2/'two' -> fetched: /t/t_pkey/2/'two'/c -> 22 fetched: /t/t_pkey/2/'two'/d -> 'bar' output row: [2 'two' 22 'bar'] @@ -42,10 +42,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'one' -> NULL +fetched: /t/t_pkey/1/'one' -> fetched: /t/t_pkey/1/'one'/c -> 11 fetched: /t/t_pkey/1/'one'/d -> 'foo' -fetched: /t/t_pkey/3/'three' -> NULL +fetched: /t/t_pkey/3/'three' -> fetched: /t/t_pkey/3/'three'/c -> 33 fetched: /t/t_pkey/3/'three'/d -> 'blah' output row: [1 'one' 11 'foo'] @@ -59,8 +59,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/dc/'bar'/22/2/'two' -> NULL -fetched: /t/dc/'foo'/11/1/'one' -> NULL +fetched: /t/dc/'bar'/22/2/'two' -> +fetched: /t/dc/'foo'/11/1/'one' -> output row: [2 'two' 22 'bar'] output row: [1 'one' 11 'foo'] @@ -72,8 +72,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/dc/'bar'/22/2/'two' -> NULL -fetched: /t/dc/'foo'/11/1/'one' -> NULL +fetched: /t/dc/'bar'/22/2/'two' -> +fetched: /t/dc/'foo'/11/1/'one' -> output row: [2 'two' 22 'bar'] output row: [1 'one' 11 'foo'] @@ -85,7 +85,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/dc/'foo'/11/1/'one' -> NULL +fetched: /t/dc/'foo'/11/1/'one' -> output row: [1 'one' 11 'foo'] statement ok @@ -96,7 +96,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'one' -> NULL +fetched: /t/t_pkey/1/'one' -> fetched: /t/t_pkey/1/'one'/c -> 11 fetched: /t/t_pkey/1/'one'/d -> 'foo' output row: [1 'one' 11 'foo'] @@ -109,10 +109,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'one' -> NULL +fetched: /t/t_pkey/1/'one' -> fetched: /t/t_pkey/1/'one'/c -> 11 fetched: /t/t_pkey/1/'one'/d -> 'foo' -fetched: /t/t_pkey/2/'two' -> NULL +fetched: /t/t_pkey/2/'two' -> fetched: /t/t_pkey/2/'two'/c -> 22 fetched: /t/t_pkey/2/'two'/d -> 'bar' output row: [1 'one' 11 'foo'] @@ -126,8 +126,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/bc/'three'/?/3 -> NULL -fetched: /t/bc/'two'/?/2 -> NULL +fetched: /t/bc/'three'/?/3 -> +fetched: /t/bc/'two'/?/2 -> output row: [3 'three'] output row: [2 'two'] @@ -139,7 +139,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/dc/'bar'/22/2/'two' -> NULL +fetched: /t/dc/'bar'/22/2/'two' -> output row: [2 'two' 22 'bar'] statement ok @@ -150,13 +150,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'one' -> NULL +fetched: /t/t_pkey/1/'one' -> fetched: /t/t_pkey/1/'one'/c -> 11 fetched: /t/t_pkey/1/'one'/d -> 'foo' -fetched: /t/t_pkey/2/'two' -> NULL +fetched: /t/t_pkey/2/'two' -> fetched: /t/t_pkey/2/'two'/c -> 22 fetched: /t/t_pkey/2/'two'/d -> 'bar' -fetched: /t/t_pkey/3/'three' -> NULL +fetched: /t/t_pkey/3/'three' -> fetched: /t/t_pkey/3/'three'/c -> 33 fetched: /t/t_pkey/3/'three'/d -> 'blah' output row: [2 'two' 22 'bar'] @@ -170,9 +170,9 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/a_desc/3/? -> NULL -fetched: /t/a_desc/2/? -> NULL -fetched: /t/a_desc/1/? -> NULL +fetched: /t/a_desc/3/? -> +fetched: /t/a_desc/2/? -> +fetched: /t/a_desc/1/? -> output row: [3] output row: [2] output row: [1] @@ -186,8 +186,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/a_desc/3/? -> NULL -fetched: /t/a_desc/2/? -> NULL +fetched: /t/a_desc/3/? -> +fetched: /t/a_desc/2/? -> output row: [3] output row: [2] @@ -249,7 +249,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'c' -> NULL +fetched: /t/t_pkey/1/'c' -> output row: [1 'c' NULL NULL] statement ok @@ -260,7 +260,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'c' -> NULL +fetched: /t/t_pkey/1/'c' -> output row: [1 'c' NULL NULL] statement ok @@ -288,7 +288,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/t_pkey/1/'b' -> NULL +fetched: /t/t_pkey/1/'b' -> output row: [1 'b' NULL NULL] statement ok @@ -312,7 +312,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/3/4 -> output row: [3 4] statement ok @@ -323,7 +323,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/3/4 -> output row: [3 4] statement ok @@ -334,8 +334,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL -fetched: /t/ab/5/6 -> NULL +fetched: /t/ab/3/4 -> +fetched: /t/ab/5/6 -> output row: [3 4] output row: [5 6] @@ -347,8 +347,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/1/2 -> NULL -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/1/2 -> +fetched: /t/ab/3/4 -> output row: [1 2] output row: [3 4] @@ -360,8 +360,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/1/2 -> NULL -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/1/2 -> +fetched: /t/ab/3/4 -> output row: [1 2] output row: [3 4] @@ -373,8 +373,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/1/2 -> NULL -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/1/2 -> +fetched: /t/ab/3/4 -> output row: [1 2] output row: [3 4] @@ -386,8 +386,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL -fetched: /t/ab/5/6 -> NULL +fetched: /t/ab/3/4 -> +fetched: /t/ab/5/6 -> output row: [3 4] output row: [5 6] @@ -399,8 +399,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL -fetched: /t/ab/5/6 -> NULL +fetched: /t/ab/3/4 -> +fetched: /t/ab/5/6 -> output row: [3 4] output row: [5 6] @@ -412,8 +412,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL -fetched: /t/ab/5/6 -> NULL +fetched: /t/ab/3/4 -> +fetched: /t/ab/5/6 -> output row: [3 4] output row: [5 6] @@ -425,8 +425,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/1/2 -> NULL -fetched: /t/ab/5/6 -> NULL +fetched: /t/ab/1/2 -> +fetched: /t/ab/5/6 -> output row: [1 2] output row: [5 6] @@ -438,7 +438,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t/ab/3/4 -> NULL +fetched: /t/ab/3/4 -> output row: [3 4] query T @@ -1318,8 +1318,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /noncover/b/?/1 -> NULL -fetched: /noncover/noncover_pkey/1 -> NULL +fetched: /noncover/b/?/1 -> +fetched: /noncover/noncover_pkey/1 -> fetched: /noncover/noncover_pkey/1/b -> 2 fetched: /noncover/noncover_pkey/1/c -> 3 fetched: /noncover/noncover_pkey/1/d -> 4 @@ -1356,7 +1356,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- fetched: /noncover/c/? -> /5 -fetched: /noncover/noncover_pkey/5 -> NULL +fetched: /noncover/noncover_pkey/5 -> fetched: /noncover/noncover_pkey/5/b -> 6 fetched: /noncover/noncover_pkey/5/c -> 7 fetched: /noncover/noncover_pkey/5/d -> 8 @@ -1599,10 +1599,10 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/bc/2/1/4 -> NULL -fetched: /t2/bc/2/2/5 -> NULL -fetched: /t2/bc/2/3/6 -> NULL -fetched: /t2/t2_pkey/5 -> NULL +fetched: /t2/bc/2/1/4 -> +fetched: /t2/bc/2/2/5 -> +fetched: /t2/bc/2/3/6 -> +fetched: /t2/t2_pkey/5 -> fetched: /t2/t2_pkey/5/b -> 2 fetched: /t2/t2_pkey/5/c -> 2 fetched: /t2/t2_pkey/5/s -> '22' @@ -1635,13 +1635,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/bc/?/?/4 -> NULL -fetched: /t2/bc/?/?/6 -> NULL -fetched: /t2/t2_pkey/4 -> NULL +fetched: /t2/bc/?/?/4 -> +fetched: /t2/bc/?/?/6 -> +fetched: /t2/t2_pkey/4 -> fetched: /t2/t2_pkey/4/b -> 2 fetched: /t2/t2_pkey/4/c -> 1 fetched: /t2/t2_pkey/4/s -> '21' -fetched: /t2/t2_pkey/6 -> NULL +fetched: /t2/t2_pkey/6 -> fetched: /t2/t2_pkey/6/b -> 2 fetched: /t2/t2_pkey/6/c -> 3 fetched: /t2/t2_pkey/6/s -> '23' @@ -1657,13 +1657,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/bc/?/?/4 -> NULL -fetched: /t2/bc/?/?/6 -> NULL -fetched: /t2/t2_pkey/4 -> NULL +fetched: /t2/bc/?/?/4 -> +fetched: /t2/bc/?/?/6 -> +fetched: /t2/t2_pkey/4 -> fetched: /t2/t2_pkey/4/b -> 2 fetched: /t2/t2_pkey/4/c -> 1 fetched: /t2/t2_pkey/4/s -> '21' -fetched: /t2/t2_pkey/6 -> NULL +fetched: /t2/t2_pkey/6 -> fetched: /t2/t2_pkey/6/b -> 2 fetched: /t2/t2_pkey/6/c -> 3 fetched: /t2/t2_pkey/6/s -> '23' @@ -1679,39 +1679,39 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t2/t2_pkey/1 -> NULL +fetched: /t2/t2_pkey/1 -> fetched: /t2/t2_pkey/1/b -> 1 fetched: /t2/t2_pkey/1/c -> 1 fetched: /t2/t2_pkey/1/s -> '11' -fetched: /t2/t2_pkey/2 -> NULL +fetched: /t2/t2_pkey/2 -> fetched: /t2/t2_pkey/2/b -> 1 fetched: /t2/t2_pkey/2/c -> 2 fetched: /t2/t2_pkey/2/s -> '12' -fetched: /t2/t2_pkey/3 -> NULL +fetched: /t2/t2_pkey/3 -> fetched: /t2/t2_pkey/3/b -> 1 fetched: /t2/t2_pkey/3/c -> 3 fetched: /t2/t2_pkey/3/s -> '13' -fetched: /t2/t2_pkey/4 -> NULL +fetched: /t2/t2_pkey/4 -> fetched: /t2/t2_pkey/4/b -> 2 fetched: /t2/t2_pkey/4/c -> 1 fetched: /t2/t2_pkey/4/s -> '21' -fetched: /t2/t2_pkey/5 -> NULL +fetched: /t2/t2_pkey/5 -> fetched: /t2/t2_pkey/5/b -> 2 fetched: /t2/t2_pkey/5/c -> 2 fetched: /t2/t2_pkey/5/s -> '22' -fetched: /t2/t2_pkey/6 -> NULL +fetched: /t2/t2_pkey/6 -> fetched: /t2/t2_pkey/6/b -> 2 fetched: /t2/t2_pkey/6/c -> 3 fetched: /t2/t2_pkey/6/s -> '23' -fetched: /t2/t2_pkey/7 -> NULL +fetched: /t2/t2_pkey/7 -> fetched: /t2/t2_pkey/7/b -> 3 fetched: /t2/t2_pkey/7/c -> 1 fetched: /t2/t2_pkey/7/s -> '31' -fetched: /t2/t2_pkey/8 -> NULL +fetched: /t2/t2_pkey/8 -> fetched: /t2/t2_pkey/8/b -> 3 fetched: /t2/t2_pkey/8/c -> 2 fetched: /t2/t2_pkey/8/s -> '32' -fetched: /t2/t2_pkey/9 -> NULL +fetched: /t2/t2_pkey/9 -> fetched: /t2/t2_pkey/9/b -> 3 fetched: /t2/t2_pkey/9/c -> 3 fetched: /t2/t2_pkey/9/s -> '33' @@ -1806,7 +1806,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t4/t4_pkey/?/? -> NULL +fetched: /t4/t4_pkey/?/? -> fetched: /t4/t4_pkey/?/?/c -> 30 output row: [30] @@ -1830,7 +1830,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /t4/t4_pkey/?/? -> NULL +fetched: /t4/t4_pkey/?/? -> fetched: /t4/t4_pkey/?/?/d -> 40 output row: [40] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/update b/pkg/sql/opt/exec/execbuilder/testdata/update index f837456c71bc..2dbc8332e4f4 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/update +++ b/pkg/sql/opt/exec/execbuilder/testdata/update @@ -20,13 +20,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv2/kv2_pkey/'a' -> NULL +fetched: /kv2/kv2_pkey/'a' -> fetched: /kv2/kv2_pkey/'a'/v -> 'b' -fetched: /kv2/kv2_pkey/'c' -> NULL +fetched: /kv2/kv2_pkey/'c' -> fetched: /kv2/kv2_pkey/'c'/v -> 'd' -fetched: /kv2/kv2_pkey/'e' -> NULL +fetched: /kv2/kv2_pkey/'e' -> fetched: /kv2/kv2_pkey/'e'/v -> 'f' -fetched: /kv2/kv2_pkey/'f' -> NULL +fetched: /kv2/kv2_pkey/'f' -> fetched: /kv2/kv2_pkey/'f'/v -> 'g' output row: ['a' 'b'] output row: ['c' 'd'] @@ -61,13 +61,13 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /kv2/kv2_pkey/'a' -> NULL +fetched: /kv2/kv2_pkey/'a' -> fetched: /kv2/kv2_pkey/'a'/v -> 'b' -fetched: /kv2/kv2_pkey/'c' -> NULL +fetched: /kv2/kv2_pkey/'c' -> fetched: /kv2/kv2_pkey/'c'/v -> 'd' -fetched: /kv2/kv2_pkey/'e' -> NULL +fetched: /kv2/kv2_pkey/'e' -> fetched: /kv2/kv2_pkey/'e'/v -> 'f' -fetched: /kv2/kv2_pkey/'f' -> NULL +fetched: /kv2/kv2_pkey/'f' -> fetched: /kv2/kv2_pkey/'f'/v -> 'g' output row: ['a' 'b'] output row: ['c' 'd'] @@ -301,7 +301,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY WHERE message LIKE 'fetched:%' OR message LIKE 'output row%' ORDER BY message LIKE 'fetched:%' DESC, ordinality ASC ---- -fetched: /pks/pks_pkey/2/2 -> NULL +fetched: /pks/pks_pkey/2/2 -> fetched: /pks/pks_pkey/2/2/v -> 3 output row: [2 2 3] diff --git a/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic b/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic index c7059feb1373..fa2ef182c9ca 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic +++ b/pkg/sql/opt/exec/execbuilder/testdata/update_nonmetamorphic @@ -44,8 +44,8 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE operation != 'dist sender send' ---- Scan /Table/56/{1-2} -fetched: /tu/tu_pkey/1 -> NULL -fetched: /tu/tu_pkey/1 -> NULL +fetched: /tu/tu_pkey/1 -> +fetched: /tu/tu_pkey/1 -> fetched: /tu/tu_pkey/1/c/d -> /3/4 Put /Table/56/1/1/2/1 -> /TUPLE/3:3:Int/4/1:4:Int/4 fast path completed @@ -59,7 +59,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WHERE operation != 'dist sender send' ---- Scan /Table/56/{1-2} -fetched: /tu/tu_pkey/1 -> NULL +fetched: /tu/tu_pkey/1 -> fetched: /tu/tu_pkey/1/b -> 2 fetched: /tu/tu_pkey/1/c/d -> /4/4 Del /Table/56/1/1/1/1 diff --git a/pkg/sql/opt/exec/execbuilder/testdata/window b/pkg/sql/opt/exec/execbuilder/testdata/window index 6b70745ecb0a..46fa5118e261 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/window +++ b/pkg/sql/opt/exec/execbuilder/testdata/window @@ -33,21 +33,21 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY ---- fetched: /kv/kv_pkey/1/v -> /2 fetched: /kv/kv_pkey/1/d -> 1 -fetched: /kv/kv_pkey/1 -> NULL +fetched: /kv/kv_pkey/1 -> fetched: /kv/kv_pkey/3/v -> /4 fetched: /kv/kv_pkey/3/d -> 8 -fetched: /kv/kv_pkey/3 -> NULL -fetched: /kv/kv_pkey/5 -> NULL +fetched: /kv/kv_pkey/3 -> +fetched: /kv/kv_pkey/5 -> fetched: /kv/kv_pkey/5/d -> -321 fetched: /kv/kv_pkey/6/v -> /2 fetched: /kv/kv_pkey/6/d -> 4.4 -fetched: /kv/kv_pkey/6 -> NULL +fetched: /kv/kv_pkey/6 -> fetched: /kv/kv_pkey/7/v -> /2 fetched: /kv/kv_pkey/7/d -> 7.9 -fetched: /kv/kv_pkey/7 -> NULL +fetched: /kv/kv_pkey/7 -> fetched: /kv/kv_pkey/8/v -> /4 fetched: /kv/kv_pkey/8/d -> 3 -fetched: /kv/kv_pkey/8 -> NULL +fetched: /kv/kv_pkey/8 -> output row: [5 NULL] output row: [1 3.4501207708330056852] output row: [6 3.4501207708330056852] diff --git a/pkg/sql/row/fetcher.go b/pkg/sql/row/fetcher.go index 0a34de20cc01..e3114a33ba69 100644 --- a/pkg/sql/row/fetcher.go +++ b/pkg/sql/row/fetcher.go @@ -869,7 +869,7 @@ func (rf *Fetcher) processKV( if table.neededCols.Empty() { // We don't need to decode any values. if rf.traceKV { - prettyValue = tree.DNull.String() + prettyValue = "" } return prettyKey, prettyValue, nil } @@ -977,7 +977,7 @@ func (rf *Fetcher) processKV( } if rf.traceKV && prettyValue == "" { - prettyValue = tree.DNull.String() + prettyValue = "" } return prettyKey, prettyValue, nil diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index 749df19a5300..09b6bb0a4d7d 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -3792,7 +3792,7 @@ CREATE TABLE d.t ( } // Ensure that the decoder sees the old encoding. for indexName, expExplainRow := range map[string]string{ - "i": "fetched: /t/i/1/11/2 -> NULL", + "i": "fetched: /t/i/1/11/2 -> ", "u": "fetched: /t/u/1 -> /11/2", } { t.Run("index scan", func(t *testing.T) {