Skip to content

Commit 30b30f0

Browse files
craig[bot]dhartunianrytaft
committed
140531: gceworker: better handling of firewall for home use r=dhartunian a=dhartunian Previously, creating a gceworker from outside the office would fail because firewall rules wouldn't get updated prior to ssh-ing in. We now update the firewall prior to ssh-ing, and also delete the home ssh rule on destroy. Release note: None 142924: sql: support disabling full auto stats independent of partial auto stats r=rytaft a=rytaft This commit adds support for enabling and disabling full auto stats collection independent of whether or not partial auto stats are enabled/disabled. This commit also fixes a flake in the `distsql_automatic_partial_stats` logictest. Fixes #132697 Release note (sql change): It is now possible to automatically collect partial table statistics, but disable automatic collection of full table statistics. The new cluster and table settings to enable/ disable automatic collection of full table statistics (without affecting the settings for partial stats) are: - `sql.stats.automatic_full_collection.enabled`/ `sql_stats_automatic_full_collection_enabled` - Defaults to `true` Co-authored-by: David Hartunian <[email protected]> Co-authored-by: Rebecca Taft <[email protected]>
3 parents b02a97a + 2401ba3 + 748a5cf commit 30b30f0

File tree

13 files changed

+227
-46
lines changed

13 files changed

+227
-46
lines changed

docs/generated/settings/settings-for-tenants.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ sql.stats.activity.persisted_rows.max integer 200000 maximum number of rows of s
343343
sql.stats.automatic_collection.enabled boolean true automatic statistics collection mode application
344344
sql.stats.automatic_collection.fraction_stale_rows float 0.2 target fraction of stale rows per table that will trigger a statistics refresh application
345345
sql.stats.automatic_collection.min_stale_rows integer 500 target minimum number of stale rows per table that will trigger a statistics refresh application
346+
sql.stats.automatic_full_collection.enabled boolean true automatic full statistics collection mode application
346347
sql.stats.automatic_partial_collection.enabled boolean true automatic partial statistics collection mode application
347348
sql.stats.automatic_partial_collection.fraction_stale_rows float 0.05 target fraction of stale rows per table that will trigger a partial statistics refresh application
348349
sql.stats.automatic_partial_collection.min_stale_rows integer 100 target minimum number of stale rows per table that will trigger a partial statistics refresh application

docs/generated/settings/settings.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
<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>
299299
<tr><td><div id="setting-sql-stats-automatic-collection-fraction-stale-rows" class="anchored"><code>sql.stats.automatic_collection.fraction_stale_rows</code></div></td><td>float</td><td><code>0.2</code></td><td>target fraction of stale rows per table that will trigger a statistics refresh</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
300300
<tr><td><div id="setting-sql-stats-automatic-collection-min-stale-rows" class="anchored"><code>sql.stats.automatic_collection.min_stale_rows</code></div></td><td>integer</td><td><code>500</code></td><td>target minimum number of stale rows per table that will trigger a statistics refresh</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
301+
<tr><td><div id="setting-sql-stats-automatic-full-collection-enabled" class="anchored"><code>sql.stats.automatic_full_collection.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>automatic full statistics collection mode</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
301302
<tr><td><div id="setting-sql-stats-automatic-partial-collection-enabled" class="anchored"><code>sql.stats.automatic_partial_collection.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>automatic partial statistics collection mode</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
302303
<tr><td><div id="setting-sql-stats-automatic-partial-collection-fraction-stale-rows" class="anchored"><code>sql.stats.automatic_partial_collection.fraction_stale_rows</code></div></td><td>float</td><td><code>0.05</code></td><td>target fraction of stale rows per table that will trigger a partial statistics refresh</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
303304
<tr><td><div id="setting-sql-stats-automatic-partial-collection-min-stale-rows" class="anchored"><code>sql.stats.automatic_partial_collection.min_stale_rows</code></div></td><td>integer</td><td><code>100</code></td><td>target minimum number of stale rows per table that will trigger a partial statistics refresh</td><td>Serverless/Dedicated/Self-Hosted</td></tr>

