Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.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_Sql_Database_Performance - Fatal编程技术网

Mysql 优化慢速查询

Mysql 优化慢速查询,mysql,sql,database,performance,Mysql,Sql,Database,Performance,考虑下面的MySQL语句 SELECT AccountNumber, Currency, Balance FROM clients JOIN balances ON clients.AccountNumber= balances.AccountNumber WHERE date > “2009-01-01” 查询运行缓慢,请描述您将如何尝试解决此问题。使用日期索引列 create index yourIndex on yourTable (date DESC); 试试这

考虑下面的MySQL语句

SELECT AccountNumber, Currency, Balance 
FROM clients 
    JOIN balances ON clients.AccountNumber= balances.AccountNumber  
WHERE date > “2009-01-01”

查询运行缓慢,请描述您将如何尝试解决此问题。

使用日期索引列

create index yourIndex on yourTable (date DESC);
试试这个:

SELECT C.AccountNumber, C.Currency, B.Balance FROM clients C INNER JOIN balances B ON C.AccountNumber=B.AccountNumber WHERE C.date > “2009-01-01”

(我假设:表余额中的余额字段)

日期的聚集索引对初学者来说很好。这假设MySql支持聚集索引(Sybase/Sql server支持)。

您的索引和数据量是什么?请显示创建表。。。对于您的表。什么时间对您来说又慢又快?
余额
需要在
账号
上建立索引,在
日期
上建立另一个索引(假设
日期
不是
客户
表的字段;它在
余额
上更有意义,但无法确定)。请参阅DasbLinkedLight的评论!!假设应用程序只发布了三年,因此所有记录的日期都大于2009年1月1日。那么索引有什么用呢?