Re: contrib idea
От | Bruce Momjian |
---|---|
Тема | Re: contrib idea |
Дата | |
Msg-id | 200201030625.g036PqR16995@candle.pha.pa.us обсуждение исходный текст |
Ответ на | Re: contrib idea (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
Tom Lane wrote: > Bruce Momjian <pgman@candle.pha.pa.us> writes: > >> If you have a foreign key on a column, then whenever the primary key is > >> modified, the following checks may occur: > >> > >> * Check to see if the child row exists (no action) > >> * Delete the child row (cascade delete) > >> * Update the child row (cascade update) > >> > >> All of which will benefit from an index... > > > OK, then perhaps we should be creating an index automatically? Folks? > > We should not *force* people to have an index. If the master table very > seldom changes, then an index on the referencing table will be a net > loss (at least as far as the foreign-key ops go). You'll pay for it on > every referencing-table update, and use it only seldom. > > Possibly there should be an entry in the "performance tips" chapter > recommending that people consider adding an index on the referencing > column if they are concerned about the speed of updates to the > referenced table. But I dislike software that considers itself smarter > than the DBA. OK, I have added the following to the create_lang.sgml manual page. I couldn't find a good place to put this in the performance page. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 Index: doc/src/sgml/ref/create_table.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v retrieving revision 1.50 diff -c -r1.50 create_table.sgml *** doc/src/sgml/ref/create_table.sgml 2001/12/08 03:24:35 1.50 --- doc/src/sgml/ref/create_table.sgml 2002/01/03 06:23:36 *************** *** 437,442 **** --- 437,449 ---- </varlistentry> </variablelist> </para> + <para> + If primary key column is updated frequently, it may be wise to + add an index to the <literal>REFERENCES</literal> column so that + <literal>NO ACTION</literal> and <literal>CASCADE</literal> + actions associated with the <literal>REFERENCES</literal> + column can be more efficiently performed. + </para> </listitem> </varlistentry> *************** *** 472,477 **** --- 479,486 ---- </listitem> </varlistentry> </variablelist> + + </refsect1>
В списке pgsql-hackers по дате отправления: