Mysql performance sending data -
i've got table looks this:
id (int, 9, unique key) --- item (int, 3) --- userid (int, 9) --- position (varchar, 12)
now want run folling query:
select count( * ) table position 'bag%' , userid = ".userid."
the possible positions cases "bag0", "bag1", [...], "bag6"
, unique - means there no userid has 2 items in bag2, example.
but it's not unique - example 2 rows having "userid: 82378, positon: 'box1'" possible
if try in()-clause doesn't change result.
the "sending data"-time query 50ms.
do have ideas how modify table query works faster?
this query:
select count( * ) table position 'bag%' , userid = ".userid.";
this pretty simple query. way can speed using index. suggest composite index of table(userid, position)
. mysql should optimize like
because initial prefix constant. but, if want really, sure index gets used, can do:
select count( * ) table position in ('bag0', 'bag1', 'bag2', 'bag3', 'bag4', 'bag5', 'bag6') , userid = ".userid.";
Comments
Post a Comment