So i have a question.
Say you have a table requests, which represent a graph. There are 3 columns in the request table, A, B, time. A -> B At time. So what each row represents is a directed connection from A (the requestor) to B (the requestee) at Time T (time is just for organizing data, not really for anything else).
So what is faster if say requests were 1,000,000 rows.
Index(A, B)
Index(A) and Index(B)
Unique(A, B)?
Thanks guys! And A, B are VARCHAR(32) (MD5’s)
Sorry, i forgot a typical query.
I need to be able to see if User A (who logged on) has any requests!
I also will need to search to verify that a user has accepted a correct request, A Accepts B.
So the statements will look like.
Any new requests?
SELECT B, time
FROM requests
WHERE A='$id';
Does A have a request from B?
SELECT time
FROM requests
WHERE A='$A' and B='$B';
In this specific case, use a composite index including A and B. Make sure that A is first in the index. That way when you run these two queries, the index would be used for both.
More on composite indexes:
http://dev.mysql.com/doc/refman/5.5/en/multiple-column-indexes.html
Also, uniqueness (A,B) shouldn’t matter unless your requirement is that B can only request A at most once.