Skip to content

Commit

Permalink
sql: add a default AOST option to CREATE STATISTICS
Browse files Browse the repository at this point in the history
Using CREATE STATISTICS without an AOST option results in a regular scan
which could contend with concurrent transactions. This commit adds a
default AOST option of -1us to the CREATE STATISTICS command to avoid
this.

Fixes: #72719

Release note (sql change): using the CREATE STATISTICS command without
the AS OF SYSTEM TIME option could contend with concurrent transactions
and cost performance. Running CREATE STATISTICS without specifying AS OF
SYSTEM TIME now uses a default of -1us.
  • Loading branch information
Uzair5162 committed May 22, 2024
1 parent 3a3c1d8 commit 805b682
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/distsql_event_log
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FROM system.eventlog
WHERE "eventType" = 'create_statistics' AND ("info"::JSONB ->> 'DescriptorID')::INT = 106
ORDER BY "timestamp", info
----
1 {"EventType": "create_statistics", "Statement": "CREATE STATISTICS s1 ON id FROM test.public.a", "TableName": "test.public.a", "Tag": "CREATE STATISTICS", "User": "root"}
1 {"EventType": "create_statistics", "Statement": "CREATE STATISTICS s1 ON id FROM test.public.a WITH OPTIONS AS OF SYSTEM TIME '-1us'", "TableName": "test.public.a", "Tag": "CREATE STATISTICS", "User": "root"}

statement ok
DROP TABLE a
Loading

0 comments on commit 805b682

Please sign in to comment.