Skip to content

Commit

Permalink
workload: create statistics when making fixtures
Browse files Browse the repository at this point in the history
`workload make` imports a workload and then creates the backup (that
can be later used by `workload load`).

This change adds functionality to call CREATE STATISTICS on all tables
before creating the backup. This can be turned off using a flag.

Release note: None
  • Loading branch information
RaduBerinde committed Sep 25, 2020
1 parent 2f5ed88 commit 7f8c776
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/ccl/workloadccl/cliccl/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func config() workloadccl.FixtureConfig {
config.BillingProject = *gcsBillingProjectOverride
}
config.CSVServerURL = *fixturesMakeImportCSVServerURL
config.TableStats = *fixturesMakeTableStats
return config
}

Expand Down Expand Up @@ -91,6 +92,10 @@ var fixturesMakeFilesPerNode = fixturesMakeCmd.PersistentFlags().Int(
`files-per-node`, 1,
`number of file URLs to generate per node when using csv-server`)

var fixturesMakeTableStats = fixturesMakeCmd.PersistentFlags().Bool(
`table-stats`, true,
`generate full table statistics for all tables`)

var fixturesImportFilesPerNode = fixturesImportCmd.PersistentFlags().Int(
`files-per-node`, 1,
`number of file URLs to generate per node`)
Expand Down
26 changes: 26 additions & 0 deletions pkg/ccl/workloadccl/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ type FixtureConfig struct {
// storage requests. This is required to be set if using a "requestor pays"
// bucket.
BillingProject string

// If TableStats is true, CREATE STATISTICS is called on all tables before
// crating the fixture.
TableStats bool
}

func (s FixtureConfig) objectPathToURI(folder string) string {
Expand Down Expand Up @@ -279,6 +283,28 @@ func MakeFixture(
return Fixture{}, err
}

if config.TableStats {
// Clean up any existing statistics.
_, err := sqlDB.Exec("DELETE FROM system.table_statistics WHERE true")
if err != nil {
return Fixture{}, errors.Wrapf(err, "while deleting table statistics")
}
g := ctxgroup.WithContext(ctx)
for _, t := range gen.Tables() {
t := t
g.Go(func() error {
log.Infof(ctx, "Creating table stats for %s", t.Name)
_, err := sqlDB.Exec(fmt.Sprintf(
`CREATE STATISTICS pre_backup FROM "%s"."%s"`, dbName, t.Name,
))
return err
})
}
if err := g.Wait(); err != nil {
return Fixture{}, err
}
}

g := ctxgroup.WithContext(ctx)
for _, t := range gen.Tables() {
t := t
Expand Down

0 comments on commit 7f8c776

Please sign in to comment.