Skip to content

Commit

Permalink
sql: remove count from stmt/txn stats system table
Browse files Browse the repository at this point in the history
Previously, system.statement_statistics and
system.transaction_statistics table includes a `count` column
that corresponds to `roachpb.StatementStatistics.Count` and
`roachpb.TransactionStatistics.Count` fields respectively.
The objective for that column is to make
`INSERT ON CONFLICT DO UPDATE` style query easy. However,
since early prototyping have shown that
`INSERT ON CONFLICT DO UPDATE` style statement is quite inefficient,
the SQL Stats flush mechanism will be implemented using
separate queries INSERT and UPDATE statements.
This column is no longer userful and it would require special handling.
Removing this column simplifies the flush logic and removes the
need for special handlings.

Release note (sql change): count column is removed from
 system.statement_statistics and system.transaction_statistics
 tables.
  • Loading branch information
Azhng committed Aug 5, 2021
1 parent 0592999 commit a445110
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 56 deletions.
58 changes: 24 additions & 34 deletions pkg/sql/catalog/systemschema/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,13 @@ CREATE TABLE system.join_tokens (
CREATE TABLE system.statement_statistics (
aggregated_ts TIMESTAMPTZ NOT NULL,
fingerprint_id BYTES NOT NULL,
plan_hash INT NOT NULL,
plan_hash INT8 NOT NULL,
app_name STRING NOT NULL,
node_id INT NOT NULL,
node_id INT8 NOT NULL,
count INT NOT NULL,
agg_interval INTERVAL NOT NULL,
metadata JSONB NOT NULL,
statistics JSONB NOT NULL,
plan JSONB NOT NULL,
PRIMARY KEY (aggregated_ts, fingerprint_id, plan_hash, app_name, node_id)
Expand All @@ -399,7 +396,6 @@ CREATE TABLE system.statement_statistics (
plan_hash,
app_name,
node_id,
count,
agg_interval,
metadata,
statistics,
Expand All @@ -413,11 +409,9 @@ CREATE TABLE system.transaction_statistics (
aggregated_ts TIMESTAMPTZ NOT NULL,
fingerprint_id BYTES NOT NULL,
app_name STRING NOT NULL,
node_id INT NOT NULL,
node_id INT8 NOT NULL,
count INT NOT NULL,
agg_interval INTERVAL NOT NULL,
metadata JSONB NOT NULL,
statistics JSONB NOT NULL,
Expand All @@ -430,7 +424,6 @@ CREATE TABLE system.transaction_statistics (
fingerprint_id,
app_name,
node_id,
count,
agg_interval,
metadata,
statistics
Expand Down Expand Up @@ -1928,31 +1921,30 @@ var (
{Name: "plan_hash", ID: 3, Type: types.Int, Nullable: false},
{Name: "app_name", ID: 4, Type: types.String, Nullable: false},
{Name: "node_id", ID: 5, Type: types.Int, Nullable: false},
{Name: "count", ID: 6, Type: types.Int, Nullable: false},
{Name: "agg_interval", ID: 7, Type: types.Interval, Nullable: false},
{Name: "metadata", ID: 8, Type: types.Jsonb, Nullable: false},
{Name: "statistics", ID: 9, Type: types.Jsonb, Nullable: false},
{Name: "plan", ID: 10, Type: types.Jsonb, Nullable: false},
{Name: "agg_interval", ID: 6, Type: types.Interval, Nullable: false},
{Name: "metadata", ID: 7, Type: types.Jsonb, Nullable: false},
{Name: "statistics", ID: 8, Type: types.Jsonb, Nullable: false},
{Name: "plan", ID: 9, Type: types.Jsonb, Nullable: false},
{
Name: "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_shard_8",
ID: 11,
ID: 10,
Type: types.Int4,
Nullable: false,
ComputeExpr: &sqlStmtHashComputeExpr,
Hidden: true,
},
},
NextColumnID: 12,
NextColumnID: 11,
Families: []descpb.ColumnFamilyDescriptor{
{
Name: "primary",
ID: 0,
ColumnNames: []string{
"crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_shard_8",
"aggregated_ts", "fingerprint_id", "plan_hash", "app_name", "node_id",
"count", "agg_interval", "metadata", "statistics", "plan",
"agg_interval", "metadata", "statistics", "plan",
},
ColumnIDs: []descpb.ColumnID{11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
ColumnIDs: []descpb.ColumnID{10, 1, 2, 3, 4, 5, 6, 7, 8, 9},
DefaultColumnID: 0,
},
},
Expand All @@ -1977,7 +1969,7 @@ var (
descpb.IndexDescriptor_ASC,
descpb.IndexDescriptor_ASC,
},
KeyColumnIDs: []descpb.ColumnID{11, 1, 2, 3, 4, 5},
KeyColumnIDs: []descpb.ColumnID{10, 1, 2, 3, 4, 5},
Version: descpb.StrictIndexColumnIDGuaranteesVersion,
Sharded: descpb.ShardedDescriptor{
IsSharded: true,
Expand All @@ -1997,7 +1989,7 @@ var (
Expr: "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_shard_8 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8)",
Name: "check_crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_plan_hash_shard_8",
Validity: descpb.ConstraintValidity_Validated,
ColumnIDs: []descpb.ColumnID{11},
ColumnIDs: []descpb.ColumnID{10},
IsNonNullConstraint: false,
Hidden: true,
},
Expand All @@ -2022,7 +2014,7 @@ var (
descpb.IndexDescriptor_ASC,
},
KeyColumnIDs: []descpb.ColumnID{2, 1, 3, 4, 5},
KeySuffixColumnIDs: []descpb.ColumnID{11},
KeySuffixColumnIDs: []descpb.ColumnID{10},
Version: descpb.StrictIndexColumnIDGuaranteesVersion,
},
},
Expand All @@ -2046,31 +2038,29 @@ var (
{Name: "fingerprint_id", ID: 2, Type: types.Bytes, Nullable: false},
{Name: "app_name", ID: 3, Type: types.String, Nullable: false},
{Name: "node_id", ID: 4, Type: types.Int, Nullable: false},
{Name: "count", ID: 5, Type: types.Int, Nullable: false},
{Name: "agg_interval", ID: 6, Type: types.Interval, Nullable: false},
{Name: "metadata", ID: 7, Type: types.Jsonb, Nullable: false},
{Name: "statistics", ID: 8, Type: types.Jsonb, Nullable: false},
{Name: "agg_interval", ID: 5, Type: types.Interval, Nullable: false},
{Name: "metadata", ID: 6, Type: types.Jsonb, Nullable: false},
{Name: "statistics", ID: 7, Type: types.Jsonb, Nullable: false},
{
Name: "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8",
ID: 9,
ID: 8,
Type: types.Int4,
Nullable: false,
ComputeExpr: &sqlTxnHashComputeExpr,
Hidden: true,
},
},
NextColumnID: 10,
NextColumnID: 9,
Families: []descpb.ColumnFamilyDescriptor{
{
Name: "primary",
ID: 0,
ColumnNames: []string{
"crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8",
"aggregated_ts", "fingerprint_id", "app_name", "node_id",
"count", "agg_interval", "metadata", "statistics",
"agg_interval", "metadata", "statistics",
},
ColumnIDs: []descpb.ColumnID{9, 1, 2, 3, 4, 5, 6, 7, 8},

ColumnIDs: []descpb.ColumnID{8, 1, 2, 3, 4, 5, 6, 7},
DefaultColumnID: 0,
},
},
Expand All @@ -2093,7 +2083,7 @@ var (
descpb.IndexDescriptor_ASC,
descpb.IndexDescriptor_ASC,
},
KeyColumnIDs: []descpb.ColumnID{9, 1, 2, 3, 4},
KeyColumnIDs: []descpb.ColumnID{8, 1, 2, 3, 4},
Version: descpb.StrictIndexColumnIDGuaranteesVersion,
Sharded: descpb.ShardedDescriptor{
IsSharded: true,
Expand All @@ -2112,7 +2102,7 @@ var (
Expr: "crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8 IN (0:::INT8, 1:::INT8, 2:::INT8, 3:::INT8, 4:::INT8, 5:::INT8, 6:::INT8, 7:::INT8)",
Name: "check_crdb_internal_aggregated_ts_app_name_fingerprint_id_node_id_shard_8",
Validity: descpb.ConstraintValidity_Validated,
ColumnIDs: []descpb.ColumnID{9},
ColumnIDs: []descpb.ColumnID{8},
IsNonNullConstraint: false,
Hidden: true,
},
Expand All @@ -2135,7 +2125,7 @@ var (
descpb.IndexDescriptor_ASC,
},
KeyColumnIDs: []descpb.ColumnID{2, 1, 3, 4},
KeySuffixColumnIDs: []descpb.ColumnID{9},
KeySuffixColumnIDs: []descpb.ColumnID{8},
Version: descpb.StrictIndexColumnIDGuaranteesVersion,
},
},
Expand Down
Loading

0 comments on commit a445110

Please sign in to comment.