covering-index

MySQL select seems very slow but cannot think how to improve?

巧了我就是萌 提交于 2019-12-18 09:47:22
问题 I have a single table with four columns... `id` INT(11) NOT NULL AUTO_INCREMENT `tid` INT(11) NOT NULL `cid` INT(11) NOT NULL `name` NVARCHAR(4096) NULL DEFAULT NULL id is the unique primary key. The other columns are not unique. I want to return the list of all id values that have specific tid and cid values and are sorted by the name. So this... select id from myTable where cid = 1 && tid = 1 order by name There are about 125k records in the table and there should be around 50k that happen

Does compound index have direction in MySQL?

风流意气都作罢 提交于 2019-12-11 08:25:45
问题 When will the below be necessary: create index i_t_a_b on t(a,b); create index i_t_b_a on t(b,a); 回答1: When you want the maximum retrieval speed and have both columns in the join or where conditions, BUT sometimes column a has higher selectivity and sometimes column b has higher selectivity, and you want to capitalize on that fact from single index. Also I think your ratio of data size / performance of the machine should be quite high and at the same time you will have to (guesstimating) be

Proper field orders for covering index - MySQL

我的梦境 提交于 2019-12-11 01:57:20
问题 Is there a standard order to create a covering index for a table in MySQL? Meaning if I have query that has a where clause, order by and the fields in the select statement, in what order would I have the fields to the index to properly create a covering index? 回答1: A covering index takes a list of columns in a comma separated list. This list is traversed/reviewed starting at the left side. If the left most column is not used, the index is not used. Meaning, having a column list like: col_a,

MySQL select seems very slow but cannot think how to improve?

丶灬走出姿态 提交于 2019-11-29 18:10:57
I have a single table with four columns... `id` INT(11) NOT NULL AUTO_INCREMENT `tid` INT(11) NOT NULL `cid` INT(11) NOT NULL `name` NVARCHAR(4096) NULL DEFAULT NULL id is the unique primary key. The other columns are not unique. I want to return the list of all id values that have specific tid and cid values and are sorted by the name. So this... select id from myTable where cid = 1 && tid = 1 order by name There are about 125k records in the table and there should be around 50k that happen to match this criteria. All four columns have individual indexes. On my machine the query takes around

Mysql covering vs composite vs column index

我们两清 提交于 2019-11-27 11:47:32
In the following query SELECT col1,col2 FROM table1 WHERE col3='value1' AND col4='value2' If I have 2 separate indexes one on col3 and the other on col4 , Which one of them will be used in this query ? I read somewhere that for each table in the query only one index is used. Does that mean that there is no way for the query to use both indexes ? Secondly, If I created a composite index using both col3 and col4 together but used only col3 in the WHERE clause will that be worse for the performance? example: SELECT col1,col2 FROM table1 WHERE col3='value1' Lastly, Is it better to just use

Mysql covering vs composite vs column index

 ̄綄美尐妖づ 提交于 2019-11-26 12:58:46
问题 In the following query SELECT col1,col2 FROM table1 WHERE col3=\'value1\' AND col4=\'value2\' If I have 2 separate indexes one on col3 and the other on col4 , Which one of them will be used in this query ? I read somewhere that for each table in the query only one index is used. Does that mean that there is no way for the query to use both indexes ? Secondly, If I created a composite index using both col3 and col4 together but used only col3 in the WHERE clause will that be worse for the