Taking lot of time to read from SQL Server using c# -


i have 4 million rows in table.( size around 300 gb ), want read rows in table sql server database. used following code in c#. taking time. please suggest me improvements.

            list<int> hit_block_index = new list<int>();              /* here process other , populate hit_block_index integers */              string _query = "select tracename,blockvector 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;                   }            } 

something might work. i'm not sure on efficiency yet - may depend on amount of hits you're looking for:

create type hitblocks table (     hitindex int not null ) go create procedure findmaxcover     @hits hitblocks readonly     ;with decomposedblocks (         select (hitindex/8)+1 byteindex,power(2,(hitindex%8)) bitmask         @hits     ), coverage (         select             t.tracename,sum(case when substring(t.blockvector,db.byteindex,1) & bitmask != 0 1 else 0 end) coverage                     trace t                 cross join             decomposedblocks db         group             t.tracename     ), ranked (         select *,rank() on (order coverage desc) rk         coverage     )     select         t.tracename,         t.blockvector,         r.coverage             ranked r             inner join         trace t             on                 r.tracename = t.tracename     rk = 1 

at moment, return multiple rows if there multiple results same coverage level. may have adjust a) off-by-one errors between expectations , yours, , b) there may endianness issues in computing correct bitmask values.

from code, populate datatable values you're storing in hit_block_index , pass across @hits parameter.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -