Issue metrics run UPDATE queries that will never update anything
Today I found the following in pg_stat_activity
:
gitlabhq_production=# select pid, query_start, now() - query_start, query from pg_stat_activity where query like 'UPDATE%';
pid | query_start | ?column? | query
-------+-------------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
51735 | 2017-03-15 15:33:23.27935+00 | 00:00:00.700402 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 15:24:56.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
44192 | 2017-03-15 15:33:20.043223+00 | 00:00:03.936529 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 15:12:47.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
44000 | 2017-03-15 15:33:21.784576+00 | 00:00:02.195176 | UPDATE "merge_request_metrics" SET "latest_build_started_at" = '2017-03-15 15:25:04.215455', "latest_build_finished_at" = '2017-03-15 15:33:20.386195', "pipeline_id" = 7035697 WHERE 1=0
33443 | 2017-03-15 15:24:58.184939+00 | 00:08:25.794813 | UPDATE "projects" SET "import_error" = 'The mirror user is not allowed to push code to all branches on this project.' WHERE "projects"."id" = $1
36139 | 2017-03-15 15:33:20.431943+00 | 00:00:03.547809 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 14:40:17.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
36137 | 2017-03-15 15:33:20.662963+00 | 00:00:03.316789 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 15:33:09.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
41699 | 2017-03-15 15:33:23.863313+00 | 00:00:00.116439 | UPDATE "merge_request_metrics" SET "latest_build_started_at" = '2017-03-15 15:30:57.052251', "latest_build_finished_at" = '2017-03-15 15:33:23.733820', "pipeline_id" = 7035833 WHERE 1=0
30204 | 2017-03-15 15:33:23.262776+00 | 00:00:00.716976 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-14 01:45:56.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
30201 | 2017-03-15 15:33:23.978176+00 | 00:00:00.001576 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 15:33:17.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
29985 | 2017-03-15 15:33:23.496694+00 | 00:00:00.483058 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-15 14:45:36.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
29984 | 2017-03-15 15:33:23.274293+00 | 00:00:00.705459 | UPDATE "issue_metrics" SET "first_mentioned_in_commit_at" = '2017-03-14 02:58:35.000000' WHERE 1=0 AND "issue_metrics"."first_mentioned_in_commit_at" IS NULL
Some of these UPDATEs use WHERE 1=0 AND ...
which translates to WHERE false AND ...
. This means we're running useless queries that will never update anything.