mysql> create table w0904procedure (wa char, wb char, wd char, wi char);
Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO w0904procedure VALUES(NULL, 0, 'www0904', 'w0904d');
ERROR 1406 (22001): Data too long for column 'wd' at row 1 mysql> desc w0904procedure;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| wa | char(1) | YES | | NULL | |
| wb | char(1) | YES | | NULL | |
| wd | char(1) | YES | | NULL | |
| wi | char(1) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
4 rows in set (0.00 sec) mysql> DROP PROCEDURE IF EXISTS insert_many_rows_w0904;
Query OK, 0 rows affected (0.00 sec) mysql> delimiter //
mysql> CREATE PROCEDURE insert_many_rows_w0904 (IN loops INT)
-> BEGIN
-> DECLARE v1 INT;
-> SET v1=loops;
-> WHILE v1 > 0 DO
-> INSERT INTO w0904procedure VALUES(NULL, 0, 'w', 'w');
-> SET v1 = v1 - 1;
-> END WHILE;
-> END;
-> //
Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
mysql>
mysql> SET @loops=987987;
Query OK, 0 rows affected (0.00 sec) mysql> CALL insert_many_rows_w0904(@loops);
Query OK, 1 row affected (43.05 sec) mysql> SELECT * FROM w0904procedure LIMIT 20;
+------+------+------+------+
| wa | wb | wd | wi |
+------+------+------+------+
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
| NULL | 0 | w | w |
+------+------+------+------+
20 rows in set (0.00 sec) mysql> SELECT COUNT(*) FROM w0904procedure;
+----------+
| COUNT(*) |
+----------+
| 987988 |
+----------+
1 row in set (0.00 sec)
High Performance MySQL, Third Edition
by Baron Schwartz, Peter Zaitsev, and Vadim Tkachenko
 
 <?php

 $db = new mysqli('localhost', 'root', '', 'w');
if($db->connect_error){
die('Connect Error ( '.$db->connect_errno.' )'.$db->connect_error);
}
echo 'Connect OK.<br>';
$start = microtime(TRUE);
if($res=$db->query('SELECT COUNT(*) FROM w0904procedure')){
while($row=$res->fetch_all()){
var_dump($row);
}
}
$end0 = microtime(TRUE);
if($res=$db->query('SELECT * FROM w0904procedure LIMIT 2')){
while($row=$res->fetch_all()){
var_dump($row);
}
}
$end1 = microtime(TRUE);
$w = 987987;
do{
$db->query('INSERT INTO w0904procedure VALUES(NULL, 1, "w", "w")');
$w--;
}
while($w>0);
$end2 = microtime(TRUE);
echo $end0 - $start, '<br>', $end1 - $end0, '<br>', $end2 - $end1;
 Connect OK.

 D:\wamp64\www\wdb.php:11:
array (size=1)
0 =>
array (size=1)
0 => string '987988' (length=6) D:\wamp64\www\wdb.php:17:
array (size=2)
0 =>
array (size=4)
0 => null
1 => string '0' (length=1)
2 => string 'w' (length=1)
3 => string 'w' (length=1)
1 =>
array (size=4)
0 => null
1 => string '0' (length=1)
2 => string 'w' (length=1)
3 => string 'w' (length=1) 0
0.003000020980835
97.394570112228
 mysql> SELECT COUNT(*) FROM w0904procedure;
+----------+
| COUNT(*) |
+----------+
| 987988 |
+----------+
1 row in set (0.00 sec) mysql> SELECT COUNT(*) FROM w0904procedure;
+----------+
| COUNT(*) |
+----------+
| 1975975 |
+----------+
1 row in set (0.00 sec) mysql>
We usually prefer to keep stored routines small and simple. We like to perform complex logic outside the database in a procedural language, which is more expressive and versatile. It can also give you access to more computational resources and potentially
to different forms of caching.
However, stored procedures can be much faster for certain types of operations—especially when a single stored procedure call with a loop inside it can replace many small queries. If a query is small enough, the overhead of parsing and network communication becomes a significant fraction of the overall work required to execute it.
 
To illustrate this, we created a simple stored procedure that inserts a specified number
of rows into a table.
The stored procedure is much faster, mostly because it avoids the overhead of network communication, parsing, optimizing, and so on.

