Skip to content

Zoekt: Add cross-namespace search

Dmitry Gruzd requested to merge 389748-zoekt-cross-namespace-search into master

What does this MR do and why?

This MR introduces an initial (naive) implementation of Zoekt cross-namespace search behind a feature flag.

Performance-wise it should be ok for medium-sized instances.

#389748 (closed)

Database queries

SELECT "zoekt_node_id", array_agg(projects.id) FROM "projects" INNER JOIN "namespaces" ON "namespaces"."id" = "projects"."namespace_id" INNER JOIN zoekt_indices ON zoekt_indices.namespace_id = namespaces.traversal_ids[1] INNER JOIN zoekt_enabled_namespaces ON zoekt_indices.zoekt_enabled_namespace_id = zoekt_enabled_namespaces.id WHERE (EXISTS (SELECT 1 FROM "project_authorizations" WHERE "project_authorizations"."user_id" = 5054237 AND (project_authorizations.project_id = projects.id)) OR projects.visibility_level IN (10,20)) AND "projects"."pending_delete" = FALSE AND "projects"."hidden" = FALSE AND "zoekt_indices"."namespace_id" IN (9970, 6543) AND "zoekt_enabled_namespaces"."search" = TRUE AND "zoekt_indices"."state" = 10 GROUP BY "zoekt_node_id";

https://postgres.ai/console/gitlab/gitlab-production-main/sessions/27290/commands/84839

Click to see old queries

::Search::Zoekt::Index.searchable.namespace_targets

SELECT "zoekt_indices"."zoekt_node_id", "zoekt_indices"."namespace_id" FROM "zoekt_indices" INNER JOIN "zoekt_enabled_namespaces" "zoekt_enabled_namespace" ON "zoekt_enabled_namespace"."id" = "zoekt_indices"."zoekt_enabled_namespace_id" WHERE "zoekt_indices"."state" = 10 AND "zoekt_enabled_namespace"."search" = TRUE AND "zoekt_indices"."id" >= 2 AND "zoekt_indices"."id" < 1991

https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/27070/commands/84155

::Search::Zoekt::Index.searchable.maximum(:updated_at)

No longer used

SELECT MAX("zoekt_indices"."updated_at") FROM "zoekt_indices" INNER JOIN "zoekt_enabled_namespaces" "zoekt_enabled_namespace" ON "zoekt_enabled_namespace"."id" = "zoekt_indices"."zoekt_enabled_namespace_id" WHERE "zoekt_indices"."state" = 10 AND "zoekt_enabled_namespace"."search" = TRUE

https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/27070/commands/84150

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Example below:

  1. Enable Zoekt for at least 2 namespaces
  2. In rails console enable the FF
    Feature.enable(:zoekt_cross_namespace_search)
  3. Perform a global code search
  4. Ensure that you can see the results from multiple top-level namespaces
Edited by Dmitry Gruzd

Merge request reports