MySQL speed question (12, permasaged)

1 Name: #!/usr/bin/anonymous : 2009-08-09 08:04 ID:5FfRIDHu

I was wondering, when you have a large set of data in a MySQL table, is it faster to find the data you want with MySQL's Select function, or by dumping the whole table into a PHP array and searching through that?

Basically, which works faster with lots of data, PHP or MySQL?

4 Name: #!/usr/bin/anonymous : 2009-08-10 13:36 ID:Heaven

I guess I should be offering an explanation as to why >>2 is correct, so here it goes.

MySQL is a database thing. It's written in C and it offers an API (in C), that you use to store and retrieve data. It's pretty damn fast, faster than anything you or some other individual alone would be able to implement. So, other languages make use of this API by integrating the C functions et cetera to their interface. Since there's more work to be done in runtime, using functions from those languages is going to be a tad slower, but not enough to be noticable in a small/medium scale project.

You'll find the C api documentation here,
http://dev.mysql.com/doc/refman/6.0/en/c.html

As for PHP, you already know this I hope, but here's the docs
http://php.net/manual/en/book.mysql.php

5 Name: #!/usr/bin/anonymous : 2009-08-10 13:38 ID:Heaven

>>4
Ah yeah, but converting the data retrieved to some native structure of the language you are using (ie an array), and searching... is a million times slower.

Not just the conversion is going to be awfully slow the bigger your data is, but searching might take minutes. MySQL takes proper care of the right data structures and algorithms for your data.

This thread has been closed. You cannot post in this thread any longer.