Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
74342: storage: short-circuit in recordIteratorStats if not recording r=nvanbenschoten a=nvanbenschoten

This commit adds a short-circuit fast-path in recordIteratorStats that
avoids a call to `tracing.Span.RecordStructured` when the tracing span
is not recording. This avoids a heap allocation in the common case where
tracing is not enabled.

```
name                      old time/op    new time/op    delta
KV/Scan/Native/rows=1-10    18.8µs ± 2%    18.5µs ± 3%  -1.14%  (p=0.003 n=20+19)
KV/Scan/SQL/rows=1-10       95.4µs ± 3%    95.7µs ± 5%    ~     (p=0.602 n=20+20)

name                      old alloc/op   new alloc/op   delta
KV/Scan/Native/rows=1-10    7.42kB ± 1%    7.35kB ± 1%  -1.01%  (p=0.000 n=20+20)
KV/Scan/SQL/rows=1-10       23.5kB ± 0%    23.4kB ± 0%  -0.31%  (p=0.000 n=19+20)

name                      old allocs/op  new allocs/op  delta
KV/Scan/Native/rows=1-10      58.0 ± 0%      57.0 ± 0%  -1.72%  (p=0.000 n=19+20)
KV/Scan/SQL/rows=1-10          279 ± 0%       278 ± 0%  -0.36%  (p=0.000 n=18+19)
```
----

This is part of a collection of assorted micro-optimizations:
- #74336
- #74337
- #74338
- #74339
- #74340
- #74341
- #74342
- #74343
- #74344
- #74345
- #74346
- #74347
- #74348

Combined, these changes have the following effect on end-to-end SQL query performance:
```
name                      old time/op    new time/op    delta
KV/Scan/SQL/rows=1-10       94.4µs ±10%    92.3µs ±11%   -2.20%  (p=0.000 n=93+93)
KV/Scan/SQL/rows=10-10       102µs ±10%      99µs ±10%   -2.16%  (p=0.000 n=94+94)
KV/Update/SQL/rows=10-10     378µs ±15%     370µs ±11%   -2.04%  (p=0.003 n=95+91)
KV/Insert/SQL/rows=1-10      133µs ±14%     132µs ±12%     ~     (p=0.738 n=95+93)
KV/Insert/SQL/rows=10-10     197µs ±14%     196µs ±13%     ~     (p=0.902 n=95+94)
KV/Update/SQL/rows=1-10      186µs ±14%     185µs ±14%     ~     (p=0.351 n=94+93)
KV/Delete/SQL/rows=1-10      132µs ±13%     132µs ±14%     ~     (p=0.473 n=94+94)
KV/Delete/SQL/rows=10-10     254µs ±16%     250µs ±16%     ~     (p=0.086 n=100+99)

name                      old alloc/op   new alloc/op   delta
KV/Scan/SQL/rows=1-10       20.1kB ± 0%    19.1kB ± 1%   -4.91%  (p=0.000 n=96+96)
KV/Scan/SQL/rows=10-10      21.7kB ± 0%    20.7kB ± 1%   -4.61%  (p=0.000 n=96+97)
KV/Delete/SQL/rows=10-10    64.0kB ± 3%    63.7kB ± 3%   -0.55%  (p=0.000 n=100+100)
KV/Update/SQL/rows=1-10     45.8kB ± 1%    45.5kB ± 1%   -0.55%  (p=0.000 n=97+98)
KV/Update/SQL/rows=10-10     105kB ± 1%     105kB ± 1%   -0.10%  (p=0.008 n=97+98)
KV/Delete/SQL/rows=1-10     40.8kB ± 0%    40.7kB ± 0%   -0.08%  (p=0.001 n=95+96)
KV/Insert/SQL/rows=1-10     37.4kB ± 1%    37.4kB ± 0%     ~     (p=0.698 n=97+96)
KV/Insert/SQL/rows=10-10    76.4kB ± 1%    76.4kB ± 0%     ~     (p=0.822 n=99+98)

name                      old allocs/op  new allocs/op  delta
KV/Scan/SQL/rows=1-10          245 ± 0%       217 ± 0%  -11.43%  (p=0.000 n=95+92)
KV/Scan/SQL/rows=10-10         280 ± 0%       252 ± 0%  -10.11%  (p=0.000 n=75+97)
KV/Delete/SQL/rows=10-10       478 ± 0%       459 ± 0%   -4.04%  (p=0.000 n=94+97)
KV/Delete/SQL/rows=1-10        297 ± 1%       287 ± 1%   -3.34%  (p=0.000 n=97+97)
KV/Update/SQL/rows=1-10        459 ± 0%       444 ± 0%   -3.27%  (p=0.000 n=97+97)
KV/Insert/SQL/rows=1-10        291 ± 0%       286 ± 0%   -1.72%  (p=0.000 n=82+86)
KV/Update/SQL/rows=10-10       763 ± 1%       750 ± 1%   -1.68%  (p=0.000 n=96+98)
KV/Insert/SQL/rows=10-10       489 ± 0%       484 ± 0%   -1.03%  (p=0.000 n=98+98)
```


