On 24 Apr 2017, at 3:20pm, Clemens Ladisch <clem...@ladisch.de> wrote:

> Bubu Bubu wrote:
>> Can someone tell me if there can really be performance issues when one uses
>> foreign keys in their database?
> 
> The documentation <http://www.sqlite.org/foreignkeys.html#fk_indexes>
> warns against a case where some operations can be slow if you do not
> have an index on the child key.

Yeah.  To do FOREIGN KEYs with speed you need two indexes: a UNIQUE one on the 
parent key columns and one on the child key columns.  To understand why you 
need the one on the child table, consider what should happen if you delete a 
row in the parent table.

> But if you have all suggested indexes, then all the checks done to
> enforce (foreign key) constraints are simple index lookups.  These are
> mostly harmless, unless the number of rows you are changing is so large
> that all the individual operations add up to something noticeable.
> (If you predict that that happens, you can simply disable foreign key
> constraint checks.)

Right.  As this post and others have mentioned, there will be a small increase 
in time taken, but this increase is tiny compared to any other way of ensuring 
integrity.  FOREIGN KEYs really are the most efficient way to do this.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to