Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>The second approach is surposed to be faster than the first one,the result is not as what I thought to be though,Could anyone tell me does bindparam() really speed up bulk insertion?</p> </blockquote> <p>It actually is faster. Just not necessarily for trivial queries like the one you posted.</p> <p>This is a bit like benchmarking MySQL vs PostgreSQL. If you run a test with MyISAM tables that does trivial non-concurrent selects, your benchmark might decide that MySQL outperforms Postgres. If, however, you run hundreds of concurrent queries with a half-dozen joins, your benchmark might tell you a very different story.</p> <p>In your case, you're preparing a trivial insert. It's trivial to parse the SQL; determining the optimal query plan is equally trivial. The benefit of preparing the statement is very slim. If, on the other hand, you have a couple of non-trivial triggers that fire on each insert, you'll likely get a very different story.</p> <p>There's also something to be said about true prepares vs emulated prepares. Sometimes, a prepared statement doesn't give you an optimal plan. Consider this query:</p> <pre><code>select * from foo order by bar limit ? </code></pre> <p>If you prepare the above, the planner cannot decide whether to use an index on bar -- if bar is low enough, it'll make sense; if it's enormous, you might as well fetch the entire table and top-n sort it. And so the planner will pick the latter plan.</p> <p>In contrast, if you send the final query directly, the planner will have all the elements it needs to decide whether using that same index makes sense or not for that particular value. In other words, an emulated prepare is occasionally better for queries that are only run a single time, or for trivial queries.</p> <p>Oh, and don't forget to wrap the entire thing into a single transaction. That'll speed things up significantly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload