我想在 select 语句中搜索超过 15000 个值,如下所示:
从表A中选择*,其中id在(1,2,3......16000)
我可以使用线程(例如 3 个左右)并在不同的 select 语句中划分 15000 个值吗?
从 tableA 中选择 *,其中 id 在 (1,2,3......5000)
从 tableA 中选择 *,其中 id 在 (5001....10000)
从 tableA 中选择 *,其中 id 在 (10001....15000)
并并行运行这 3 个选择语句。
最佳答案
是的,但真正的问题是为什么?
类似这样的事情可能会让你开始:
var itms = new List<YourDataClass>();
var thr1 = new Thread(new ThreadStart(delegate()
{
// select code
// populate itms
}));
var thr2 = new Thread(new ThreadStart(delegate()
{
// select code
// populate itms
}));
var thr3 = new Thread(new ThreadStart(delegate()
{
// select code
// populate itms
}));
thr1.Start();
thr2.Start();
thr3.Start();
但是,也就是说,如果您的 ID 是整数并且(根据您的样本)范围为 IN
值是连续的,您可能需要切换到 where id > 1 and id < 16000
风格。这可能会产生更好的性能。
关于c# - 使用c#进行多线程搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3504609/