Which is faster sql or file?

Here’s my question. Wrote the engine, now I’m trying to optimize it. And I wanted to ask what is faster than the query or query in php through include.

  1. Does it make sense to cut requests?
  2. Or will it not affect the speed?
  3. If there is no difference, what gives more load on the server?

Answer 1, authority 100%

File processing is faster than executing database queries. For a small amount of data, a file is better. But if the volumes are large, then you no longer have to choose, the database is definitely!
Work on the optimization of SQL queries is a very important process in the implementation of the task, because a good request can reduce the load on the server several times.

But the comparison of the sql query with the include function is not clear to me…


Answer 2, authority 50%

If you want to cache queries to the database, then why not use the standard tools mySQL? If you use a database or plan to work with a large amount of data, then this is your option. Otherwise, you can use the files, why not?


Answer 3, authority 25%

Let’s separate the tasks:

  1. Select a record from the list with filters (10 positions, starting from 20 in the category products, in price from 100 to 1000) – this is a query to the database, since organizing this on files will be difficult or slow.
  2. You need to code the result of work (menu generation, page) – this is usually written to a file based on a selection from the database and processing.
  3. You need to display one record out of 1000000. Or the database, but its size will be impressive, and it is unlikely to be too fast. Or a file with a rigid structure (eg binary).

That is, the answer to your question largely depends on the problem.

Optimal for optimization and simplicity is generation + caching.


Answer 4

Why make it so complicated? You simply make the required request and that’s it, why include anything in order to execute the same request, but from a different file?


Answer 5

I think it’s best to use a stripped-down version of MySQL Lite in this variant, if, of course, it is possible to customize the server for yourself. I personally use XML files, you can easily pull everything out of them using SimpleXML – the sampling speed is incredibly high.