Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
101825: sql: add crdb_internal.pretty_value r=Xiang-Gu,msbutler a=stevendanna

This composes nicely with crdb_internal.scan to allow inspection of table data and other command line tools like cockroach debug pebble.

Epic: none

Release note: None

102907: workload: remove initial prefix from bank workload payload r=herkolategan,srosenberg a=renatolabs

An `initial-` prefix is added to the payload column of the `bank` table when the workload is initialized. It was introduced about 6 years ago [1] and its purpose at the time is not clear. There are two main problems with it:

* the `initial-` prefix suggests the payload may be updated, but that actually never happens.
* as currently implemented, it assumes that the `payload-bytes` command line flag is at least `len([]byte("initial-"))`. Passing a lower value to that command line flag leads to a panic. This is an implicit assumption that should not exist.

This changes the row generation function so that `payload-bytes` bytes are randomly generated and inserted into the `payload` column, without the `initial-` prefix.

[1] d49d535

Epic: none

Release note: None

102961: sql: default sql.show_ranges_deprecated_behavior.enabled to true r=irfansharif a=irfansharif

We enabled range coalescing by default in 23.2 as part of #98820. Alongside that change, we want to flip the SHOW RANGES behavior to be compatible with coalesced ranges, which this commit does. See #93644 and the accompanying release notes.

Release note (backward-incompatible change): The pre-v23.1 output produced by SHOW RANGES, crdb_internal.ranges,
crdb_internal.ranges_no_leases was deprecated in 23.1, and is now replaced by default with output that's compatible with coalesced ranges (i.e. ranges that pack multiple tables/indexes/partitions into individual ranges). See the 23.1 release notes for SHOW RANGES for more details.

Co-authored-by: Steven Danna <[email protected]>
Co-authored-by: Renato Costa <[email protected]>
Co-authored-by: irfan sharif <[email protected]>
  • Loading branch information
4 people committed May 9, 2023
4 parents 03e4c91 + b4bfe1a + 90a9904 + 904b301 commit f614c52
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ sql.multiregion.drop_primary_region.enabled boolean true allows dropping the PRI
sql.notices.enabled boolean true enable notices in the server/client protocol being sent tenant-rw
sql.optimizer.uniqueness_checks_for_gen_random_uuid.enabled boolean false if enabled, uniqueness checks may be planned for mutations of UUID columns updated with gen_random_uuid(); otherwise, uniqueness is assumed due to near-zero collision probability tenant-rw
sql.schema.telemetry.recurrence string @weekly cron-tab recurrence for SQL schema telemetry job tenant-ro
sql.show_ranges_deprecated_behavior.enabled boolean true if set, SHOW RANGES and crdb_internal.ranges{_no_leases} behave with deprecated pre-v23.1 semantics. NB: the new SHOW RANGES interface has richer WITH options than pre-v23.1 SHOW RANGES. tenant-rw
sql.show_ranges_deprecated_behavior.enabled boolean false if set, SHOW RANGES and crdb_internal.ranges{_no_leases} behave with deprecated pre-v23.1 semantics. NB: the new SHOW RANGES interface has richer WITH options than pre-v23.1 SHOW RANGES. tenant-rw
sql.spatial.experimental_box2d_comparison_operators.enabled boolean false enables the use of certain experimental box2d comparison operators tenant-rw
sql.stats.activity.persisted_rows.max integer 200000 maximum number of rows of statement and transaction activity that will be persisted in the system tables tenant-rw
sql.stats.automatic_collection.enabled boolean true automatic statistics collection mode tenant-rw
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<tr><td><div id="setting-sql-notices-enabled" class="anchored"><code>sql.notices.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>enable notices in the server/client protocol being sent</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-optimizer-uniqueness-checks-for-gen-random-uuid-enabled" class="anchored"><code>sql.optimizer.uniqueness_checks_for_gen_random_uuid.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if enabled, uniqueness checks may be planned for mutations of UUID columns updated with gen_random_uuid(); otherwise, uniqueness is assumed due to near-zero collision probability</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-schema-telemetry-recurrence" class="anchored"><code>sql.schema.telemetry.recurrence</code></div></td><td>string</td><td><code>@weekly</code></td><td>cron-tab recurrence for SQL schema telemetry job</td><td>Serverless/Dedicated/Self-Hosted (read-only)</td></tr>
<tr><td><div id="setting-sql-show-ranges-deprecated-behavior-enabled" class="anchored"><code>sql.show_ranges_deprecated_behavior.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>if set, SHOW RANGES and crdb_internal.ranges{_no_leases} behave with deprecated pre-v23.1 semantics. NB: the new SHOW RANGES interface has richer WITH options than pre-v23.1 SHOW RANGES.</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-show-ranges-deprecated-behavior-enabled" class="anchored"><code>sql.show_ranges_deprecated_behavior.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if set, SHOW RANGES and crdb_internal.ranges{_no_leases} behave with deprecated pre-v23.1 semantics. NB: the new SHOW RANGES interface has richer WITH options than pre-v23.1 SHOW RANGES.</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-spatial-experimental-box2d-comparison-operators-enabled" class="anchored"><code>sql.spatial.experimental_box2d_comparison_operators.enabled</code></div></td><td>boolean</td><td><code>false</code></td><td>enables the use of certain experimental box2d comparison operators</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-stats-activity-persisted-rows-max" class="anchored"><code>sql.stats.activity.persisted_rows.max</code></div></td><td>integer</td><td><code>200000</code></td><td>maximum number of rows of statement and transaction activity that will be persisted in the system tables</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-stats-automatic-collection-enabled" class="anchored"><code>sql.stats.automatic_collection.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>automatic statistics collection mode</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,8 @@ active for the current transaction.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="crdb_internal.pretty_span"></a><code>crdb_internal.pretty_span(raw_key_start: <a href="bytes.html">bytes</a>, raw_key_end: <a href="bytes.html">bytes</a>, skip_fields: <a href="int.html">int</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>This function is used only by CockroachDB’s developers for testing purposes.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="crdb_internal.pretty_value"></a><code>crdb_internal.pretty_value(raw_value: <a href="bytes.html">bytes</a>) &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>This function is used only by CockroachDB’s developers for testing purposes.</p>
</span></td><td>Immutable</td></tr>
<tr><td><a name="crdb_internal.range_stats"></a><code>crdb_internal.range_stats(key: <a href="bytes.html">bytes</a>) &rarr; jsonb</code></td><td><span class="funcdesc"><p>This function is used to retrieve range statistics information as a JSON object.</p>
</span></td><td>Volatile</td></tr>
<tr><td><a name="crdb_internal.read_file"></a><code>crdb_internal.read_file(uri: <a href="string.html">string</a>) &rarr; <a href="bytes.html">bytes</a></code></td><td><span class="funcdesc"><p>Read the content of the file at the supplied external storage URI</p>
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/workloadccl/allccl/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestDeterministicInitialData(t *testing.T) {
// TODO(dan): We're starting to accumulate these various lists, bigInitialData
// is another. Consider moving them to be properties on the workload.Meta.
fingerprintGoldens := map[string]uint64{
`bank`: 0x7b4d519ed8bd07ce,
`bank`: 0xb9065bb21c3594a2,
`bulkingest`: 0xcf3e4028ac084aea,
`indexes`: 0xcbf29ce484222325,
`intro`: 0x81c6a8cfd9c3452a,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/deprecatedshowranges/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var ShowRangesDeprecatedBehaviorSetting = settings.RegisterBoolSetting(
"if set, SHOW RANGES and crdb_internal.ranges{_no_leases} behave with deprecated pre-v23.1 semantics."+
" NB: the new SHOW RANGES interface has richer WITH options "+
"than pre-v23.1 SHOW RANGES.",
true,
false,
).WithPublic()

const envVarName = "COCKROACH_FORCE_DEPRECATED_SHOW_RANGE_BEHAVIOR"
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -1332,3 +1332,10 @@ user root
skipif config local-mixed-22.2-23.1
statement ok
REVOKE SYSTEM MODIFYSQLCLUSTERSETTING FROM testuser

subtest pretty_value

query T
SELECT crdb_internal.pretty_value('\x170995790a3609616d7374657264616d1cc28f5c28f5c2400080000000000000261cbbbbbbbbbbbb4800800000000000000b161b32313030312053636f747420537175617265205375697465203337161b313537333120477265676f7279205669657773204170742e20373818cabca3c10b0018ea97a9c10b001504348a2260')
----
/TUPLE/3:3:Bytes/amsterdam/1:4:UUID/c28f5c28-f5c2-4000-8000-000000000026/1:5:UUID/bbbbbbbb-bbbb-4800-8000-00000000000b/1:6:Bytes/21001 Scott Square Suite 37/1:7:Bytes/15731 Gregory Views Apt. 78/1:8:Time/2018-12-15T03:04:05Z/1:9:Time/2018-12-15T16:04:05Z/1:10:Decimal/88.00
19 changes: 19 additions & 0 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5538,6 +5538,25 @@ DO NOT USE -- USE 'CREATE TENANT' INSTEAD`,
},
),

"crdb_internal.pretty_value": makeBuiltin(
tree.FunctionProperties{
Category: builtinconstants.CategorySystemInfo,
},
tree.Overload{
Types: tree.ParamTypes{
tree.ParamType{Name: "raw_value", Typ: types.Bytes},
},
ReturnType: tree.FixedReturnType(types.String),
Fn: func(_ context.Context, _ *eval.Context, args tree.Datums) (tree.Datum, error) {
var v roachpb.Value
v.RawBytes = []byte(tree.MustBeDBytes(args[0]))
return tree.NewDString(v.PrettyPrint()), nil
},
Info: "This function is used only by CockroachDB's developers for testing purposes.",
Volatility: volatility.Immutable,
},
),

// Return statistics about a range.
"crdb_internal.range_stats": makeBuiltin(
tree.FunctionProperties{
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/builtins/fixed_oids.go
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,7 @@ var builtinOidsArray = []string{
2407: `crdb_internal.tenant_span() -> bytes[]`,
2408: `crdb_internal.job_execution_details(job_id: int) -> jsonb`,
2409: `st_bdpolyfromtext(str: string, srid: int) -> geometry`,
2410: `crdb_internal.pretty_value(raw_value: bytes) -> string`,
}

var builtinOidsBySignature map[string]oid.Oid
Expand Down
4 changes: 1 addition & 3 deletions pkg/workload/bank/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ func (b *bank) Tables() []workload.Table {
for rowIdx := rowBegin; rowIdx < rowEnd; rowIdx++ {
var payload []byte
*a, payload = a.Alloc(b.payloadBytes, 0 /* extraCap */)
const initialPrefix = `initial-`
copy(payload[:len(initialPrefix)], []byte(initialPrefix))
randStringLetters(rng, payload[len(initialPrefix):])
randStringLetters(rng, payload)

rowOffset := rowIdx - rowBegin
idCol[rowOffset] = int64(rowIdx)
Expand Down
10 changes: 5 additions & 5 deletions pkg/workload/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func TestHandleCSV(t *testing.T) {
}{
{
`?rows=1`, `
0,0,initial-dTqnRurXztAPkykhZWvsCmeJkMwRNcJAvTlNbgUEYfagEQJaHmfPsquKZUBOGwpAjPtATpGXFJkrtQCEJODSlmQctvyh`,
0,0,dTqnRurXztAPkykhZWvsCmeJkMwRNcJAvTlNbgUEYfagEQJaHmfPsquKZUBOGwpAjPtATpGXFJkrtQCEJODSlmQctvyhWevfEafP`,
},
{
`?rows=5&row-start=1&row-end=3&batch-size=1`, `
1,0,initial-vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZT
2,0,initial-qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZz`,
1,0,vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZTLdqDkrhj
2,0,qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZzvGuJkQXu`,
},
}

Expand Down Expand Up @@ -123,8 +123,8 @@ func TestCSVRowsReader(t *testing.T) {
b, err := io.ReadAll(r)
require.NoError(t, err)
expected := `
1,0,initial-vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZT
2,0,initial-qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZz
1,0,vOpikzTTWxvMqnkpfEIVXgGyhZNDqvpVqpNnHawruAcIVltgbnIEIGmCDJcnkVkfVmAcutkMvRACFuUBPsZTemTDSfZTLdqDkrhj
2,0,qMvoPeRiOBXvdVQxhZUfdmehETKPXyBaVWxzMqwiStIkxfoDFygYxIDyXiaVEarcwMboFhBlCAapvKijKAyjEAhRBNZzvGuJkQXu
`
require.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(b)))
}
Expand Down

0 comments on commit f614c52

Please sign in to comment.