Is php sort better than mysql “order by”?

You're comparing a system with methods implemented in optimized C, meant to do exactly this task, with another that you are going to implement in an interpreted scripting language.

You're comparing a system with methods implemented in optimized C, meant to do exactly this task, with another that you are going to implement in an interpreted scripting language. Basically, anything written in C is going to be a lot faster than an equivalent function written in PHP, by a factor of 10 to 100. As already noted, there's no question at all that it is far more efficient to configure your DB properly and let it do the work.

Language doesn't THAT matter, pal. We use PHP with that factor everyday and happy with it. You are just wrong.

That language difference is a least reason, and doesn't matter – Col. Shrapnel Sep 2 '10 at 5:32 @Col. Shrapnel What a joke!

Are you serious? C is not in the same class of languages as PHP - THAT is the difference. I'm not comparing it to Python or Ruby - you clearly don't know what you're talking about.

I don't use C at all because it's not suitable for web apps, but there is ABSOLUTELY NO QUESTION C is faster than PHP for the same task - however, it takes 20,000 time as many lines of code and 5 times as long to write. There IS a reason people don't write operating systems, database engine in PHP or Perl. I mean, PHP is IMPLEMENTED IN C.

They are absolutely for different things. – flexxy Sep 2 '10 at 5:45 @Col. Shrapnel I mean, seriously.Shootout.alioth.debian.org/u32/… PHP is slower than C but it's a hell of a lot more convenient.

It's apples and oranges. But that's not what we're comparing - we're talking native database code vs. a PHP script. I don't care if it's PHP, Python, Perl, Ruby or whatever - native database code (written in C) is going to be faster.

– flexxy Sep 2 '10 at 5:49 we are not talking of operating systems. Even not of reasons why mysql written not in PHP. You can see only one point, and do not understand others.

It's a pity. – Col. Shrapnel Sep 2 '10 at 5:51 @Col.

Shrapnel. Seriously, I don't know what you are talking about. Nor do you.

The issue is native database code versus a program written in an interpreted scripting language. Are you saying sorting in PHP would be equivalent to having MySQL do it? Nobody else seems to think so.

– flexxy Sep 2 '10 at 5:53.

MySQL, hands down. It's optimized to do this, and can make use of indexes. This would be horrible to do in PHP (and you would reach the memory_limit quickly).

In the hypothetical case that you actually get the records in the memory of your application then mysql will still beat the pants of your app because if you configured your database right it won't HAVE to sort. I fyou want to order by in a table of 1 Mio records, you would provide in index which would be typically implemented as a B-Tree where Mysql can walk through and get the sorted results.

MySQL will win. One more reason besides the others listed is that, assuming the records are already in the DB, you don't have to copy them out of the DB to sort them. And paging or subindexing them will be easy and optimized automatically.In short, if the DB CAN do it, the DB SHOULD do it, almost always.

1 +1 - Tranferring the data to do the sort will be much more expensive than doing it on the database. – James Black Sep 1 '10 at 18:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions