简体   繁体   中英

How to run multiple simple select statements independently of each other simultaneously in SQL Server?

I have a SQL Server installed on ubuntu with only one table (accessed via sqlcmd ) has nearly 2 trillion rows. It currently has a clustered index on column index A (which is not useful for me).

I would like to do a select statement on the data

select b, c, d, e, f 
from table 
where b = 'a vehicle number'

and write the results to a .csv file. But this query takes around 20 minutes to run on the computer even after creating a nonclustered index on column b.

I have to run the same query for 400 different vehicle numbers and it will take days to execute.

How can I make this process faster? Can I run two select statements (for two vehicles) simultaneously in some way so that both these statements are complete within 20 minutes? (not 20 + 20 = 40)?

I have a powerful PC with 128 GB RAM, 40 cores, Intel xeon 4210 @ 2.2Ghz.

Create a table to store the vehicle numbers and join it to the other table, that way a single query will retrieve all rows you are interested in, and you can enumerate the result.

select t1.b, t1.c, t1.d, t1.e, t1.f 
from table1 as t1
inner join table2 as t2 on t1.b = t2.b

You might also try making the primary key/clustered index a composite of a, b. With that many rows it might not be practical, but maybe worth a shot.

Also, it seems like something might be wrong, use DBCC to check integrity and periodically rebuild the indexes.

I take it they don't provide Sql Server Management Studio with the linux version? If they do, use it to display the query cost, it will break it down to each step, and give you values for computational and i/o costs of each.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM