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. php mongodb manager 查数据的各种姿势

    一.连接 mongodb 数据库 以下操作默认都是以上面操作为前提(已连接成功)而做的操作 二.查的各种姿势 1)通过主键_id来查询,注意:_id不是直接用字符串来表示,要用 new \MongoD ...

  2. Django 创建第一个项目

    创建项目: [root@localhost ~]$ django-admin.py startproject web # web是项目名 [root@localhost ~]$ tree web/ w ...

  3. VS无法导航到插入点F12失败

    关闭VS 开启控制台并导航到Visual安装文件夹,例如C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\ID ...

  4. Android文件系统编译出错记录

    错误1: 注意:external/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java 使用了未经检查或不 ...

  5. [C] 如何使用头文件 .h 编译 C 源码

    在 C 语言中,头文件或包含文件通常是一个源代码文件,程序员使用编译器指令将头文件包含进其他源文件的开始(或头部),由编译器在处理另一个源文件时自动包含进来. 一个头文件一般包含类.子程序.变量和其他 ...

  6. warning C4305:“初始化”:从“double”到“float”截断

    编译VS项目时出现警告: warning C4305:“初始化”:从“double”到“float”截断(warning C4305: 'initializing' : truncation from ...

  7. Repeater的j简单使用

    嘿嘿,今天没有任务,所以突然想起来我之前记得笔 记说要把repeater的使用以及获取值的详细使用总结一下,所以这就闲来无聊总结一下,虽然现在不会使用这些小知识点的,但是我感觉自己的学习还是要 不断地 ...

  8. 十款不错的Hybrid App移动开发框架

    本文转载至http://www.pureasme.com/blog/2015/0419476.html ionic 是个高级的 HTML5 移动端应用框架,是个很漂亮的使用 HTML5 开发混合移动应 ...

  9. Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.0.1.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempt

    第一次用 Spring Starter Project 创建一个Spring应用时,POM 文件报错: Project build error: Non-resolvable parent POM f ...

  10. Linq-string判断忽略大小写

    Coupon203Play play = dbContext.Coupon203Plays.Where(u => u.VerifyCode.Equals(verifyCode,StringCom ...