How does a prepared expression work? What does it mean to say that my request is compiled?

I'm not sure I understand the prepared statement regarding speed or efficiency. I read that the prepared statement is compiled on the database server and can be used again and again.

But let's say I have a webpage. He makes one request. The next user brings up the page, the same request, only different parameters for this user.

In the second hit on the web page, a statement was prepared looking at dbms to find out if this particular request exists on the database server? I don’t understand what it means to say that the instruction is compiled and can be executed β€œover and over”. Does he not cook it on every page run?

Also, this is not about SQL injection. This part, which I really understand, relates to compilation.

Thanks.

edit: I searched, but I can not find the answer. I just came to this question.

edit: Based on the comments below, given my scenario, I don't see any efficiency. Security yes. The whole compiled thing. Not. Does anyone have a scenario that they can give as an example that meets performance requirements?

+6
source share
1 answer

The query plan created during the first run can be cached either by the database (potentially providing benefits to all applications connecting to the database that execute the same query) or by the database driver (providing the advantage to the application if it is not restarted). Soft parsing will still be performed on every run, but usually it is much cheaper.

Please note that your mileage may vary depending on the type of database, driver, etc. The operator cache is also usually limited, which means that only a certain number of statements will be stored in the cache.

Ask Tom gives some answers regarding the difference between soft and hard parsing.

+3
source

Source: https://habr.com/ru/post/922981/


All Articles