A SQL/Database question that I was asked in an interview
Anonymous User
2540

Hi experts,
I was once asked this question in an interview with a small company.

Say you are asked to write a SQL query to get some data from database, but the table is very large and there's no indices in the table, and you cannot add indices to it or make any changes to the table. Querying data from the table is slow, what can you do to make it faster?

I was not able to give a good solution, in the end I asked the interviewer what the best solution was. He told me that the correct answer should be to make use of temp tables, create a temp table, move the data there and build indices there, then query from temp table.

I did not have time to ask for more details. and I don't know much about database, so want to know the mechanism behind this solution. Does database engine has some speal handling in temp table so that dumping data to temp table is much faster than query data from regular table? I assume the "temp table" he mentioned is the temp table that a typical database has normally, not just another regular table. Not sure if I understand it correctly.

Thanks,
Michael

Comments (7)