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. CentOS-6.4 安装 Memcached

    1.准备文件 cd /usr/src 最新版下载地址 :http://code.google.com/p/memcached/downloads/list wget http://memcached. ...

  2. Python中的and/or

    在Python中,可以通过and,or和not进行逻辑运算,下面就来看看and和or的简单介绍. 逻辑与-and 对于包含and运算的表达式,Python解释器将从左到右扫描,返回第一个为假的表达式值 ...

  3. 简单思考 如何用PHP输出本周的周三日期

    简单思考 如何用PHP输出本周的周三日期?比如今天2017-10-31 计算本周周三应该是2017-11-01 自己动脑筋想一想,然后给我留言或者评论

  4. java.lang.IllegalArgumentException: No converter found for return value of type

    原文地址: http://blog.csdn.net/linhaiguo/article/details/51554766 问题原因: 请求返回的数据无法转换,需要添加如下配置 解决方法: 1.在po ...

  5. Nginx(十)-- 进程模型及工作原理

    1.nginx进程模型 Nginx是一个master和worker的模型.master主要用来管理worker进程,master就比作老板,worker就是打工仔,master指挥worker来做事情 ...

  6. vmware下虚拟机不能上网问题解决

    这个问题困扰了好久,vmware下装的虚拟机可以通过DHCP获取单独IP,但当用到管控较严格的环境,需要它与主机共享IP时,就不好使了. 今天在一篇文章中找到答案,如下图,windows系统中要启动V ...

  7. 学习下新塘M0芯片的下载方法

    编程方式多种多样,解释这几种方式的原理,方便做后续的回答: 一.脱机 脱机的意思就是脱离PC机,有很多芯片必须连接PC才能烧录,比如某些FPGA芯片.MCU芯片.NAND Flash芯片等.脱机和在线 ...

  8. 【cs229-Lecture5】生成学习算法:1)高斯判别分析(GDA);2)朴素贝叶斯(NB)

    参考: cs229讲义 机器学习(一):生成学习算法Generative Learning algorithms:http://www.cnblogs.com/zjgtan/archive/2013/ ...

  9. HTML - 网页特殊字符大全(转)

    原文地址请跳转:https://blog.csdn.net/Iversons/article/details/78996776

  10. Spring.NET依赖注入框架学习-- 泛型对象的创建和使用

    Spring.NET依赖注入框架学习-- 泛型对象的创建和使用 泛型对象的创建方法和普通对象是一样的. 通过构造器创建泛型对象 下面是一个泛型类的代码: namespace GenericsPlay ...