I have an ecommerce database running MariaDB + InnoDB, which has a table to store the transactions (T) and another which stores quotes (Q).
I'd like to make a connection between T and Q by adding a foreign key on T referencing Q.
Considering that Q has over 1 million rows (constantly growing) and T about 100k, do you think that adding a foreign key in table T to Q would cause a significant performance impact during daily operation? The alternative would be to add a simple INT column without a foreign key. Or anything else, I'm open to suggestions :)
For the details :
- T has about 20 rows, mainly (SHORT) INTEGERs, some other foreign keys and a couple DateTime fields
- Q has 2 SHORTINT fields and a couple VARCHAR fields (255b each).
Thanks in advance for your insights.
The index on the T table will increase lookup speed at the price of a small hit for inserts.Maybe I should have suggested that the OP perform some tests to quantify the performance gains (lookups) and penalties (inserts) but I believe that the question is answered - only the OP has access to their own data to provide exact metrics for their use case. I would just say that IMHO it is worth paying a high performance price in order to maintain (Declarative Referential) data Dntegrity where the data model warrants it. DRI is best maintained in the RDBMS, not the app! – Vérace Jun 19 '19 at 07:15