1

Hi, I've got one table in DB on 4k notes with 2 columns(id and title) and one array on 4k elements. Both of them are full of equal data. What is the best way to sort it and insert in sorted order into another table in DB? Which way takes less resources to sort: using SQL or code it yourself using quick sort with array? Which strategy is better to use array or DB?

3
  • I guess doing your own time timings would give you the answer. My guess would be that the DB would be quicker as that's what they are optimized to do Commented Aug 23, 2013 at 6:54
  • 1
    What do you mean by "insert in sorted order into another table in DB"? Database tables aren't sorted. If you do select * from ponies, the rows usually come in a predictable order (which may change e.g. if you add an index), but by definition, tables aren't sorted. Commented Aug 23, 2013 at 7:05
  • I know that tables are not sorted. Commented Aug 23, 2013 at 7:10

2 Answers 2

1

If you query for the data, then use order by and load it in the correct order in the first place.

If that data is available in your application without querying the other table, then do not do it and quicksort. You will save your database some work and it will probably be faster, especially since you're using java.

Sign up to request clarification or add additional context in comments.

Comments

0

Using inbuilt DB operations should be faster. Sorting externally and again putting back involves I/O operations which themselves are slow, and then it also depends on the language you are using.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.