Harden operations_dashboard_default_dashboard usage query
requested to merge 220479-harden-operations_dashboard_default_dashboard-usage-data-queries into master
What does this MR do?
Harden operations_dashboard_default_dashboard usage data query by using precomputed user min/max id range
Query MIN
SELECT MIN("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513'
https://explain.depesz.com/s/LBDPU 406 seconds
Before:After: precomputed value
Query MAX
SELECT MAX("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513'
https://explain.depesz.com/s/9qYN
Before:After: precomputed value
Query Count
SELECT COUNT("users"."id") FROM "users" WHERE ("users"."state" IN ('active')) AND ("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) AND "users"."dashboard" = 8 AND "users"."created_at" BETWEEN '2020-05-08 11:17:49.312323' AND '2020-06-05 11:17:49.312513' AND "users"."id" BETWEEN 0 AND 9999
https://explain.depesz.com/s/31Cx 337 milliseconds for a batch of 10K which is fine
Before:Timing less than 5 seconds on gitlab.com
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Closes #220479 (closed)
Edited by Alper Akgun