Home > database >  SQL server single table access large amount of data
SQL server single table access large amount of data

Time:10-11

TableA I have a table, for example, 200 million records, about 15 fields, no special index, the primary key is an ID column, regardless of the month according to the table, depots, is currently the table on a yearly basis, is the purpose of this query to query all users within a specified time period, the final landing time of the record,
In SQL server SSMS to run the following query:
Select a t1. Id, t1. Name, t1. Login time,...
The from tableA AS t1
Right outer join
(
Select name, MAX (landing time)
The from tableA where landing time between 'start time' and 'end times' group by name
) as t2
On t1. Name=t2. Name and t1. The landing time=t2. The time

The entire statement operation takes about 10 minutes, I tested each statement alone, the following query time this sentence in about 80 seconds:
Select name, MAX (landing time)
The from tableA where landing time between 'start time' and 'end times' group by name

Then tested on a monthly table, nested similar to the above statement, in about 2 seconds, the overall in about 20 seconds, the situation is obvious, now my question is why the gap is so big, I really don't want to a monthly table, temporary tables and stored procedures to solve the problem? I'm not familiar with these two kinds of schemes, there is no test, database operation level is limited, while groping test, but look at the introduction of temporary tables and stored procedures, feel the temporary tables and stored procedures can't solve the problem of query speed,
Score is limited, please understand, discuss technical
 
,


  • Related