Rupesh Kahane

Rupesh Kahane

  • 126
  • 15.4k
  • 2.2m

Optimize SQL query - one hundred twenty-nine million records

Apr 4 2019 7:08 AM

I have a table (UserDeptMapping) which conatins 129000000 (one hundred twenty-nine millions records).

 
 Department details table which has 500 entries.
 

ID

DeptId

WorldLocationId

RegionId

DistrictId

 
 
 Table UserDeptMapping which contains below data like
 
 
 Id UsertId   MappingId
 1 1 1
 2 1 2
 3 1 3
 4 2 1
 
Suppose execute below query against Department Id 1 like
  1. Select * from UserDeptMapping Where MappingId = 2    

 Output comes with total 300000 rows which is taking 30 seconds. 

How can I optimiase the query., so it will reduce the time. 


Answers (3)