如何为枚举器优化此查询:
SELECT * FROM Customers
Table Customers
customerId int - has index on it
customerName, etc
返回集合客户的SQLReader将以枚举器的方式按需读取。虽然它可以返回可以在foreach循环中缓慢读取/使用的大型数据集,但同一个表上的每个其他查询都会遇到许多争论。如何优化/避免这种情况?光标还是选择临时表?
下面是一个会引起很多争论的代码示例(我分析了它,数字看起来确实很糟糕):
public void DumpCustomers()
{
Thread thread = new Thread(AccessCustomers);
thread.Start();
// GetCustomers returns enumerator with yield return; big # of customers
foreach (Customer customer in GetCustomers())
{
Console.WriteLine(customer.CustomerName);
System.Threading.Thread.Sleep(200);
}
thread.Abort();
}
public void AccessCustomers()
{
while (true)
{
Console.WriteLine(GetCustomer("Zoidberg").CustomerName);
Thread.Sleep(100);
}
}
另外,我还需要在MySQL中对此进行优化。