Skip to content

Commit 635d448

Browse files
committed
Add indexes
1 parent 5b4b06a commit 635d448

File tree

1 file changed

+73
-74
lines changed

1 file changed

+73
-74
lines changed

sql/build-tables.sql

+73-74
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
create language plpgsql;
1+
CREATE LANGUAGE plpgsql;
22

33
-- Engler's names of bugs
4-
create table bug_categories (
5-
standardized_name VarChar(256) not null ,
6-
standardized_name_id integer NOT NULL,
4+
CREATE TABLE bug_categories (
5+
standardized_name VarChar(256),
6+
standardized_name_id integer,
77

8-
primary key (standardized_name),
9-
unique (standardized_name_id)
8+
PRIMARY KEY(standardized_name, standardized_name_id)
109
);
1110

1211
-- binding of the errors between us and Engler's ones
13-
create table error_names (
14-
report_error_name VarChar(256) primary key,
15-
standardized_name VarChar(256) not null -- references standardized_names
12+
CREATE TABLE error_names (
13+
report_error_name VarChar(256) PRIMARY KEY,
14+
standardized_name VarChar(256) NOT NULL REFERENCES bug_categories
1615
);
1716

1817
-- binding of the notes between us and Engler's ones
19-
create table note_names (
20-
standardized_name VarChar(256) not null, -- references standardized_names,
21-
note_error_name VarChar(256) not null -- Can not be a primary key. Notes sharing.
18+
CREATE TABLE note_names (
19+
note_error_name VarChar(256) PRIMARY KEY,
20+
standardized_name VarChar(256) NOT NULL REFERENCES bug_categories
2221
);
2322

2423
--
2524
-- Name: dir_names; List of directories to study
2625
--
2726
CREATE TABLE study_dirnames (
28-
study_dirname text primary key,
29-
study_dirname_id int NOT NULL
27+
study_dirname text PRIMARY KEY,
28+
study_dirname_id int NOT NULL
3029
);
3130

3231
-- versions are used to compute the age of a file and to filter versions
33-
create table versions (
34-
version_name VarChar(256) primary key, -- '2.6.33' for example
32+
CREATE TABLE versions (
33+
version_name VarChar(256) PRIMARY KEY, -- '2.6.33' for example
3534
commit_id VarChar(256) , -- revision name
36-
main integer not null, -- 2
37-
major integer not null, -- 6
35+
main integer NOT NULL, -- 2
36+
major integer NOT NULL, -- 6
3837
minor integer, -- 33
39-
release_date date not null, -- used to compute the age of a file
38+
release_date date NOT NULL, -- used to compute the age of a file
4039
locc bigint DEFAULT 0 NOT NULL,-- # of C-code lines
4140

4241
unique (commit_id),
@@ -46,20 +45,20 @@ create table versions (
4645
COMMENT ON COLUMN versions.commit_id IS 'Revision name in the source code manager';
4746

4847
-- Describe of a file
49-
create table file_names (
50-
file_name VarChar(256) primary key,
51-
family_name VarChar(256) not null, -- first part of the directory
52-
type_name VarChar(256) not null, -- second part
53-
impl_name VarChar(256) not null, -- third part
54-
other_name VarChar(256) not null, -- other parts
55-
study_dirname VarChar(256) not null -- the study dir name
48+
CREATE TABLE file_names (
49+
file_name VarChar(256) PRIMARY KEY,
50+
family_name VarChar(256) NOT NULL, -- first part of the directory
51+
type_name VarChar(256) NOT NULL, -- second part
52+
impl_name VarChar(256) NOT NULL, -- third part
53+
other_name VarChar(256) NOT NULL, -- other parts
54+
study_dirname VarChar(256) NOT NULL -- the study dir name
5655
);
5756

5857
-- describe a file with version
59-
create table files (
60-
file_id serial primary key,
61-
file_name VarChar(256) not null references file_names,
62-
version_name VarChar(256) not null references versions,
58+
CREATE TABLE files (
59+
file_id serial PRIMARY KEY,
60+
file_name VarChar(256) NOT NULL REFERENCES file_names,
61+
version_name VarChar(256) NOT NULL REFERENCES versions,
6362
file_size int ,
6463
nb_mods int ,
6564
def_compiled boolean DEFAULT false NOT NULL,
@@ -81,24 +80,23 @@ create table files (
8180
-- );
8281

8382
-- describe a note
84-
create table notes (
85-
note_id serial primary key,
86-
file_id int not null references files,
87-
data_source VarChar(256) not null, -- for update
88-
note_error_name VarChar(256) not null,
89-
line_no int not null,
90-
column_start int not null,
91-
column_end int not null,
83+
CREATE TABLE notes (
84+
note_id serial PRIMARY KEY,
85+
file_id int NOT NULL REFERENCES files,
86+
data_source VarChar(256) NOT NULL, -- for update
87+
note_error_name VarChar(256) NOT NULL,
88+
line_no int NOT NULL,
89+
column_start int NOT NULL,
90+
column_end int NOT NULL,
9291
text_link VarChar(256) , -- text hyperlink
9392

94-
unique (file_id, note_error_name, line_no, column_start)
93+
UNIQUE (file_id, note_error_name, line_no, column_start, column_end)
9594
);
95+
CREATE UNIQUE INDEX note_idx ON notes (file_id, note_error_name, line_no, column_start, column_end);
9696

97-
create table authors (
98-
author_id serial primary key,
99-
author_name VarChar(256) not null,
100-
101-
unique (author_name)
97+
CREATE TABLE authors (
98+
author_id serial PRIMARY KEY,
99+
author_name VarChar(256) UNIQUE NOT NULL
102100
);
103101

104102
-- create table tmp_bug_authors (
@@ -107,45 +105,46 @@ unique (author_name)
107105
-- commit_id VarChar(64) not null
108106
-- );
109107

110-
create table history (
111-
commit_id VarChar(64) primary key,
112-
author_id int not null references authors,
113-
author_date date not null,
114-
committer_id int not null references authors(author_id),
115-
committer_date date not null,
116-
version_name VarChar(256) references versions ON UPDATE CASCADE ON DELETE SET NULL,
108+
CREATE TABLE history (
109+
commit_id VarChar(64) PRIMARY KEY,
110+
author_id int NOT NULL REFERENCES authors,
111+
author_date date NOT NULL,
112+
committer_id int NOT NULL REFERENCES authors(author_id),
113+
committer_date date NOT NULL,
114+
version_name VarChar(256) REFERENCES versions ON UPDATE CASCADE ON DELETE SET NULL,
117115
author_expertise real,
118116
committer_expertise real
119117
);
120118

121119
-- TODO: Add a reference (fkey) to the versions table once the history table is created.
122120

123-
create sequence correlation_idx;
121+
CREATE SEQUENCE correlation_idx;
124122

125123
-- describe a set of correlated reports
126-
create table correlations (
127-
correlation_id int primary key,
128-
report_error_name VarChar(256) not null,
129-
status VarChar(256) not null,
124+
CREATE TABLE correlations (
125+
correlation_id int PRIMARY KEY,
126+
report_error_name VarChar(256) NOT NULL,
127+
status VarChar(256) NOT NULL,
130128
reason_phrase VarChar(256), -- annotation
131-
data_source VarChar(256) not null,
129+
data_source VarChar(256) NOT NULL,
132130
birth_commit_number VarChar(64), -- hash of the commit that introduces the bug
133131
death_commit_number VarChar(64), -- hash of the commit that removes the bug
134132
patch_status VarChar(128) -- status of the fix.
135133
);
136134

137135
-- describe one report
138-
create table reports (
139-
report_id serial primary key,
140-
correlation_id int not null references correlations on delete cascade,
141-
file_id int not null references files on delete cascade,
142-
line_no int not null,
143-
column_start int not null,
144-
column_end int not null,
136+
CREATE TABLE reports (
137+
report_id serial PRIMARY KEY,
138+
correlation_id int NOT NULL REFERENCES correlations ON DELETE CASCADE,
139+
file_id int NOT NULL REFERENCES files ON DELETE CASCADE,
140+
line_no int NOT NULL,
141+
column_start int NOT NULL,
142+
column_end int NOT NULL,
145143
text_link VarChar(256) , -- text hyperlink
146144

147-
unique (report_id, file_id, line_no, column_start)
145+
UNIQUE (report_id, file_id, line_no, column_start, column_end)
148146
);
147+
CREATE UNIQUE INDEX reports_idx ON reports (correlation_id, file_id, line_no, column_start, column_end);
149148

150149
-- describe a position of a note
151150
-- create table report_annotations (
@@ -157,13 +156,13 @@ create table reports (
157156
-- );
158157

159158
-- describe a function
160-
create table functions (
161-
function_id serial primary key,
162-
file_id int not null references files on delete cascade,
163-
function_name VarChar(256) not null,
164-
start int not null,
165-
finish int not null,
166-
167-
unique(file_id, start),
168-
unique(file_id, finish)
159+
CREATE TABLE functions (
160+
function_id serial PRIMARY KEY,
161+
file_id int NOT NULL REFERENCES files ON DELETE CASCADE,
162+
function_name VarChar(256) NOT NULL,
163+
start int NOT NULL,
164+
finish int NOT NULL,
165+
166+
UNIQUE(file_id, start),
167+
UNIQUE(file_id, finish)
169168
);

0 commit comments

Comments
 (0)