Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3349,6 +3349,10 @@ may increase either contention or retry errors, or both.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="current_user"></a><code>current_user() &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the current user. This function is provided for compatibility with PostgreSQL.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="information_schema.crdb_reset_index_usage_stats"></a><code>information_schema.crdb_reset_index_usage_stats() &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>This function is used to clear the collected index usage statistics.</p>
</span></td><td>Volatile</td></tr>
<tr><td><a name="information_schema.crdb_reset_sql_stats"></a><code>information_schema.crdb_reset_sql_stats() &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>This function is used to clear the collected SQL statistics.</p>
</span></td><td>Volatile</td></tr>
<tr><td><a name="session_user"></a><code>session_user() &rarr; <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns the session user. This function is provided for compatibility with PostgreSQL.</p>
</span></td><td>Stable</td></tr>
<tr><td><a name="to_regclass"></a><code>to_regclass(text: <a href="string.html">string</a>) &rarr; regtype</code></td><td><span class="funcdesc"><p>Translates a textual relation name to its OID</p>
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/builtins
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SELECT message FROM [SHOW TRACE FOR SESSION] WHERE message LIKE '%query cache%';
query cache hit

statement ok
SELECT crdb_internal.clear_query_plan_cache();
SELECT information_schema.crdb_clear_query_plan_cache();

statement ok
SET TRACING = "on", cluster;
Expand Down Expand Up @@ -201,7 +201,7 @@ SELECT message FROM [SHOW TRACE FOR SESSION] WHERE message LIKE '%reading statis
----

statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
SET TRACING = "on", cluster;
Expand Down
12 changes: 6 additions & 6 deletions pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_cascade
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ANALYZE great_grandparent;

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Only the scan in the main query is parallelized when we don't have stats on
# the descendant tables.
Expand All @@ -74,7 +74,7 @@ ANALYZE grandparent;

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Now we also should parallelize lookup join into the grandparent table.
query I
Expand All @@ -87,7 +87,7 @@ ANALYZE parent;

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Now we also should parallelize lookup join into the parent table.
query I
Expand All @@ -100,7 +100,7 @@ ANALYZE child;

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Finally, all three lookup joins as well as the scan in the main query should
# be parallelized.
Expand Down Expand Up @@ -306,7 +306,7 @@ ALTER TABLE grandparent INJECT STATISTICS '[

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

query I
SELECT count(*) FROM [EXPLAIN (VERBOSE) DELETE FROM great_grandparent WHERE i = 1] WHERE info LIKE '%parallel%';
Expand Down Expand Up @@ -351,7 +351,7 @@ ALTER TABLE grandparent INJECT STATISTICS '[

# Clear the stat cache so that the new statistic is guaranteed to be used.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