97.394570112228 - Query OK, 1 row affected (43.05 sec) - the overhead of parsing and network communication的更多相关文章

  1. Error Code: 1366. Incorrect DECIMAL value: '0' for column '' at row -1 0.266 sec;

    Reference: https://stackoverflow.com/questions/35037288/incorrect-decimal-integer-value-mysql     Er ...

  2. MySQL5.6 ALTER TABLE 分析和测试

    在MySQL5.5和之前版本,在运行的生产环境对大表(超过数百万纪录)执行Alter操作是一件很困难的事情.因为将重建表和锁表,影响用户者的使用.因此知道Alter操作何时结束对我们是非常重要的.甚至 ...

  3. MySQL GTID 错误处理汇总

    MySQL GTID是在传统的mysql主从复制的基础之上演化而来的产物,即通过UUID加上事务ID的方式来确保每一个事物的唯一性.这样的操作方式使得我们不再需要关心所谓的log_file和log_P ...

  4. MySQL碎碎念

    1. 如何修改Mysql的用户密码 mysql> update mysql.user set password=password('hello') where user='root'; mysq ...

  5. mysql一个事务中有DDL语句的binlog情况

      在autocommit=1的情况下,开启一个事务,如果里面有DDL语句,那么事务开始到DDL语句之间的DML语句都会被提交.再开启新的事务.可以从binlog中看出   session语句: 09 ...

  6. MySQL 闪回工具之 binlog2sql

    生产上误删数据.误改数据的现象也是时常发生的现象,作为 DBA 这时候就需要出来补锅了,最开始的做法是恢复备份,然后从中找到需要的数据再进行修复,但是这个时间太长了,对于大表少数数据的修复来讲,动作太 ...

  7. MySql技术内幕之MySQL入门(2)

    MySql技术内幕之MySQL入门(2) 接上一篇. mysql> source create_member.sql; # 创建member表 Query OK, 0 rows affected ...

  8. 详解MariaDB数据库的存储过程

    1.什么是存储过程 很多时候,SQL语句都是针对一个或多个表的单条语句.但是也有时候有的查询语句需要进行多次联表查询才能完成,此时就需要用到存储过程了. 存储过程(Stored Procedure)是 ...

  9. Mysql表的约束设计和关联关系设计

    https://blog.csdn.net/u012750578/article/details/15026677 Mysql表的约束设计和关联关系设计 ======================表 ...

随机推荐

  1. Java 数据库访问层

    最近项目中需要对mysql进行操作,数据库的知识早在本科毕业那会就忘光了,这几年开发都没接触到数据库的操作. 借这个机会重新学习,数据库访问层是对数据库操作的一个封装,屏蔽底层的数据操作细节,通过使用 ...

  2. 《C++ Primer Plus》16.1 string类 学习笔记

    16.1.1 构造字符串程序清单16.1使用了string的7个构造函数.程序清单16.1 str1.cpp---------------------------------------------- ...

  3. [OpenGL]用OpenGL制作动画

    //在窗口内绘制一个移动的矩形 /*我们通常还可以用OpenGL程序创建动画效果,这里我们利用前面的例子,绘制正方形,并使这个正方形在窗口的边框反弹.这里需要创建一个循环,在每次调用显示回调函数之前改 ...

  4. springbatch---->springbatch的使用(一)

    这里我们通过一个简单的实例来对springbatch做一个入门的体会.刚刚好,看见你幸福的样子,于是幸福着你的幸福. springbatch的入门案例 简单项目的结构如下: 一.引入maven的spr ...

  5. Ubuntu 14.04 LTS 火狐浏览器中,鼠标选择文字被删除的解决办法

    这篇文章主要介绍了Ubuntu 火狐浏览器中,鼠标选择文字被删除的解决办法,需要的朋友可以参考下在终端中输入命令: ibus-setup将 “在应用程序窗口中启用内嵌编辑模式“ 选项取消

  6. EXCEL通俗易懂讲公式(一):sumif,sumifs,countif,countifs

    最近公司招了一批新人,excel基本都是小白阶段,以前用过的也就是画个课程表,没做过什么数据统计和文本计算等工作.因此各种问题都来了,什么vlookup,offset,连条件求和的sumif也不会用, ...

  7. JiraRemoteUserAuth

    配置Jira7.x版本使用REMOTE_USER的HTTP Header方式登录: 前提是已经安装好了JIRA,并且前端使用apache或者nginx拦截对应的地址进行认证,认证之后访问对应的应用的时 ...

  8. FPAG结构 组成 工作原理 开发流程(转)

    FPGA组成.工作原理和开发流程 备注:下面的描述基于ALTERA系列的FPGA芯片,而且是第一次学习FPGA,其中的一部分内容是参考一些资料总结的,个人独特的分析和见解还偏少. 1. FPGA概述 ...

  9. 预编译 ASP.NET 网站以进行部署

    预编译 ASP.NET 网站以进行部署和更新 打开一个命令窗口并定位到包含 .NET Framework 的文件夹. .NET Framework 将安装在以下位置. %windir%\Microso ...

  10. 【CF913G】Power Substring 数论+原根

    [CF913G]Power Substring 题意:T组询问,每次给定一个数a,让你求一个k,满足$2^k$的10进制的后$min(100,length(k))$位包含a作为它的子串.你只需要输出一 ...