pkg/sql/catalog/catpb/catalog.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ package catpb
99
// enabled table setting is enabled, disabled, or not set.
1010
type AutoStatsCollectionStatus int
1111

12-
// AutoPartialStatsCollectionStatus represents whether the auto stats
12+
// AutoPartialStatsCollectionStatus represents whether the auto partial stats
1313
// collections enabled table setting is enabled, disabled or not set.
1414
type AutoPartialStatsCollectionStatus int
1515

16+
// AutoFullStatsCollectionStatus represents whether the auto full stats
17+
// collections enabled table setting is enabled, disabled or not set.
18+
type AutoFullStatsCollectionStatus int
19+
1620
// The values for AutoStatsCollectionStatus.
1721
const (
1822
AutoStatsCollectionNotSet AutoStatsCollectionStatus = iota
@@ -26,6 +30,12 @@ const (
2630
AutoPartialStatsCollectionDisabled
2731
)
2832

33+
const (
34+
AutoFullStatsCollectionNotSet AutoFullStatsCollectionStatus = iota
35+
AutoFullStatsCollectionEnabled
36+
AutoFullStatsCollectionDisabled
37+
)
38+
2939
const (
3040
// AutoStatsEnabledSettingName is the name of the automatic stats collection
3141
// enabled cluster setting.
@@ -60,15 +70,15 @@ const (
6070
AutoStatsFractionStaleTableSettingName = "sql_stats_automatic_collection_fraction_stale_rows"
6171

6272
// AutoPartialStatsEnabledSettingName is the name of the automatic partial
63-
// stats collection enabled cluster setting
73+
// stats collection enabled cluster setting.
6474
AutoPartialStatsEnabledSettingName = "sql.stats.automatic_partial_collection.enabled"
6575

6676
// AutoPartialStatsEnabledTableSettingName is the name of the automatic
6777
// partial stats collection enabled table setting.
6878
AutoPartialStatsEnabledTableSettingName = "sql_stats_automatic_partial_collection_enabled"
6979

7080
// AutoPartialStatsMinStaleSettingName is the name of the automatic partial
71-
// stats collection min stale rows cluster setting
81+
// stats collection min stale rows cluster setting.
7282
AutoPartialStatsMinStaleSettingName = "sql.stats.automatic_partial_collection.min_stale_rows"
7383

7484
// AutoPartialStatsMinStaleTableSettingName is the name of the automatic
@@ -82,6 +92,14 @@ const (
8292
// AutoPartialStatsFractionStaleTableSettingName is the name of the automatic
8393
// partial stats collection fraction stale rows table setting.
8494
AutoPartialStatsFractionStaleTableSettingName = "sql_stats_automatic_partial_collection_fraction_stale_rows"
95+
96+
// AutoFullStatsEnabledSettingName is the name of the automatic full
97+
// stats collection enabled cluster setting.
98+
AutoFullStatsEnabledSettingName = "sql.stats.automatic_full_collection.enabled"
99+
100+
// AutoFullStatsEnabledTableSettingName is the name of the automatic
101+
// full stats collection enabled table setting.
102+
AutoFullStatsEnabledTableSettingName = "sql_stats_automatic_full_collection_enabled"
85103
)
86104

87105
// AutoStatsCollectionEnabled indicates if automatic statistics collection is
@@ -124,6 +142,7 @@ func (as *AutoStatsSettings) NoAutoStatsSettingsOverrides() bool {
124142
as.MinStaleRows != nil ||
125143
as.FractionStaleRows != nil ||
126144
as.PartialEnabled != nil ||
145+
as.FullEnabled != nil ||
127146
as.PartialMinStaleRows != nil ||
128147
as.PartialFractionStaleRows != nil {
129148
return false
@@ -151,6 +170,18 @@ func (as *AutoStatsSettings) AutoPartialStatsCollectionEnabled() AutoPartialStat
151170
return AutoPartialStatsCollectionDisabled
152171
}
153172

173+
// AutoFullStatsCollectionEnabled indicates if automatic full statistics
174+
// collection is explicitly enabled or disabled.
175+
func (as *AutoStatsSettings) AutoFullStatsCollectionEnabled() AutoFullStatsCollectionStatus {
176+
if as.FullEnabled == nil {
177+
return AutoFullStatsCollectionNotSet
178+
}
179+
if *as.FullEnabled {
180+
return AutoFullStatsCollectionEnabled
181+
}
182+
return AutoFullStatsCollectionDisabled
183+
}
184+
154185
// AutoPartialStatsMinStaleRows indicates the setting of
155186
// sql_stats_automatic_partial_collection_min_stale_rows in
156187
// AutoStatsSettings. If ok is true, then the minStaleRows value is

pkg/sql/catalog/catpb/catalog.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ message AutoStatsSettings {
213213
// PartialEnabled is table setting sql_stats_automatic_partial_collection_enabled.
214214
optional bool partial_enabled = 4;
215215
// PartialMinStaleRows is table setting sql_stats_automatic_partial_collection_min_stale_rows.
216-
optional int64 partial_min_stale_rows = 5;
216+
optional int64 partial_min_stale_rows = 5;
217217
// PartialFractionStaleRows is table setting sql_stats_automatic_partial_collection_fraction_stale_rows.
218218
optional double partial_fraction_stale_rows = 6;
219+
// FullEnabled is table setting sql_stats_automatic_full_collection_enabled.
220+
optional bool full_enabled = 7;
219221
}

pkg/sql/catalog/descriptor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ type TableDescriptor interface {
796796
// AutoPartialStatsCollectionEnabled indicates if automatic partial statistics
797797
// collection is explicitly enabled or disabled for this table.
798798
AutoPartialStatsCollectionEnabled() catpb.AutoPartialStatsCollectionStatus
799+
// AutoFullStatsCollectionEnabled indicates if automatic full statistics
800+
// collection is explicitly enabled or disabled for this table.
801+
AutoFullStatsCollectionEnabled() catpb.AutoFullStatsCollectionStatus
799802
// AutoStatsMinStaleRows indicates the setting of
800803
// sql_stats_automatic_collection_min_stale_rows for this table.
801804
// If ok is true, then the minStaleRows value is valid, otherwise this has not

pkg/sql/catalog/tabledesc/structured.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,11 @@ func (desc *wrapper) GetStorageParams(spaceBetweenEqual bool) []string {
25192519
appendStorageParam(catpb.AutoPartialStatsEnabledTableSettingName,
25202520
fmt.Sprintf("%v", value))
25212521
}
2522+
if settings.FullEnabled != nil {
2523+
value := *settings.FullEnabled
2524+
appendStorageParam(catpb.AutoFullStatsEnabledTableSettingName,
2525+
fmt.Sprintf("%v", value))
2526+
}
25222527
if settings.PartialMinStaleRows != nil {
25232528
value := *settings.PartialMinStaleRows
25242529
appendStorageParam(catpb.AutoPartialStatsMinStaleTableSettingName,
@@ -2576,13 +2581,22 @@ func (desc *wrapper) AutoStatsCollectionEnabled() catpb.AutoStatsCollectionStatu
25762581
return desc.AutoStatsSettings.AutoStatsCollectionEnabled()
25772582
}
25782583

2584+
// AutoPartialStatsCollectionEnabled implements the TableDescriptor interface.
25792585
func (desc *wrapper) AutoPartialStatsCollectionEnabled() catpb.AutoPartialStatsCollectionStatus {
25802586
if desc.AutoStatsSettings == nil {
25812587
return catpb.AutoPartialStatsCollectionNotSet
25822588
}
25832589
return desc.AutoStatsSettings.AutoPartialStatsCollectionEnabled()
25842590
}
25852591

2592+
// AutoFullStatsCollectionEnabled implements the TableDescriptor interface.
2593+
func (desc *wrapper) AutoFullStatsCollectionEnabled() catpb.AutoFullStatsCollectionStatus {
2594+
if desc.AutoStatsSettings == nil {
2595+
return catpb.AutoFullStatsCollectionNotSet
2596+
}
2597+
return desc.AutoStatsSettings.AutoFullStatsCollectionEnabled()
2598+
}
2599+
25862600
// AutoStatsMinStaleRows implements the TableDescriptor interface.
25872601
func (desc *wrapper) AutoStatsMinStaleRows() (minStaleRows int64, ok bool) {
25882602
if desc.AutoStatsSettings == nil {

pkg/sql/catalog/tabledesc/validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,7 @@ func (desc *wrapper) validateAutoStatsSettings(vea catalog.ValidationErrorAccumu
22382238
}
22392239
desc.validateAutoStatsEnabled(vea, catpb.AutoStatsEnabledTableSettingName, desc.AutoStatsSettings.Enabled)
22402240
desc.validateAutoStatsEnabled(vea, catpb.AutoPartialStatsEnabledTableSettingName, desc.AutoStatsSettings.PartialEnabled)
2241+
desc.validateAutoStatsEnabled(vea, catpb.AutoFullStatsEnabledTableSettingName, desc.AutoStatsSettings.FullEnabled)
22412242

22422243
desc.validateMinStaleRows(vea, catpb.AutoStatsMinStaleTableSettingName, desc.AutoStatsSettings.MinStaleRows)
22432244
desc.validateMinStaleRows(vea, catpb.AutoPartialStatsMinStaleTableSettingName, desc.AutoStatsSettings.PartialMinStaleRows)

pkg/sql/catalog/tabledesc/validate_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ var validationMap = []struct {
313313
"MinStaleRows": {status: iSolemnlySwearThisFieldIsValidated},
314314
"FractionStaleRows": {status: iSolemnlySwearThisFieldIsValidated},
315315
"PartialEnabled": {status: iSolemnlySwearThisFieldIsValidated},
316+
"FullEnabled": {status: iSolemnlySwearThisFieldIsValidated},
316317
"PartialMinStaleRows": {status: iSolemnlySwearThisFieldIsValidated},
317318
"PartialFractionStaleRows": {status: iSolemnlySwearThisFieldIsValidated},
318319
},
@@ -2566,6 +2567,18 @@ func TestValidateTableDesc(t *testing.T) {
25662567
NextColumnID: 2,
25672568
AutoStatsSettings: &catpb.AutoStatsSettings{PartialEnabled: &boolTrue},
25682569
}},
2570+
{err: `Setting sql_stats_automatic_full_collection_enabled may not be set on virtual table`,
2571+
desc: descpb.TableDescriptor{
2572+
ID: catconstants.MinVirtualID,
2573+
ParentID: 1,
2574+
Name: "foo",
2575+
FormatVersion: descpb.InterleavedFormatVersion,
2576+
Columns: []descpb.ColumnDescriptor{
2577+
{ID: 1, Name: "bar"},
2578+
},
2579+
NextColumnID: 2,
2580+
AutoStatsSettings: &catpb.AutoStatsSettings{FullEnabled: &boolTrue},
2581+
}},
25692582
{err: `Setting sql_stats_automatic_collection_enabled may not be set on a view or sequence`,
25702583
desc: descpb.TableDescriptor{
25712584
Name: "bar",

pkg/sql/logictest/testdata/logic_test/distsql_automatic_partial_stats

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,21 @@ statistics_name column_names row_count distinct_count null_count partial_p
2929
statement ok
3030
CREATE STATISTICS __auto__ FROM data
3131

32-
# Set the min_stale_rows to MaxInt32 to ensure that full stat collections are
33-
# not triggered
32+
query TTIIIT colnames,retry
33+
SELECT DISTINCT ON (statistics_name, column_names) statistics_name, column_names, row_count, distinct_count, null_count, partial_predicate
34+
FROM [SHOW STATISTICS FOR TABLE data] ORDER BY statistics_name, column_names, created DESC
35+
----
36+
statistics_name column_names row_count distinct_count null_count partial_predicate
37+
__auto__ {a} 1000 10 0 NULL
38+
__auto__ {a,b} 1000 100 0 NULL
39+
__auto__ {a,b,c} 1000 1000 0 NULL
40+
__auto__ {b} 1000 10 0 NULL
41+
__auto__ {c} 1000 10 0 NULL
42+
__auto__ {d} 1000 1 0 NULL
43+
44+
# Disable full stat collections.
3445
statement ok
35-
SET CLUSTER SETTING sql.stats.automatic_collection.min_stale_rows = 2147483647
46+
SET CLUSTER SETTING sql.stats.automatic_full_collection.enabled = false
3647

3748
statement ok
3849
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = true
@@ -60,11 +71,16 @@ __auto_partial__ {a} 0 0 0 (a IS NUL
6071
__auto_partial__ {c} 0 0 0 (c IS NULL) OR ((c < 1.0:::FLOAT8) OR (c > 10.0:::FLOAT8))
6172
__auto_partial__ {d} 100 1 0 (d IS NULL) OR ((d < 1:::DECIMAL) OR (d > 1:::DECIMAL))
6273

63-
# Disable automatic partial stats with the table setting
74+
# Enable full stat collections with the cluster setting.
6475
statement ok
65-
ALTER TABLE data SET (sql_stats_automatic_partial_collection_enabled = false)
76+
SET CLUSTER SETTING sql.stats.automatic_full_collection.enabled = true
6677

67-
# Change 20% of the table, no new partial stats should be collected.
78+
# Disable automatic partial and full stats with the table settings.
79+
statement ok
80+
ALTER TABLE data SET (sql_stats_automatic_partial_collection_enabled = false);
81+
ALTER TABLE data SET (sql_stats_automatic_full_collection_enabled = false)
82+
83+
# Change 20% of the table, no new partial or full stats should be collected.
6884
statement ok
6985
UPDATE DATA SET d = 3 WHERE a = 1 OR a = 2
7086

@@ -175,3 +191,27 @@ __auto__ {d} 1000 1 0 NULL
175191
__auto_partial__ {a} 16 1 0 (a IS NULL) OR ((a < 1:::INT8) OR (a > 10:::INT8))
176192
__auto_partial__ {c} 16 4 0 (c IS NULL) OR ((c < 1.0:::FLOAT8) OR (c > 10.0:::FLOAT8))
177193
__auto_partial__ {d} 216 3 4 (d IS NULL) OR ((d < 1:::DECIMAL) OR (d > 1:::DECIMAL))
194+
195+
# Now disable automatic partial stats but enable full stats with the table settings.
196+
statement ok
197+
ALTER TABLE data SET (sql_stats_automatic_partial_collection_enabled = false);
198+
ALTER TABLE data SET (sql_stats_automatic_full_collection_enabled = true)
199+
200+
# Insert enough data to trigger a full stats collection.
201+
statement ok
202+
INSERT INTO data SELECT a, b, c FROM
203+
generate_series(15, 25) AS a(a),
204+
generate_series(15, 25) AS b(b),
205+
generate_series(15, 25) AS c(c)
206+
207+
query TTIIIT colnames,retry
208+
SELECT DISTINCT ON (statistics_name, column_names) statistics_name, column_names, row_count, distinct_count, null_count, partial_predicate
209+
FROM [SHOW STATISTICS FOR TABLE data] ORDER BY statistics_name, column_names, created DESC
210+
----
211+
statistics_name column_names row_count distinct_count null_count partial_predicate
212+
__auto__ {a} 2347 22 0 NULL
213+
__auto__ {a,b} 2347 225 0 NULL
214+
__auto__ {a,b,c} 2347 2347 0 NULL
215+
__auto__ {b} 2347 25 0 NULL
216+
__auto__ {c} 2347 25 0 NULL
217+
__auto__ {d} 2347 4 1335 NULL

0 commit comments

Comments
 (0)