【发布时间】:2013-03-26 09:55:56
【问题描述】:
我写了一个查询,需要 30 多秒。
我的代码:
MySqlConnection myConnection = new MySqlConnection(ConfigurationSettings.AppSettings["CollectiveIntelligence"]);
string query = @"SELECT TBL.NAME1,
TBL.NAME2
FROM (SELECT MLD1.LOGIN_NAME AS NAME1,
MLD2.LOGIN_NAME AS NAME2
FROM FEDERATED_M_LOGIN_DETAILS MLD1
JOIN FEDERATED_M_LOGIN_DETAILS MLD2
WHERE MLD1.LOGIN_NAME < MLD2.LOGIN_NAME
ORDER BY NAME1,NAME2) TBL
WHERE NOT EXISTS (SELECT USER_NAME1,
USER_NAME2
FROM CONNECTION C
WHERE (C.USER_NAME1 = TBL.NAME1 AND C.USER_NAME2 = TBL.NAME2));";
MySqlCommand myCommand = new MySqlCommand(query, myConnection);
//Open Connection
myConnection.Open();
myCommand.CommandTimeout = 0;
MySqlDataReader reader = myCommand.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
GridView1.DataSource = dt;
GridView1.DataBind();
myConnection.Close();
reader.Close();
发生错误
MySqlDataReader reader = myCommand.ExecuteReader();
错误消息:超时。在操作完成之前超时时间已过或服务器没有响应
如何增加asp.net的执行超时时间以便执行查询/
[编辑]
当我点击解释它的显示是这样的
id select_type table type possible_keys key key_len ref rows Extra
1, SIMPLE, MLD1, ALL, , , , , 295, Using temporary; Using filesort
1, SIMPLE, MLD2, ALL, , , , , 295, Using where; Using join buffer
1, SIMPLE, C, index, , INDEX_CONNECTION, 94, , 30754, Using where; Using index; Not exists
[/编辑]
请帮忙
提前致谢
【问题讨论】:
-
在您的查询中,您在没有任何条件的情况下加入表,这会导致交叉连接和较长的执行时间。先尝试优化你的查询,不需要增加执行时间..
-
@Meherzad:我已经问过这个问题如何减少时间链接:stackoverflow.com/questions/15616638/…