Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, this <em>may</em> have point on large databases, when you need <strong>fast</strong> responce on <strong>massive</strong> <code>DML</code> (<code>INSERT / UPDATE / DELETE</code>).</p> <p>The problem is that if you rely on database's way to ensure integrity, you hardly can optimize it.</p> <p>There is also thing called <code>SQL/PLSQL context switching</code> in <code>Oracle</code>: if you create an <strong>empty</strong> trigger on the table, it will slow down <code>DML</code> about 20 times — with the mere fact that the trigger exists.</p> <p>In Oracle, when you write a <code>ON UPDATE</code> trigger and update <code>50,000</code> rows in the table, the trigger and the query in it gets called <code>50,000</code> times. Foreign keys perform better, but they may also get laggy (and you can do nothing with the underlying queries)</p> <p>In this case, it's better to put the results you want to update into a temporary table, issue a <code>MERGE</code>, check integrity before and after, and apply the business rules. A single query that processes <code>50,000</code> rows works faster than a loop of <code>50,000</code> queries processing single row.</p> <p>Of course, it's very hard to implement and only pays for itself when you have <em>really</em> large database and need to perform <em>really</em> massive updates on it.</p> <p>In <code>Oracle</code>, in any case, <code>FOREING KEY</code> constraints perform better than tiggers implementing the same functionality.</p> <p><code>PRIMARY KEYS</code> will most likely improve performance, as a primary key implies creating the <code>UNIQUE INDEX</code> on the constrained field, and this index may be efficiently used in the queries. A <code>UNIQUE INDEX</code> is also a natural and most efficent way to enforce uniqueness.</p> <p>But of course, as any index, is slows down <code>INSERTS</code> and those <code>UPDATES</code> and <code>DELETES</code> whose <code>WHERE</code> condition is not selective.</p> <p>I. e. if you need to <code>UPDATE</code> or <code>DELETE</code> <code>1</code> row of <code>2,000,000</code>, then the index is your friend; if you need to <code>UPDATE</code> or <code>DELETE</code> <code>1,500,000</code> rows of <code>2,000,000</code>, the index is your enemy. It's a matter of tradeoff.</p> <p>You may also see my answer <a href="https://stackoverflow.com/questions/543274/is-it-a-best-practise-for-a-database-to-allow-apps-do-crud-operations-always-thro/543503#543503"><strong>here</strong></a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload