Skip to content

Commit

Permalink
[rank] adds path count table for ranking (sourcegraph#47994)
Browse files Browse the repository at this point in the history
Adds table to count the global paths that will be used in the ranking
background jobs.

## Test plan
Tested manually.

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
  • Loading branch information
cesrjimenez committed Feb 21, 2023
1 parent a6181dc commit b70e55a
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
117 changes: 117 additions & 0 deletions internal/database/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,15 @@
"Increment": 1,
"CycleOption": "NO"
},
{
"Name": "codeintel_ranking_path_counts_inputs_id_seq",
"TypeName": "bigint",
"StartValue": 1,
"MinimumValue": 1,
"MaximumValue": 9223372036854775807,
"Increment": 1,
"CycleOption": "NO"
},
{
"Name": "codeintel_ranking_references_id_seq",
"TypeName": "bigint",
Expand Down Expand Up @@ -7576,6 +7585,114 @@
],
"Triggers": []
},
{
"Name": "codeintel_ranking_path_counts_inputs",
"Comment": "",
"Columns": [
{
"Name": "count",
"Index": 4,
"TypeName": "integer",
"IsNullable": false,
"Default": "",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
},
{
"Name": "document_path",
"Index": 3,
"TypeName": "text",
"IsNullable": false,
"Default": "",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
},
{
"Name": "graph_key",
"Index": 5,
"TypeName": "text",
"IsNullable": false,
"Default": "",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
},
{
"Name": "id",
"Index": 1,
"TypeName": "bigint",
"IsNullable": false,
"Default": "nextval('codeintel_ranking_path_counts_inputs_id_seq'::regclass)",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
},
{
"Name": "processed",
"Index": 6,
"TypeName": "boolean",
"IsNullable": false,
"Default": "false",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
},
{
"Name": "repository",
"Index": 2,
"TypeName": "text",
"IsNullable": false,
"Default": "",
"CharacterMaximumLength": 0,
"IsIdentity": false,
"IdentityGeneration": "",
"IsGenerated": "NEVER",
"GenerationExpression": "",
"Comment": ""
}
],
"Indexes": [
{
"Name": "codeintel_ranking_path_counts_inputs_pkey",
"IsPrimaryKey": true,
"IsUnique": true,
"IsExclusion": false,
"IsDeferrable": false,
"IndexDefinition": "CREATE UNIQUE INDEX codeintel_ranking_path_counts_inputs_pkey ON codeintel_ranking_path_counts_inputs USING btree (id)",
"ConstraintType": "p",
"ConstraintDefinition": "PRIMARY KEY (id)"
},
{
"Name": "codeintel_ranking_path_counts_inputs_graph_key_and_repository",
"IsPrimaryKey": false,
"IsUnique": false,
"IsExclusion": false,
"IsDeferrable": false,
"IndexDefinition": "CREATE INDEX codeintel_ranking_path_counts_inputs_graph_key_and_repository ON codeintel_ranking_path_counts_inputs USING btree (graph_key, repository)",
"ConstraintType": "",
"ConstraintDefinition": ""
}
],
"Constraints": null,
"Triggers": []
},
{
"Name": "codeintel_ranking_references",
"Comment": "References for a given upload proceduced by background job consuming SCIP indexes.",
Expand Down
16 changes: 16 additions & 0 deletions internal/database/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,22 @@ Foreign-key constraints:
```

# Table "public.codeintel_ranking_path_counts_inputs"
```
Column | Type | Collation | Nullable | Default
---------------+---------+-----------+----------+------------------------------------------------------------------
id | bigint | | not null | nextval('codeintel_ranking_path_counts_inputs_id_seq'::regclass)
repository | text | | not null |
document_path | text | | not null |
count | integer | | not null |
graph_key | text | | not null |
processed | boolean | | not null | false
Indexes:
"codeintel_ranking_path_counts_inputs_pkey" PRIMARY KEY, btree (id)
"codeintel_ranking_path_counts_inputs_graph_key_and_repository" btree (graph_key, repository)
```

# Table "public.codeintel_ranking_references"
```
Column | Type | Collation | Nullable | Default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS codeintel_ranking_path_counts_inputs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: add_codeintel_rank_path_counts_inputs
parents: [1677005673]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS codeintel_ranking_path_counts_inputs (
id bigserial PRIMARY KEY NOT NULL,
repository text NOT NULL,
document_path text NOT NULL,
count int NOT NULL,
graph_key text NOT NULL,
processed boolean NOT NULL DEFAULT false
);

CREATE INDEX IF NOT EXISTS codeintel_ranking_path_counts_inputs_graph_key_and_repository ON codeintel_ranking_path_counts_inputs (graph_key, repository);
25 changes: 25 additions & 0 deletions migrations/frontend/squashed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,24 @@ CREATE SEQUENCE codeintel_ranking_exports_id_seq

ALTER SEQUENCE codeintel_ranking_exports_id_seq OWNED BY codeintel_ranking_exports.id;

CREATE TABLE codeintel_ranking_path_counts_inputs (
id bigint NOT NULL,
repository text NOT NULL,
document_path text NOT NULL,
count integer NOT NULL,
graph_key text NOT NULL,
processed boolean DEFAULT false NOT NULL
);

CREATE SEQUENCE codeintel_ranking_path_counts_inputs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE codeintel_ranking_path_counts_inputs_id_seq OWNED BY codeintel_ranking_path_counts_inputs.id;

CREATE TABLE codeintel_ranking_references (
id bigint NOT NULL,
upload_id integer NOT NULL,
Expand Down Expand Up @@ -4187,6 +4205,8 @@ ALTER TABLE ONLY codeintel_ranking_definitions ALTER COLUMN id SET DEFAULT nextv

ALTER TABLE ONLY codeintel_ranking_exports ALTER COLUMN id SET DEFAULT nextval('codeintel_ranking_exports_id_seq'::regclass);

ALTER TABLE ONLY codeintel_ranking_path_counts_inputs ALTER COLUMN id SET DEFAULT nextval('codeintel_ranking_path_counts_inputs_id_seq'::regclass);

ALTER TABLE ONLY codeintel_ranking_references ALTER COLUMN id SET DEFAULT nextval('codeintel_ranking_references_id_seq'::regclass);

ALTER TABLE ONLY configuration_policies_audit_logs ALTER COLUMN sequence SET DEFAULT nextval('configuration_policies_audit_logs_seq'::regclass);
Expand Down Expand Up @@ -4425,6 +4445,9 @@ ALTER TABLE ONLY codeintel_ranking_definitions
ALTER TABLE ONLY codeintel_ranking_exports
ADD CONSTRAINT codeintel_ranking_exports_pkey PRIMARY KEY (id);

ALTER TABLE ONLY codeintel_ranking_path_counts_inputs
ADD CONSTRAINT codeintel_ranking_path_counts_inputs_pkey PRIMARY KEY (id);

ALTER TABLE ONLY codeintel_ranking_references
ADD CONSTRAINT codeintel_ranking_references_pkey PRIMARY KEY (id);

Expand Down Expand Up @@ -4857,6 +4880,8 @@ CREATE INDEX codeintel_ranking_definitions_upload_id ON codeintel_ranking_defini

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_and_repository ON codeintel_ranking_path_counts_inputs USING btree (graph_key, repository);

CREATE INDEX codeintel_ranking_references_upload_id ON codeintel_ranking_references USING btree (upload_id);

CREATE INDEX configuration_policies_audit_logs_policy_id ON configuration_policies_audit_logs USING btree (policy_id);
Expand Down

0 comments on commit b70e55a

Please sign in to comment.