Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让MySQL使用我创建的索引_Mysql_Database_Performance_Indexing - Fatal编程技术网

如何让MySQL使用我创建的索引

如何让MySQL使用我创建的索引,mysql,database,performance,indexing,Mysql,Database,Performance,Indexing,我有一个名为t_的表,它有一个名为index_cpn_endvalidity的索引 抱歉,我无法更好地查看我的查询结果 MySQL从不使用此索引。。。 例如,下面是一个简单查询的解释结果 explain select * from t_owecoupon where endvalidity > date('2015-01-01'); +----+-------------+-------------+------+------------------+------+---------+--

我有一个名为t_的表,它有一个名为index_cpn_endvalidity的索引

抱歉,我无法更好地查看我的查询结果 MySQL从不使用此索引。。。 例如,下面是一个简单查询的解释结果

explain select * from t_owecoupon where endvalidity > date('2015-01-01');
+----+-------------+-------------+------+------------------+------+---------+------+--------+-------------+
| id | select_type | table       | type | possible_keys    | key  | key_len | ref  | rows   | Extra       |
+----+-------------+-------------+------+------------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | t_owecoupon | ALL  | index_cpn_endval | NULL | NULL    | NULL | 307017 | Using where |
+----+-------------+-------------+------+------------------+------+---------+------+--------+-------------+
输出总是一样的,它说我可以在可能的键中使用我想要的索引。。。上面的查询就是一个例子,我有一个更复杂的查询,它也不使用索引

我尝试过:使用索引、按索引列分组、按索引列排序,但解释的输出总是相同的

如何让MySQL使用我的索引

谢谢你的帮助

真正的疑问-

SELECT  
    date_format(endvalidity,'%Y-%m') as mois, cpn.ABONNE_id, cpn.statut, regulation, cpn.id
    FROM powecpn.t_owecoupon as cpn, t_oweabonne as abo
    WHERE cpn.ABONNE_id = abo.ID
    and abo.usi != '0000000000'
    and date_format(DATE_ADD(endvalidity, INTERVAL 6 MONTH),'%Y-%m') > @DATE_ANNEE_MOIS
    and endvalidity < DATE_ADD(LAST_DAY(str_to_date(CONCAT(@DATE_ANNEE_MOIS,'-1'),"%Y-%m-%d")),INTERVAL 1 DAY)
    group by mois, cpn.ABONNE_id, cpn.ID

请显示索引的定义。不要使用日期函数。以字符串形式传递日期请在查询中指明endvalidity在哪个表中。请提供“显示创建表”。@DATE\u ANNEE\u MOIS来自哪里?在第一次查询中,表中与endvalidity>DATE'2015-01-01'匹配的百分比是多少?索引基数值是多少?
SELECT  
    date_format(endvalidity,'%Y-%m') as mois, cpn.ABONNE_id, cpn.statut, regulation, cpn.id
    FROM powecpn.t_owecoupon as cpn, t_oweabonne as abo
    WHERE cpn.ABONNE_id = abo.ID
    and abo.usi != '0000000000'
    and date_format(DATE_ADD(endvalidity, INTERVAL 6 MONTH),'%Y-%m') > @DATE_ANNEE_MOIS
    and endvalidity < DATE_ADD(LAST_DAY(str_to_date(CONCAT(@DATE_ANNEE_MOIS,'-1'),"%Y-%m-%d")),INTERVAL 1 DAY)
    group by mois, cpn.ABONNE_id, cpn.ID