Skip to content

Commit

Permalink
fix(#5658): Fix instruction stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarina Yakubova authored and Zarina Yakubova committed Oct 22, 2024
1 parent 8cab026 commit 7c26a8a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
BEGIN;

DROP INDEX IF EXISTS instruction_execution_by_modified_on_instruction_updated_time_idx;
ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove;

CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on
(
time TIMESTAMP NOT NULL,
instruction VARCHAR(500) NOT NULL,
execution_count INT NOT NULL,
successful INT NOT NULL,
avg_complete_time INT NOT NULL,
init_critical INT NOT NULL DEFAULT 0,
init_major INT NOT NULL DEFAULT 0,
init_minor INT NOT NULL DEFAULT 0,
res_critical INT NOT NULL DEFAULT 0,
res_major INT NOT NULL DEFAULT 0,
res_minor INT NOT NULL DEFAULT 0,
res_ok INT NOT NULL DEFAULT 0
);
SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE);

INSERT INTO instruction_execution_by_modified_on
(
time,
instruction,
execution_count,
successful,
avg_complete_time,
init_critical,
init_major,
init_minor,
res_critical,
res_major,
res_minor,
res_ok
)
SELECT
instruction_updated as time,
instruction,
SUM(execution_count),
SUM(successful),
AVG(avg_complete_time),
SUM(init_critical),
SUM(init_major),
SUM(init_minor),
SUM(res_critical),
SUM(res_major),
SUM(res_minor),
SUM(res_ok)
FROM instruction_execution_by_modified_on_to_remove
GROUP BY instruction, instruction_updated;

CREATE UNIQUE INDEX idx_instruction_time ON instruction_execution_by_modified_on (instruction, time);

DROP TABLE instruction_execution_by_modified_on_to_remove;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
BEGIN;

DROP INDEX IF EXISTS idx_instruction_time;
ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove;

CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on
(
time TIMESTAMP NOT NULL,
instruction_updated TIMESTAMP NOT NULL,
instruction VARCHAR(500) NOT NULL,
execution_count INT NOT NULL,
successful INT NOT NULL,
avg_complete_time INT NOT NULL,
init_critical INT NOT NULL DEFAULT 0,
init_major INT NOT NULL DEFAULT 0,
init_minor INT NOT NULL DEFAULT 0,
res_critical INT NOT NULL DEFAULT 0,
res_major INT NOT NULL DEFAULT 0,
res_minor INT NOT NULL DEFAULT 0,
res_ok INT NOT NULL DEFAULT 0
);
SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE);

INSERT INTO instruction_execution_by_modified_on
(
time,
instruction_updated,
instruction,
execution_count,
successful,
avg_complete_time,
init_critical,
init_major,
init_minor,
res_critical,
res_major,
res_minor,
res_ok
)
SELECT
NOW()::date as time,
time as instruction_updated,
instruction,
execution_count,
successful,
avg_complete_time,
init_critical,
init_major,
init_minor,
res_critical,
res_major,
res_minor,
res_ok
FROM instruction_execution_by_modified_on_to_remove;

CREATE UNIQUE INDEX instruction_execution_by_modified_on_instruction_updated_time_idx ON instruction_execution_by_modified_on (instruction, instruction_updated, time);

DROP TABLE instruction_execution_by_modified_on_to_remove;

COMMIT;

0 comments on commit 7c26a8a

Please sign in to comment.