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. 数组名和数组名取地址&

        在C中, 在几乎所有使用数组的表达式中,数组名的值是个指针常量,也就是数组第一个元素的地址. 它的类型取决于数组元素的类型: 如果它们是int类型,那么数组名的类型就是“指向int的常量指针“ ...

  2. 分析JobInProgress中Map/Reduce任务分配

    1.JobTracker能否决定给当前的TaskTracker节点分配一个Job的具体的哪一个任务? 2.什么是map本地任务? 3.nonRunningMapCache的作用是什么? 4.从Task ...

  3. Kafka配置SSL(云环境)

    本文结合一个具体的实例给出如何在公有云环境上配置Kafka broker与client之间的SSL设置. 测试环境 阿里云机一台(Server端):主机名是kafka1,负责运行单节点的Kafka集群 ...

  4. PHP array_unique()函数去除重复元素

    定义和用法 array_unique() 函数移除数组中的重复的值,并返回结果数组. 当几个数组元素的值相等时,只保留第一个元素,其他的元素被删除. 返回的数组中键名不变. 语法 array_uniq ...

  5. Qt——布局管理器

    教程地址 运行截图: 代码: #include "mainwindow.h" #include <QApplication> #include <QHBoxLay ...

  6. PowerDesigner 同步Name到Comment 及 同步 Comment 到Name

    PowerDesigner中使用方法为:     PowerDesigner->Tools->Execute Commands->Edit/Run Scripts 代码一:将Name ...

  7. spy-debugger 前端调试工具

    一站式页面调试.抓包工具.远程调试任何手机浏览器页面,任何手机移动端webview(如:微信,HybirdApp等).支持HTTP/HTTPS,无需USB连接设备.    Language: Engl ...

  8. 转载->C#中的委托的使用和讲解

    C# 中的委托 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容 ...

  9. mac下编译 boost编译工具b2

    cd boost_1_64_0/tools/build ./bootstrap.sh --with-toolset=gcc 输出: -n Bootstrapping the build engine ...

  10. 题目1459:Prime ring problem(素数环问题——递归算法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1459 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...