Prepare for speed
prepare() - what happens in the server...
- Receive and parse the SQL statement into internal form
- Get details for all the selected tables
- Check access rights for each
- Get details for all the selected fields
- Check data types in expressions
- Get details for the indices on all the fields in where/join clauses
- Develop an optimised query 'access plan' for best execution
- Return a handle for all this cached information
- This can be an expensive process
- especially the 'access plan’ for a complex multi-table query
- Some databases, like MySQL, don't cache the information
- but have simpler and faster, but less powerful, plan creation
.