Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The big question is, what will this table be used for? If the only queries are going to be ranges of ORDER_IDs or aggregates on ITEM_IDs, then you just need individual indexes on those columns. Make the QUEUE_ID the primary key (since auto increment ensures the unique and not null anyway). Try the following:</p> <p>Update: As per the OP's comment below, there can be multiple order ids per customer and vice versa, but the combination has to be unique. IMO, it is easier to create a satellite table with the unique constraint satisfied, and use the index from that table in this <code>slots</code> table.</p> <pre><code>CREATE TABLE cust_order ( combo_id int(11) NOT NULL AUTO_INCREMENT, customerid int(11) NOT NULL, orderid int(11) NOT NULL, PRIMARY KEY combo_id, INDEX customerid (customerid), INDEX orderid (orderid), UNIQUE KEY combination (customerid, orderid) ) ENGINE=INNODB; CREATE TABLE `slots` ( `combo_id` int(11) NOT NULL, `queueid` int(11) NOT NULL AUTO_INCREMENT, `item_id` int(3) NOT NULL, `variable1` int(3) NOT NULL, ... ... `variable9` tinyint(1) NOT NULL, PRIMARY KEY `queueid`, INDEX `combo_id` (`combo_id`), INDEX `itemid` (`itemid`), FOREIGN KEY (combo_id) REFERENCES cust_order (combo_id) ) ENGINE=INNODB; </code></pre> <p>You have to run two different insert queries. First, you load the combo table, which takes care of just the numerical index without the satellite data and it should be really fast. Afterwards, when you insert into the <code>slots</code>, lookup via the customerid + orderid will be really fast and you just use the combo_id as the foreign key.</p> <p><strong>Please note</strong> that you must use the InnoDB engine for the Foreign Keys to work.</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. This table or related slice is empty.
    1. 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