83796: sql/stats: convert between histograms and quantile functions r=mgartner,rytaft,yuzefovich a=michae2

To predict histograms in statistics forecasts, we will use linear
regression over quantile functions. (Quantile functions are another
representation of histogram data, in a form more amenable to statistical
manipulation.)

This commit defines quantile functions and adds methods to convert
between histograms and quantile functions.

This code was originally part of #77070 but has been pulled out to
simplify that PR. A few changes have been made:
- Common code has been factored into closures.
- More checks have been added for positive values.
- In `makeQuantile` we now trim leading empty buckets as well as
  trailing empty buckets.
- The logic in `quantile.toHistogram` to steal from `NumRange` if
  `NumEq` is zero now checks that `NumRange` will still be >= 1.
- More tests have been added.

Assists: #79872

Release note: None

83827: asim: update range size split threshold, more keys r=kvoli a=kvoli

This patch updates the range size split threshold to 512mb by default.
Additionally it adds support for initializing a testing replica
distribution, where the ranges contain an equal span of the keyspace.

Release note: None

83891: sql: sql parser for `CREATE FUNCTION` statement r=chengxiong-ruan a=chengxiong-ruan

handles #83218

This commit added parser support for `CREATE FUNCTION` sql
statement. Scanner was extended so that it can recognize the
`BEGIN ATOMIC` context so that it doesnot return early when it
sees `;` charater which normally indicates the end of a
statement.

Release note (sql change): `CREATE FUNCTION` statement now
can be parsed by crdb, but an unimplemented error would be
thrown since the statement processing is not done yet.

83913: pkg/ui: Don't force tracez tags to uppercase. r=benbardin a=benbardin

Also, deprecate uses of db-console/.../Badge in favor of the identical version
in cluster-ui.

<img width="1476" alt="Screen Shot 2022-07-06 at 1 21 50 PM" src="https://user-images.githubusercontent.com/261508/177608120-e7360b9e-d2dd-4e50-8bfe-de97a0d61adf.png">

Release note: None

83929: pgwire: use better error for invalid Describe message r=ZhouXing19 a=rafiss

fixes #82785

Release note: None

84165: gc: fix NumKeysAffected counting more than collected r=erikgrinaker a=aliher1911

Previously if key is not collected after a GC batch is sent out
it would still be included as affected in GC stats.
Those stats are mostly used for logging and tests, the unfortunate
effect is that randomized test could fail.
This commit fixes the bug.

Release note: None

Fixes #84164

Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Michael Erickson <[email protected]>
Co-authored-by: Austen McClernon <[email protected]>
Co-authored-by: Chengxiong Ruan <[email protected]>
Co-authored-by: Ben Bardin <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
Co-authored-by: Oleg Afanasyev <[email protected]>
  • Loading branch information
