我正在研究查詢MySQL數據庫的C#WinForm應用程序。查詢所需的時間令人難以置信,速度很慢(30秒 - 1分鐘)。我對DB的經驗很少,我似乎無法弄清楚我的查詢有什麼問題。有人可以指出我做錯了什麼。查詢運行速度太慢
string sql = "SELECT t1.date, t1.name, t2.name, t3.addrs
FROM tbl1 t1 JOIN tbl2 t2 ON tbl1.id = tbl2.id
JOIN tbl3 t3 ON t3.addrs = t2.addrs WHERE t1.date = '2013-04-01';";
string connStr = "Server = 10.10.10.100; Database = mydb; etc...";
MySQLConnection conn = new MySQLConnection(connStr);
MySQLCommand cmd = new MySQLCommand(sql, conn);
MySQLDataReader rdr = null;
DataTable dt = new DataTable();
dt.Columns.Add("Id","FirstName","LastName","Address","Date");
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
dt.Rows.Add(rdr["ID"], rdr["FirstName"], rdr["LastName"], rdr["Address"],rdr["Date"]);
}
conn.Close();
rdr.Close();
dataGridView.DataSource = dt;
@user ....你試過索引你的表嗎? – MikeTWebb
請再次粘貼您的代碼,這次請選擇整個區塊,然後單擊代碼按鈕! – Blorgbeard
查詢需要多長時間手動運行? – Blorgbeard