Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql, stats: use the jobs framework for CREATE STATISTICS #34279

Merged
merged 1 commit into from
Jan 30, 2019
Merged
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
1,201 changes: 1,002 additions & 199 deletions pkg/jobs/jobspb/jobs.pb.go

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions pkg/jobs/jobspb/jobs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ message ChangefeedProgress {
repeated ResolvedSpan resolved_spans = 2 [(gogoproto.nullable) = false];
}

// CreateStatsDetails are used for the CreateStats job, which is triggered
// whenever the `CREATE STATISTICS` SQL statement is run. The CreateStats job
// collects table statistics, which contain info such as the number of rows in
// the table or the number of distinct values in a column.
message CreateStatsDetails {
message ColList {
repeated uint32 ids = 1 [
(gogoproto.customname) = "IDs",
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sqlbase.ColumnID"
];
}
string name = 1 [
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/sql/sem/tree.Name"
];
sqlbase.TableDescriptor table = 2 [(gogoproto.nullable) = false];
repeated ColList column_lists = 3 [(gogoproto.nullable) = false];
string Statement = 4;
}

message CreateStatsProgress {

}

message Payload {
string description = 1;
string username = 2;
Expand All @@ -215,6 +238,7 @@ message Payload {
SchemaChangeDetails schemaChange = 12;
ImportDetails import = 13;
ChangefeedDetails changefeed = 14;
CreateStatsDetails createStats = 15;
}
}

Expand All @@ -232,6 +256,7 @@ message Progress {
SchemaChangeProgress schemaChange = 12;
ImportProgress import = 13;
ChangefeedProgress changefeed = 14;
CreateStatsProgress createStats = 15;
}
}

Expand All @@ -245,4 +270,5 @@ enum Type {
SCHEMA_CHANGE = 3 [(gogoproto.enumvalue_customname) = "TypeSchemaChange"];
IMPORT = 4 [(gogoproto.enumvalue_customname) = "TypeImport"];
CHANGEFEED = 5 [(gogoproto.enumvalue_customname) = "TypeChangefeed"];
CREATE_STATS = 6 [(gogoproto.enumvalue_customname) = "TypeCreateStats"];
}
12 changes: 12 additions & 0 deletions pkg/jobs/jobspb/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var _ Details = BackupDetails{}
var _ Details = RestoreDetails{}
var _ Details = SchemaChangeDetails{}
var _ Details = ChangefeedDetails{}
var _ Details = CreateStatsDetails{}

// ProgressDetails is a marker interface for job progress details proto structs.
type ProgressDetails interface{}
Expand All @@ -36,6 +37,7 @@ var _ ProgressDetails = BackupProgress{}
var _ ProgressDetails = RestoreProgress{}
var _ ProgressDetails = SchemaChangeProgress{}
var _ ProgressDetails = ChangefeedProgress{}
var _ ProgressDetails = CreateStatsProgress{}

// Type returns the payload's job type.
func (p *Payload) Type() Type {
Expand All @@ -55,6 +57,8 @@ func DetailsType(d isPayload_Details) Type {
return TypeImport
case *Payload_Changefeed:
return TypeChangefeed
case *Payload_CreateStats:
return TypeCreateStats
default:
panic(fmt.Sprintf("Payload.Type called on a payload with an unknown details type: %T", d))
}
Expand All @@ -79,6 +83,8 @@ func WrapProgressDetails(details ProgressDetails) interface {
return &Progress_Import{Import: &d}
case ChangefeedProgress:
return &Progress_Changefeed{Changefeed: &d}
case CreateStatsProgress:
return &Progress_CreateStats{CreateStats: &d}
default:
panic(fmt.Sprintf("WrapProgressDetails: unknown details type %T", d))
}
Expand All @@ -98,6 +104,8 @@ func (p *Payload) UnwrapDetails() Details {
return *d.Import
case *Payload_Changefeed:
return *d.Changefeed
case *Payload_CreateStats:
return *d.CreateStats
default:
return nil
}
Expand All @@ -117,6 +125,8 @@ func (p *Progress) UnwrapDetails() ProgressDetails {
return *d.Import
case *Progress_Changefeed:
return *d.Changefeed
case *Progress_CreateStats:
return *d.CreateStats
default:
return nil
}
Expand Down Expand Up @@ -149,6 +159,8 @@ func WrapPayloadDetails(details Details) interface {
return &Payload_Import{Import: &d}
case ChangefeedDetails:
return &Payload_Changefeed{Changefeed: &d}
case CreateStatsDetails:
return &Payload_CreateStats{CreateStats: &d}
default:
panic(fmt.Sprintf("jobs.WrapPayloadDetails: unknown details type %T", d))
}
Expand Down
Loading