8 people committed Jul 11, 2022
8 parents 10853d2 + 2904f89 + 4ad11bd + 28f5627 + ee5c080 + 4caddd4 + e96d23c + bf86973 commit bef1101
Show file tree
Hide file tree
Showing 51 changed files with 2,358 additions and 336 deletions.
7 changes: 7 additions & 0 deletions docs/generated/sql/bnf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ FILES = [
"create_database_stmt",
"create_ddl_stmt",
"create_extension_stmt",
"create_func_stmt",
"create_index_stmt",
"create_index_with_storage_param",
"create_inverted_index_stmt",
Expand Down Expand Up @@ -130,6 +131,9 @@ FILES = [
"insert_stmt",
"iso_level",
"joined_table",
"legacy_begin_stmt",
"legacy_end_stmt",
"legacy_transaction_stmt",
"like_table_option_list",
"limit_clause",
"move_cursor_stmt",
Expand Down Expand Up @@ -167,6 +171,8 @@ FILES = [
"resume_stmt",
"revoke_stmt",
"rollback_transaction",
"routine_body_stmt",
"routine_return_stmt",
"row_source_extension_stmt",
"savepoint_stmt",
"scrub_database_stmt",
Expand Down Expand Up @@ -230,6 +236,7 @@ FILES = [
"split_table_at",
"stmt",
"stmt_block",
"stmt_without_legacy_transaction",
"table_clause",
"table_constraint",
"table_ref",
Expand Down
18 changes: 0 additions & 18 deletions docs/generated/sql/bnf/begin_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
begin_stmt ::=
'BEGIN' 'TRANSACTION' 'PRIORITY' 'LOW' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'PRIORITY' 'NORMAL' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'PRIORITY' 'HIGH' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'READ' 'ONLY' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'READ' 'WRITE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION' 'NOT' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'TRANSACTION'
| 'BEGIN' 'PRIORITY' 'LOW' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'PRIORITY' 'NORMAL' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'PRIORITY' 'HIGH' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'READ' 'ONLY' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'READ' 'WRITE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN' 'NOT' 'DEFERRABLE' ( ( ( ',' | ) ( ( 'PRIORITY' ( 'LOW' | 'NORMAL' | 'HIGH' ) ) | ( 'READ' 'ONLY' | 'READ' 'WRITE' ) | ( 'AS' 'OF' 'SYSTEM' 'TIME' a_expr ) | ( 'DEFERRABLE' | 'NOT' 'DEFERRABLE' ) ) ) )*
| 'BEGIN'
2 changes: 0 additions & 2 deletions docs/generated/sql/bnf/commit_transaction.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
commit_stmt ::=
'COMMIT' 'TRANSACTION'
| 'COMMIT'
| 'END' 'TRANSACTION'
| 'END'
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/create_ddl_stmt.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ create_ddl_stmt ::=
| create_type_stmt
| create_view_stmt
| create_sequence_stmt
| create_func_stmt
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/create_func_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_func_stmt ::=
'CREATE' opt_or_replace 'FUNCTION' func_create_name '(' opt_func_arg_with_default_list ')' 'RETURNS' opt_return_set func_return_type opt_create_func_opt_list opt_routine_body
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/legacy_begin_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy_begin_stmt ::=
'BEGIN' opt_transaction begin_transaction
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/legacy_end_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
legacy_end_stmt ::=
'END' opt_transaction
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/legacy_transaction_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
legacy_transaction_stmt ::=
legacy_begin_stmt
| legacy_end_stmt
3 changes: 3 additions & 0 deletions docs/generated/sql/bnf/routine_body_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
routine_body_stmt ::=
stmt_without_legacy_transaction
| routine_return_stmt
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/routine_return_stmt.bnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
routine_return_stmt ::=
'RETURN' a_expr
23 changes: 2 additions & 21 deletions docs/generated/sql/bnf/stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
stmt ::=
'HELPTOKEN'
| preparable_stmt
| analyze_stmt
| copy_from_stmt
| comment_stmt
| execute_stmt
| deallocate_stmt
| discard_stmt
| grant_stmt
| prepare_stmt
| revoke_stmt
| savepoint_stmt
| reassign_owned_by_stmt
| drop_owned_by_stmt
| release_stmt
| refresh_stmt
| nonpreparable_set_stmt
| transaction_stmt
| close_cursor_stmt
| declare_cursor_stmt
| fetch_cursor_stmt
| move_cursor_stmt
| stmt_without_legacy_transaction
| legacy_transaction_stmt
Loading

0 comments on commit bef1101

Please sign in to comment.