query I
SELECT count(*) FROM [EXPLAIN (VERBOSE) DELETE FROM great_grandparent WHERE i = 1] WHERE info LIKE '%parallel%';
Expand Down
6 changes: 3 additions & 3 deletions pkg/ccl/serverccl/statusccl/tenant_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ func testResetSQLStatsRPCForTenant(
t.Run(fmt.Sprintf("flushed=%t", flushed), func(t *testing.T) {
// Clears the SQL Stats at the end of each test via builtin.
defer func() {
testTenantConn.Exec(t, "SELECT crdb_internal.reset_sql_stats()")
controlCluster.TenantConn(serverccl.RandomServer).Exec(t, "SELECT crdb_internal.reset_sql_stats()")
testTenantConn.Exec(t, "SELECT information_schema.crdb_reset_sql_stats()")
controlCluster.TenantConn(serverccl.RandomServer).Exec(t, "SELECT information_schema.crdb_reset_sql_stats()")
}()

for _, stmt := range stmts {
Expand Down Expand Up @@ -704,7 +704,7 @@ func testResetIndexUsageStatsRPCForTenant(
resetFn: func(helper serverccl.TenantTestHelper) {
// Reset index usage stats using SQL shell built-in.
testingCluster := helper.TestCluster()
testingCluster.TenantConn(0).Exec(t, "SELECT crdb_internal.reset_index_usage_stats()")
testingCluster.TenantConn(0).Exec(t, "SELECT information_schema.crdb_reset_index_usage_stats()")
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions pkg/internal/sqlsmith/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,15 @@ var functions = func() *functionsMu {
"crdb_internal.create_join_token",
"crdb_internal.reset_multi_region_zone_configs_for_database",
"crdb_internal.reset_index_usage_stats",
"information_schema.crdb_reset_index_usage_stats",
"crdb_internal.start_replication_stream",
"crdb_internal.replication_stream_progress",
"crdb_internal.complete_replication_stream",
"crdb_internal.revalidate_unique_constraint",
"crdb_internal.request_statement_bundle",
"crdb_internal.set_compaction_concurrency",
"crdb_internal.reset_sql_stats",
"information_schema.crdb_reset_sql_stats",
} {
skip = skip || strings.Contains(def.Name, substr)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/server/application_api/sql_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,19 @@ func TestUnprivilegedUserResetIndexUsageStats(t *testing.T) {
)

require.Contains(t, err.Error(), "user non_admin_user does not have REPAIRCLUSTER system privilege")

// Test that information_schema.crdb_reset_index_usage_stats has the same behavior
_, err = ie.ExecEx(
ctx,
"test-reset-index-usage-stats-information-schema-as-non-admin-user",
nil, /* txn */
sessiondata.InternalExecutorOverride{
User: username.MakeSQLUsernameFromPreNormalizedString("non_admin_user"),
},
"SELECT information_schema.crdb_reset_index_usage_stats()",
)

require.Contains(t, err.Error(), "user non_admin_user does not have REPAIRCLUSTER system privilege")
}

// TestCombinedStatementUsesCorrectSourceTable tests that requests read from
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/canary_stats
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ statement ok
DEALLOCATE ALL;

statement ok
SELECT crdb_internal.clear_query_plan_cache();
SELECT information_schema.crdb_clear_query_plan_cache();

statement ok
SET TRACING = "on", cluster;
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/constrained_stats
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CREATE STATISTICS full_stat FROM products;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Test stats collections with WHERE expressions
statement ok
Expand Down Expand Up @@ -159,7 +159,7 @@ CREATE STATISTICS products_full FROM products;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS stat_discount ON discount_price FROM products WHERE discount_price > 30
Expand Down Expand Up @@ -222,7 +222,7 @@ CREATE STATISTICS fullstat FROM partial_indexes;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

# Filter implies the partial index predicate, so it can be used.
statement ok
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/distsql_crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ start_key end_key replicas lease_holder
…/1/9 <after:/Max> {5} 5


# As of #69273, crdb_internal.reset_sql_stats()'s behavior changes from in-memory
# As of #69273, reset_sql_stats()'s behavior changes from in-memory
# only to truncating system table. Hence, we create a small table here to
# to ensure that this test doesn't run for a very long time.
statement ok
Expand All @@ -49,7 +49,7 @@ statement ok
INSERT INTO smalldata VALUES (1), (2), (3)

query II
SELECT a, count(*) AS cnt FROM smalldata GROUP BY a HAVING crdb_internal.reset_sql_stats() ORDER BY a
SELECT a, count(*) AS cnt FROM smalldata GROUP BY a HAVING information_schema.crdb_reset_sql_stats() ORDER BY a
----
1 1
2 1
Expand Down
30 changes: 15 additions & 15 deletions pkg/sql/logictest/testdata/logic_test/distsql_stats
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ INSERT INTO xy VALUES (-1, 9), (-2, 8), (5, 15), (6, 16)
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS abcd_a_partial ON a FROM abcd USING EXTREMES;
Expand Down Expand Up @@ -2576,7 +2576,7 @@ INSERT INTO a_null VALUES (NULL), (NULL), (NULL);
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS a_null_stat_partial ON a FROM a_null USING EXTREMES;
Expand Down Expand Up @@ -2614,7 +2614,7 @@ INSERT INTO d_desc VALUES (0, 0), (5, 50);
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS sdp ON a FROM d_desc USING EXTREMES;
Expand Down Expand Up @@ -2648,7 +2648,7 @@ CREATE STATISTICS sdn ON a FROM d_desc;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS sdnp ON a FROM d_desc USING EXTREMES;
Expand Down Expand Up @@ -2704,7 +2704,7 @@ INSERT INTO s VALUES ('a'), ('b'), ('f');
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS s_partial ON s FROM s USING EXTREMES;
Expand All @@ -2731,7 +2731,7 @@ CREATE STATISTICS j_full ON j FROM j;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement error pq: table j does not contain a non-partial forward index with j as a prefix column
CREATE STATISTICS j_partial ON j FROM j USING EXTREMES;
Expand Down Expand Up @@ -2766,7 +2766,7 @@ CREATE STATISTICS only_null_stat ON a FROM only_null;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement error pq: the latest full statistic histogram for column a has only NULL values
EXPLAIN ANALYZE CREATE STATISTICS only_null_partial ON a FROM only_null USING EXTREMES;
Expand Down Expand Up @@ -3071,7 +3071,7 @@ INSERT INTO t68254 (a, b, c) VALUES (5, '5', '{"foo": {"bar": {"baz": 5}}}')
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS j6 ON d FROM t68254 USING EXTREMES
Expand Down Expand Up @@ -3143,7 +3143,7 @@ INSERT INTO int_outer_buckets SELECT generate_series(-10, -1) UNION ALL SELECT g
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS int_outer_buckets_partial ON a FROM int_outer_buckets USING EXTREMES;
Expand Down Expand Up @@ -3172,7 +3172,7 @@ CREATE STATISTICS int_outer_buckets_full ON a FROM int_outer_buckets;
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS int_outer_buckets_partial ON a FROM int_outer_buckets USING EXTREMES;
Expand Down Expand Up @@ -3219,7 +3219,7 @@ INSERT INTO timestamp_outer_buckets VALUES
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS timestamp_outer_buckets_partial ON a FROM timestamp_outer_buckets USING EXTREMES;
Expand Down Expand Up @@ -3295,7 +3295,7 @@ INSERT INTO timestamp_outer_buckets VALUES ('2024-06-28 01:00:00');
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS timestamp_outer_buckets_partial ON a FROM timestamp_outer_buckets USING EXTREMES;
Expand Down Expand Up @@ -3325,7 +3325,7 @@ CREATE STATISTICS bool_table_full ON a FROM bool_table
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement error pgcode 0A000 creating partial statistics at extremes on bool and enum columns is disabled
CREATE STATISTICS bool_table_partial ON a FROM bool_table USING EXTREMES;
Expand All @@ -3342,7 +3342,7 @@ CREATE STATISTICS enum_table_full ON a FROM enum_table
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement error pgcode 0A000 creating partial statistics at extremes on bool and enum columns is disabled
CREATE STATISTICS enum_table_full ON a FROM enum_table USING EXTREMES
Expand Down Expand Up @@ -3628,7 +3628,7 @@ INSERT INTO pstat_allindex VALUES
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement ok
CREATE STATISTICS pstat_allindex_partial FROM pstat_allindex USING EXTREMES;
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/inverted_index
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ ANALYZE t151995;
# Clear the stat cache so that the new statistic is guaranteed to be used (which
# are needed for the inverted join to be picked).
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

statement error geos error: IllegalArgumentException: BufferOp::getResultGeometry distance must be a finite value
SELECT *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ WHERE feature_name = 'sql.session.statement-hints'
5

statement ok
SELECT crdb_internal.clear_statement_hints_cache()
SELECT information_schema.crdb_clear_statement_hints_cache()

statement ok
SELECT * FROM xy WHERE x > y
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/exec/execbuilder/testdata/distsql_misc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJzsllFvo0YQx9_7K
# Clear the stat cache so that creating partial statistics has access to the
# latest full statistic.
statement ok
SELECT crdb_internal.clear_table_stats_cache();
SELECT information_schema.crdb_clear_table_stats_cache();

query T
EXPLAIN (DISTSQL) CREATE STATISTICS s1_constrained ON a FROM data WHERE a > 5
Expand Down
Loading
Loading