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

Schema changes for application-level aggregation metrics. #3315

Merged
merged 2 commits into from
Jul 22, 2024
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
2 changes: 1 addition & 1 deletion aggregator_core/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ macro_rules! supported_schema_versions {
// version is seen, [`Datastore::new`] fails.
//
// Note that the latest supported version must be first in the list.
supported_schema_versions!(6, 5);
supported_schema_versions!(7, 6);

/// Datastore represents a datastore for Janus, with support for transactional reads and writes.
/// In practice, Datastore instances are currently backed by a PostgreSQL database.
Expand Down
1 change: 1 addition & 0 deletions db/00000000000007_task_aggregation_counters.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE task_aggregation_counters;
14 changes: 14 additions & 0 deletions db/00000000000007_task_aggregation_counters.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Per-task report aggregation counters, used for metrics.
--
-- Fillfactor is lowered to improve the likelihood of heap-only tuple optimizations. See the
-- discussion around this setting for the task_upload_counters table.
CREATE TABLE task_aggregation_counters(
branlwyd marked this conversation as resolved.
Show resolved Hide resolved
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- artificial ID, internal only
task_id BIGINT NOT NULL, -- task ID the counter is associated with
ord BIGINT NOT NULL, -- the ordinal index of the task aggregation counter

success BIGINT NOT NULL DEFAULT 0, -- reports successfully aggregated

CONSTRAINT task_aggregation_counters_unique_id UNIQUE(task_id, ord),
CONSTRAINT fk_task_id FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
) WITH (fillfactor = 50);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that uploading these counter tables can be performance sensitive, I'm surprised we don't create an index on task ID. Maybe it's irrelevant because this table will be smallish anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONSTRAINT task_aggregation_counters_unique_id UNIQUE(task_id, ord) implicitly creates an index on (task_id, ord). We only ever INSERT on (task_id, ord) or SELECT task_id and aggregate over ord.

I have some query plans from task upload counters #2508 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNIQUE constraints generate a (unique) index on the relevant fields, so we have an index on (task_id, ord).

See https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS:

Adding a unique constraint will automatically create a unique B-tree index on the column or group of columns listed in the constraint.

Loading