<bdo id='NsO9e'></bdo><ul id='NsO9e'></ul>

        <legend id='NsO9e'><style id='NsO9e'><dir id='NsO9e'><q id='NsO9e'></q></dir></style></legend>

        <small id='NsO9e'></small><noframes id='NsO9e'>

        <tfoot id='NsO9e'></tfoot>
      1. <i id='NsO9e'><tr id='NsO9e'><dt id='NsO9e'><q id='NsO9e'><span id='NsO9e'><b id='NsO9e'><form id='NsO9e'><ins id='NsO9e'></ins><ul id='NsO9e'></ul><sub id='NsO9e'></sub></form><legend id='NsO9e'></legend><bdo id='NsO9e'><pre id='NsO9e'><center id='NsO9e'></center></pre></bdo></b><th id='NsO9e'></th></span></q></dt></tr></i><div id='NsO9e'><tfoot id='NsO9e'></tfoot><dl id='NsO9e'><fieldset id='NsO9e'></fieldset></dl></div>

        PDO/PHP/MySQL 中的性能:事务与直接执行

        Performance in PDO / PHP / MySQL: transaction versus direct execution(PDO/PHP/MySQL 中的性能:事务与直接执行)

          <tbody id='m9qh9'></tbody>

            <small id='m9qh9'></small><noframes id='m9qh9'>

            • <bdo id='m9qh9'></bdo><ul id='m9qh9'></ul>

              • <tfoot id='m9qh9'></tfoot>

                <i id='m9qh9'><tr id='m9qh9'><dt id='m9qh9'><q id='m9qh9'><span id='m9qh9'><b id='m9qh9'><form id='m9qh9'><ins id='m9qh9'></ins><ul id='m9qh9'></ul><sub id='m9qh9'></sub></form><legend id='m9qh9'></legend><bdo id='m9qh9'><pre id='m9qh9'><center id='m9qh9'></center></pre></bdo></b><th id='m9qh9'></th></span></q></dt></tr></i><div id='m9qh9'><tfoot id='m9qh9'></tfoot><dl id='m9qh9'><fieldset id='m9qh9'></fieldset></dl></div>
                <legend id='m9qh9'><style id='m9qh9'><dir id='m9qh9'><q id='m9qh9'></q></dir></style></legend>
                1. 本文介绍了PDO/PHP/MySQL 中的性能:事务与直接执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在遍历多个值(例如 1 到 100)并在循环内执行准备好的语句.

                  I am looping through a number of values (1 to 100 for example) and executing a prepared statement inside the loop.

                  与在循环内直接执行相比,使用事务(在循环结束后提交)是否有优势?

                  Is there and advantage to using a transaction - committing after the loop ends - compared to a direct execution inside the loop?

                  这些值不相互依赖,因此从这个角度来看不需要交易.

                  The values are not dependant on each other so a transaction is not needed from that point of view.

                  推荐答案

                  如果您的查询是 INSERT,页面 7.2.19.MySQL 手册的 INSERT 语句速度 提供了两个有趣的信息,具体取决于您是否使用事务引擎:

                  If your queries are INSERTs, the page 7.2.19. Speed of INSERT Statements of the MySQL manual gives two interesting informations, depending on whether your are using a transactionnal engine or not :

                  当使用非事务引擎时:

                  加速 INSERT 操作用多个语句执行非事务表,锁定你的表.

                  To speed up INSERT operations that are performed with multiple statements for nontransactional tables, lock your tables.

                  这有利于性能,因为索引缓冲区仅刷新到磁盘一次,在所有 INSERT 语句之后完全的.通常,会有作为许多索引缓冲区刷新,因为有插入语句.显式锁定如果可以,则不需要声明用一个 INSERT 插入所有行.

                  This benefits performance because the index buffer is flushed to disk only once, after all INSERT statements have completed. Normally, there would be as many index buffer flushes as there are INSERT statements. Explicit locking statements are not needed if you can insert all rows with a single INSERT.

                  并且,使用事务引擎:

                  为了获得更快的插入事务表,你应该使用START TRANSACTION 和 COMMIT 代替锁表.

                  To obtain faster insertions for transactional tables, you should use START TRANSACTION and COMMIT instead of LOCK TABLES.

                  所以我猜使用事务可能是一个好主意——但我想这可能取决于服务器上的负载,以及是否在同一时刻使用同一张表有多种用途,以及所有这些......

                  So I am guessing using transactions might be a good idea -- but I suppose that could depend on the load on your server, and whether there are multiple uses using the same table at the same moment, and all that...

                  我链接到的页面上有更多信息,所以不要犹豫,阅读它;-)

                  There are more informations on the page I linked to, so don't hesitate to read it ;-)


                  而且,如果您正在执行 更新语句 :

                  另一种获得快速更新的方法是延迟更新然后做很多更新一排之后.执行多个一起更新比一起快得多一次做一个,如果你锁定表.

                  Another way to get fast updates is to delay updates and then do many updates in a row later. Performing multiple updates together is much quicker than doing one at a time if you lock the table.

                  所以,我猜可以说与插入相同.

                  So, I'm guessing the same can be said than for inserts.


                  顺便说一句:可以肯定的是,您可以尝试两种解决方案,使用 microtime 对它们进行基准测试,在 PHP 方面,例如 ;-)


                  BTW : to be sure, you can try both solutions, benchmarking them with microtime, on the PHP side, for instance ;-)

                  这篇关于PDO/PHP/MySQL 中的性能:事务与直接执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  1. <small id='B00be'></small><noframes id='B00be'>

                    <tfoot id='B00be'></tfoot>

                        <i id='B00be'><tr id='B00be'><dt id='B00be'><q id='B00be'><span id='B00be'><b id='B00be'><form id='B00be'><ins id='B00be'></ins><ul id='B00be'></ul><sub id='B00be'></sub></form><legend id='B00be'></legend><bdo id='B00be'><pre id='B00be'><center id='B00be'></center></pre></bdo></b><th id='B00be'></th></span></q></dt></tr></i><div id='B00be'><tfoot id='B00be'></tfoot><dl id='B00be'><fieldset id='B00be'></fieldset></dl></div>
                        <legend id='B00be'><style id='B00be'><dir id='B00be'><q id='B00be'></q></dir></style></legend>

                            <bdo id='B00be'></bdo><ul id='B00be'></ul>

                              <tbody id='B00be'></tbody>