Re: Delete performance
От | Tom Lane |
---|---|
Тема | Re: Delete performance |
Дата | |
Msg-id | 22825.1140712500@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: Delete performance (Arnau <arnaulist@andromeiberica.com>) |
Ответы |
Re: Delete performance
|
Список | pgsql-admin |
Arnau <arnaulist@andromeiberica.com> writes: >> The referencED column is forced to have an index. The referencING >> column is not. The cases where you need an index on the latter are >> precisely updates/deletes of the referencED column. > Lets put an example > CREATE TABLE departments > ( > id INT2 > CONSTRAINT pk_dept_id PRIMARY KEY, > name VARCHAR(50) > CONSTRAINT nn_dept_name NOT NULL > ); > CREATE TABLE users > ( > id INT8 > CONSTRAINT pk_users_id PRIMARY KEY, > name VARCHAR(50) > CONSTRAINT nn_users_name NOT NULL, > department_id INT2 > CONSTRAINT fk_users_deptid REFERENCES departments(id) > CONSTRAINT nn_users_deptid NOT NULL > ) > Do we should create the following index? > CREATE INDEX idx_users_deptid ON users(department_id) Yes, if you are concerned about the performance of updates/deletes on the departments table. The reason the system doesn't make such an index automatically is that there are common scenarios where you seldom or never update the master table, and so the index wouldn't repay the cost it creates for updates of the slave table. regards, tom lane
В списке pgsql-admin по дате отправления: