Skip to content

Create Index on Environments project_id, state, environment_type

Jason Goodman requested to merge add-index-on-environment-type into master

What does this MR do?

Replace the index on the environments table on project_id, state with one on project_id, state, environment_type.

This is from discussion in !19775 (merged).

See !19775 (comment 242656843)

Issue: #3713 (closed)

This index is meant to optimize the following query (and similar with different id's):

SELECT environments.* FROM (SELECT environments.*, rank() OVER (PARTITION BY project_id ORDER BY id DESC) FROM environments WHERE environments.environment_type IS NULL AND (environments.state IN ('available'::text))) environments WHERE (rank <= 3) AND environments.project_id IN (278964, 7764);

Produced by preloading this association:

has_many :environments_for_dashboard, -> { from(with_rank.unfoldered.available, :environments).where('rank <= 3') }, class_name: 'Environment'

Found in the Environment model: !19775 (diffs)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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
Edited by Jason Goodman

Merge request reports