Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: update tenant_span builtins for consistent output #104946

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/span_builtins
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ SELECT crdb_internal.tenant_span(2)

subtest end

subtest tenant_span_at_uint_boundary

query T
SELECT crdb_internal.pretty_key(crdb_internal.tenant_span(108)[2], 0)
----
/109

query T
SELECT crdb_internal.pretty_key(crdb_internal.tenant_span(109)[2], 0)
----
/110

subtest end

subtest table_span

query T
Expand Down
21 changes: 3 additions & 18 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5428,19 +5428,8 @@ DO NOT USE -- USE 'CREATE TENANT' INSTEAD`,
if err != nil {
return nil, err
}
start := keys.MakeTenantPrefix(roachpb.MustMakeTenantID(uint64(sTenID)))
end := start.PrefixEnd()

result := tree.NewDArray(types.Bytes)
if err := result.Append(tree.NewDBytes(tree.DBytes(start))); err != nil {
return nil, err
}

if err := result.Append(tree.NewDBytes(tree.DBytes(end))); err != nil {
return nil, err
}

return result, nil
codec := keys.MakeSQLCodec(roachpb.MustMakeTenantID(uint64(sTenID)))
return spanToDatum(codec.TenantSpan())
},
Info: "This function returns the span that contains the keys for the given tenant.",
Volatility: volatility.Immutable,
Expand All @@ -5457,11 +5446,7 @@ DO NOT USE -- USE 'CREATE TENANT' INSTEAD`,
if err != nil {
return nil, err
}
start := keys.MakeTenantPrefix(tid)
return spanToDatum(roachpb.Span{
Key: start,
EndKey: start.PrefixEnd(),
})
return spanToDatum(keys.MakeSQLCodec(tid).TenantSpan())
},
Info: "This function returns the span that contains the keys for the given tenant.",
Volatility: volatility.Immutable,
Expand Down