databaseselectoptimizationrdbms-agnostic

How to make select query more efficient?


I have a table Customers with Millions of Records on 701 attributes ( columns ). I receive a csv file that has one row and 700 columns. Now on the basis of these 700 column values I have to extract the ids from the table Customers.

Now one way is obvious that i fire a select query with all 700 values in where clause.

My question is that if I first fetch a smaller table using only one attribute in where clause and then fetching again on the basis of second attribute in where clause ... and repeating this process for all attributes, would it be any faster ? Or can you suggest any other method that could make it faster ?


Solution

  • Try to understand the logic of those 700 attributes. There might be dependencies between them that can help reduce the number of the attributes to something more "realistic".

    I would then use the same technique to see if I can run smaller queries which would benefit from indexes on the main table. Each time I would store the result in a temporary table (reducing the number or rows in the tmp table), index the temp table for the next step and do it again till I have the final result. Example: if you have date attributes: try to isolate all record for the year, then the day, etc.

    Try to keep complex requests for the end as they will be running against smaller tmp tables.