<div dir="ltr"><div>There's this table: vtiger_inventorychargesrel</div><div>When creating an invoice (I suspect the same applies for other inventory modules), a query like this gets executed several times:</div><div><br></div><div>SELECT * FROM vtiger_inventorychargesrel WHERE recordid = 4535638<br></div><div><br></div><div>On a large DB with 1.5 million records on that table, each such query takes ~0.6 seconds. The creation of a single invoice was taking around 6 seconds.</div><div><br></div><div>The table is created here modules/Migration/schema/660_to_700.php with this query:</div><div>CREATE TABLE vtiger_inventorychargesrel(recordid INT(19) NOT NULL, charges TEXT)<br></div><div><br></div><div>As far as I can tell, there should be a single record  per invoice, so I added a primary key with:</div><div>ALTER TABLE vtiger_inventorychargesrel ADD PRIMARY KEY(recordid)</div><div><br></div><div>After that, creation of new invoices was taking 300 milliseconds instead of 6 seconds.</div><div><br></div><div>Why was that table created without a primary key or an index? Was it just overlooked / forgotten or is there a good reason for it?</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Saludos<div><br></div><div>Rubén</div></div></div></div></div></div>