mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:11:49 +00:00
ranking: Make counts per definition unique (#52949)
This commit is contained in:
parent
af135d87bf
commit
85bbc9357f
@ -195,12 +195,14 @@ referenced_definitions AS (
|
||||
GROUP BY s.definition_id
|
||||
),
|
||||
ins AS (
|
||||
INSERT INTO codeintel_ranking_path_counts_inputs (definition_id, count, graph_key)
|
||||
INSERT INTO codeintel_ranking_path_counts_inputs AS target (graph_key, definition_id, count, processed)
|
||||
SELECT
|
||||
%s,
|
||||
rx.definition_id,
|
||||
rx.count,
|
||||
%s
|
||||
false
|
||||
FROM referenced_definitions rx
|
||||
ON CONFLICT (graph_key, definition_id) WHERE NOT processed DO UPDATE SET count = target.count + EXCLUDED.count
|
||||
RETURNING 1
|
||||
),
|
||||
set_progress AS (
|
||||
@ -336,11 +338,12 @@ expanded_unprocessed_path_counts AS (
|
||||
FROM unprocessed_path_counts upc
|
||||
),
|
||||
ins AS (
|
||||
INSERT INTO codeintel_ranking_path_counts_inputs (definition_id, count, graph_key)
|
||||
INSERT INTO codeintel_ranking_path_counts_inputs (graph_key, definition_id, count, processed)
|
||||
SELECT
|
||||
%s,
|
||||
rd.id,
|
||||
0,
|
||||
%s
|
||||
false
|
||||
FROM locked_path_counts lpc
|
||||
JOIN expanded_unprocessed_path_counts eupc ON eupc.id = lpc.codeintel_initial_path_ranks_id
|
||||
JOIN codeintel_ranking_definitions rd ON
|
||||
@ -349,6 +352,7 @@ ins AS (
|
||||
WHERE
|
||||
rd.graph_key = %s AND
|
||||
rd.symbol_name = '$'
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING 1
|
||||
),
|
||||
set_progress AS (
|
||||
|
||||
@ -442,7 +442,7 @@ func TestVacuumStaleGraphs(t *testing.T) {
|
||||
}
|
||||
if _, err := db.ExecContext(ctx, `
|
||||
INSERT INTO codeintel_ranking_path_counts_inputs (definition_id, count, graph_key)
|
||||
SELECT 0, 100, $1 FROM generate_series(1, 30)
|
||||
SELECT v, 100, $1 FROM generate_series(1, 30) AS v
|
||||
`, graphKey); err != nil {
|
||||
t.Fatalf("failed to insert ranking path count inputs: %s", err)
|
||||
}
|
||||
|
||||
@ -491,7 +491,7 @@ pollIndexStatusLoop:
|
||||
// of the index.
|
||||
|
||||
var (
|
||||
pgErr pgconn.PgError
|
||||
pgErr *pgconn.PgError
|
||||
raceDetected bool
|
||||
|
||||
errorFilter = func(err error) error {
|
||||
|
||||
@ -8245,6 +8245,16 @@
|
||||
}
|
||||
],
|
||||
"Indexes": [
|
||||
{
|
||||
"Name": "codeintel_ranking_path_counts_inputs_graph_key_unique_definitio",
|
||||
"IsPrimaryKey": false,
|
||||
"IsUnique": true,
|
||||
"IsExclusion": false,
|
||||
"IsDeferrable": false,
|
||||
"IndexDefinition": "CREATE UNIQUE INDEX codeintel_ranking_path_counts_inputs_graph_key_unique_definitio ON codeintel_ranking_path_counts_inputs USING btree (graph_key, definition_id) WHERE NOT processed",
|
||||
"ConstraintType": "",
|
||||
"ConstraintDefinition": ""
|
||||
},
|
||||
{
|
||||
"Name": "codeintel_ranking_path_counts_inputs_pkey",
|
||||
"IsPrimaryKey": true,
|
||||
@ -8255,16 +8265,6 @@
|
||||
"ConstraintType": "p",
|
||||
"ConstraintDefinition": "PRIMARY KEY (id)"
|
||||
},
|
||||
{
|
||||
"Name": "codeintel_ranking_path_counts_inputs_graph_key_definition_id",
|
||||
"IsPrimaryKey": false,
|
||||
"IsUnique": false,
|
||||
"IsExclusion": false,
|
||||
"IsDeferrable": false,
|
||||
"IndexDefinition": "CREATE INDEX codeintel_ranking_path_counts_inputs_graph_key_definition_id ON codeintel_ranking_path_counts_inputs USING btree (graph_key, definition_id, id) WHERE NOT processed",
|
||||
"ConstraintType": "",
|
||||
"ConstraintDefinition": ""
|
||||
},
|
||||
{
|
||||
"Name": "codeintel_ranking_path_counts_inputs_graph_key_id",
|
||||
"IsPrimaryKey": false,
|
||||
|
||||
@ -1021,7 +1021,7 @@ Indexes:
|
||||
definition_id | bigint | | |
|
||||
Indexes:
|
||||
"codeintel_ranking_path_counts_inputs_pkey" PRIMARY KEY, btree (id)
|
||||
"codeintel_ranking_path_counts_inputs_graph_key_definition_id" btree (graph_key, definition_id, id) WHERE NOT processed
|
||||
"codeintel_ranking_path_counts_inputs_graph_key_unique_definitio" UNIQUE, btree (graph_key, definition_id) WHERE NOT processed
|
||||
"codeintel_ranking_path_counts_inputs_graph_key_id" btree (graph_key, id)
|
||||
|
||||
```
|
||||
|
||||
6
migrations/BUILD.bazel
generated
6
migrations/BUILD.bazel
generated
@ -1026,6 +1026,12 @@ go_library(
|
||||
"frontend/1685727930_junk_cleanup/down.sql",
|
||||
"frontend/1685727930_junk_cleanup/metadata.yaml",
|
||||
"frontend/1685727930_junk_cleanup/up.sql",
|
||||
"frontend/1685983690_make_path_count_inputs_unique_by_definition_id/down.sql",
|
||||
"frontend/1685983690_make_path_count_inputs_unique_by_definition_id/metadata.yaml",
|
||||
"frontend/1685983690_make_path_count_inputs_unique_by_definition_id/up.sql",
|
||||
"frontend/1685984018_drop_duplicate_index/down.sql",
|
||||
"frontend/1685984018_drop_duplicate_index/metadata.yaml",
|
||||
"frontend/1685984018_drop_duplicate_index/up.sql",
|
||||
"frontend/1686042710_add_assigned_teams_table/down.sql",
|
||||
"frontend/1686042710_add_assigned_teams_table/metadata.yaml",
|
||||
"frontend/1686042710_add_assigned_teams_table/up.sql",
|
||||
|
||||
@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS codeintel_ranking_path_counts_inputs_graph_key_unique_definition_id;
|
||||
@ -0,0 +1,2 @@
|
||||
name: Make path count inputs unique by definition_id.
|
||||
parents: [1685695443, 1685697346, 1685712730, 1684858266]
|
||||
@ -0,0 +1,3 @@
|
||||
UPDATE codeintel_ranking_path_counts_inputs SET processed = true WHERE NOT processed;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS codeintel_ranking_path_counts_inputs_graph_key_unique_definition_id ON codeintel_ranking_path_counts_inputs(graph_key, definition_id) WHERE NOT processed;
|
||||
@ -0,0 +1 @@
|
||||
CREATE INDEX IF NOT EXISTS codeintel_ranking_path_counts_inputs_graph_key_definition_id ON codeintel_ranking_path_counts_inputs(graph_key, definition_id, id) WHERE NOT processed;
|
||||
@ -0,0 +1,2 @@
|
||||
name: Drop duplicate index.
|
||||
parents: [1685983690]
|
||||
@ -0,0 +1 @@
|
||||
DROP INDEX IF EXISTS codeintel_ranking_path_counts_inputs_graph_key_definition_id;
|
||||
@ -5706,10 +5706,10 @@ CREATE INDEX codeintel_ranking_exports_graph_key_last_scanned_at ON codeintel_ra
|
||||
|
||||
CREATE UNIQUE INDEX codeintel_ranking_exports_graph_key_upload_id ON codeintel_ranking_exports USING btree (graph_key, upload_id);
|
||||
|
||||
CREATE INDEX codeintel_ranking_path_counts_inputs_graph_key_definition_id ON codeintel_ranking_path_counts_inputs USING btree (graph_key, definition_id, id) WHERE (NOT processed);
|
||||
|
||||
CREATE INDEX codeintel_ranking_path_counts_inputs_graph_key_id ON codeintel_ranking_path_counts_inputs USING btree (graph_key, id);
|
||||
|
||||
CREATE UNIQUE INDEX codeintel_ranking_path_counts_inputs_graph_key_unique_definitio ON codeintel_ranking_path_counts_inputs USING btree (graph_key, definition_id) WHERE (NOT processed);
|
||||
|
||||
CREATE INDEX codeintel_ranking_references_exported_upload_id ON codeintel_ranking_references USING btree (exported_upload_id);
|
||||
|
||||
CREATE INDEX codeintel_ranking_references_graph_key_id ON codeintel_ranking_references USING btree (graph_key, id);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user