我的表中有 400 万行。(大小约为 300 GB),我想从 sql server 数据库中读取表中的所有行。我在 C# 中使用了以下代码。这需要时间。请建议我一些改进。
List<int> hit_block_index = new List<int>();
/* Here i process some other and populate hit_block_index with integers */
string _query = "SELECT TraceName,BlockVector FROM Trace";
SqlConnection _connection = new SqlConnection(connection_string);
_connection.Open();
SqlCommand _command = new SqlCommand(_query, _connection);
SqlDataReader data_reader = _command.ExecuteReader();
Byte[] block_vector=null;
string trace_name = null;
BitArray trace = null;
int max_coverage = 0;
while (data_reader.Read())
{
int coverage = 0;
block_vector = (byte[])data_reader["BlockVector"];
trace_name = (string)data_reader["TraceName"];
BitArray trace = new BitArray(block_vector);
foreach (int x in hit_blocks_index)
{
if (trace[x])
{
coverage++;
}
}
Console.WriteLine("hit count is:" + coverage);
if (coverage > max_coverage)
{
most_covered_trace = trace_name;
most_covered_array = trace;
max_coverage = coverage;
}
}