【发布时间】:2016-03-11 09:56:45
【问题描述】:
我有一个 Row.Count=2.000.000 和两列包含整数值的 DataTable。
所以我需要的是有效地循环过滤数据表。
我正在这样做;
for (int i= 0; i< HugeDataTable.Rows.Count; i++)
{
tempIp= int.Parse(HugeDataTable.Rows[i]["col1"].ToString());
var filteredUsers = tumu.Select("col1= " + tempIp.ToString()).Select(dr => dr.Field<int>("col2")).ToList();
HashSet<int> filtered = new HashSet<int>(filteredUsersByJob2);
Boolean[] userVector2 = userVectorBase
.Select(item => filtered.Contains(item))
.ToArray();
...
}
我应该怎么做才能提高性能。我需要每一个小技巧。数据表索引,linq 搜索是我想出的谷歌搜索。我想听听你的建议。 谢谢。
【问题讨论】:
-
为什么
DataTable中有 2m 行?为什么不先在数据库端过滤呢? -
@Lloyd 怎么说“为什么不先在数据库端过滤它?”。但无论如何,您可以使用
AsParallel(),如果您有 2 个或更多内核,它将提高查询速度。用法:filteredUsers = tumu.AsParallel().Select("col1= " + tempIp.ToString()).Select(dr => dr.Field<int>("col2")).ToList();
标签: c# performance filter datatable