0

I have a destination table(created as an output of some other query), simple order by on one of its column is resulting "resource exceeded" error message. Destination table created has 8.5 million rows and 6 columns (size 567 MB approx).

select col1,col2.....col6 from desttable order by col 5 desc

is resulting "resource exceeded" error message.

James Z
  • 12,209
  • 10
  • 24
  • 44
saurabh
  • 13
  • 1
  • Welcome to Stack Overflow. Please take the [Tour](http://stackoverflow.com/tour) to understand how it works and then edit your question to make it a [good one](http://stackoverflow.com/help/how-to-ask). – Jordi Nebot Dec 21 '16 at 19:26
  • Thanks @JordiNebot – saurabh Dec 22 '16 at 06:52

1 Answers1

1

Remove ORDER BY and see if error disappear!
ORDER BY moves WHOLE data into one worker - thus resources exceeded

If I am adding "LIMIT" and "OFFSET" clause in the query after order by its working,even though LIMIT clause is the last to be evaluated.How it is working there??

When you add LIMIT N - query runs on multiple workers. Each worker gets only part of the data to process and outputs only respective N rows. Those N rows from all workers than gets "delivered" to one worker where final ORDER BY and LIMIT occurs and "winning" N rows becomes output of whole query

Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230
  • If I am adding "LIMIT" and "OFFSET" clause in the query after order by its working,even though LIMIT clause is the last to be evaluated.How it is working there?? – saurabh Dec 22 '16 at 06:46