Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
86078: sql/stats: generate statistics forecasts r=rytaft,yuzefovich a=michae2

**sql/stats: use nil eval.Context as CompareContext when forecasting**

When forecasting table statistics, we don't need a full *eval.Context.
We can simply use a nil *eval.Context as a tree.CompareContext. This
means we don't have to plumb an eval.Context into the stats cache.

Assists: #79872

Release note: None

**sql/stats: generate statistics forecasts in the stats cache**

As of this commit, we now try to generate statistics forecasts for every
column of every table. This happens whenever statistics are loaded into
or refreshed in the stats cache. We use only the forecasts that fit the
historical collected statistics very well, meaning we have high
confidence in their accuracy.

Fixes: #79872

Release note (performance improvement): Enable table statistics
forecasts, which predict future statistics based on historical collected
statistics. Forecasts help the optimizer produce better plans for
queries that read data modified after the latest statistics collection.
We use only the forecasts that fit the historical collected statistics
very well, meaning we have high confidence in their accuracy. Forecasts
can be viewed using `SHOW STATISTICS FOR TABLE ... WITH FORECAST`.

**sql: show forecasted stats time in EXPLAIN**

When using statistics forecasts, add the forecast time (which could be
in the future) to EXPLAIN output. This both indicates that forecasts are
in use, and gives us an idea of how up-to-date / ahead they are.

Assists: #79872

Release note: None

**sql/opt: add tests for statistics forecasts**

Add a few simple testcases for usage of statistics forecasts by the
optimizer.

Assists: #79872

Release note: None

---

Release justification: Enable feature before we get too far into
stability period.

86137: sql: use DelRange with tombstone in `force_delete_table_data` r=ajwerner a=ajwerner

Fixes #85754

Release justification: minor change needed to adopt MVCC bulk ops fully

Release note: None

86160: colexecerror: do not annotate the context canceled error r=yuzefovich a=yuzefovich

This commit makes it so that the context canceled error doesn't get
annotated with an assertion failure when it doesn't have a valid PG
code. This makes sure that the sentry issues don't get filed for the
context canceled errors - they are expected to occur.

Fixes: #82947

Release note: None

Release justification: bug fix.

86164: sql: deflake TestRoleOptionsMigration15000User r=ajwerner a=RichardJCai

Previously it was flakey because we always assumed the first user created
had ID 100, however this is not the case due to transaction failures.

Release note: None

Release justification: test only

86173: opt: fix error due to unsupported comparison for partitioned secondary index r=rytaft a=rytaft

This commit fixes a bug where we were attempting to find the locality of the
partitions in a secondary index, but we passed the incorrect index ordinal to
the function `IndexPartitionLocality`.

Fixes #86168

Release justification: Category 3: Fixes for high-priority or high-severity bugs in existing functionality

Release note (bug fix): Fixed a bug that existed on v22.1.0-v22.1.5, where
attempting to select data from a table that had different partitioning columns
used for the primary and secondary indexes could cause an error. This occured
if the primary index had zone configurations applied to the index partitions
with different regions for different partitions, and the secondary index had a
different column type than the primary index for its partitioning column(s).

Co-authored-by: Michael Erickson <[email protected]>
Co-authored-by: Andrew Werner <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: richardjcai <[email protected]>
Co-authored-by: Rebecca Taft <[email protected]>
  • Loading branch information
6 people committed Aug 16, 2022
6 parents f4042d4 + 1c21c3a + cc9da6e + f17a6cd + 9d1a0d4 + 6b452bc commit b1bc502
Show file tree
Hide file tree
Showing 23 changed files with 792 additions and 67 deletions.
9 changes: 5 additions & 4 deletions pkg/sql/colexecerror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func CatchVectorizedRuntimeError(operation func()) (retErr error) {

annotateErrorWithoutCode := true
var nie *notInternalError
if errors.As(err, &nie) {
// A notInternalError was not caused by the vectorized engine and
// represents an error that we don't want to annotate in case it
// doesn't have a valid PG code.
if errors.Is(err, context.Canceled) || errors.As(err, &nie) {
// We don't want to annotate the context cancellation and
// notInternalError errors in case they don't have a valid PG code
// so that the sentry report is not sent (errors with failed
// assertions get sentry reports).
annotateErrorWithoutCode = false
}
if code := pgerror.GetPGCode(err); annotateErrorWithoutCode && code == pgcode.Uncategorized {
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/opt/cat/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ type TableStatistic interface {
// HistogramType returns the type that the histogram was created on. For
// inverted index histograms, this will always return types.Bytes.
HistogramType() *types.T

// IsForecast returns true if this statistic is a forecast.
IsForecast() bool
}

// HistogramBucket contains the data for a single histogram bucket. Note
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/opt/exec/execbuilder/relational.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ func (b *Builder) maybeAnnotateWithEstimates(node exec.Node, e memo.RelExpr) {
}
val.TableStatsCreatedAt = stat.CreatedAt()
val.LimitHint = scan.RequiredPhysical().LimitHint
val.Forecast = stat.IsForecast()
if val.Forecast {
val.ForecastAt = stat.CreatedAt()
// Find the first non-forecast stat.
for i := 0; i < tab.StatisticCount(); i++ {
nextStat := tab.Statistic(i)
if !nextStat.IsForecast() {
val.TableStatsCreatedAt = nextStat.CreatedAt()
break
}
}
}
}
}
ef.AnnotateNode(node, exec.EstimatedStatsID, &val)
Expand Down
Loading

0 comments on commit b1bc502

Please sign in to comment.