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. ios开发之--仿购物类详情页面数量添加小功能

    话不多说先上图:

  2. ios开发之--打印bool值

    eg:NSLog(@"Hello,objective-c!");   @表示应该当作NSString字符串来处理. NSLog相当于C语言中的printf,常用于文字输出 NSLo ...

  3. Android中显示照片的Exif信息

    package com.hyzhou.pngexifdemo; import android.media.ExifInterface; import android.os.Bundle; import ...

  4. linux-友好显示文件大小

    4850905319b / 1024 /1024/1024 = 4.6G ls -lh

  5. 基于github+hexo搭建个人博客(window)

    0x01 环境搭建 1.Node.js环境 下载Node.js安装文件:https://nodejs.org/en/download/ 根据系统选择相应安装包下载,安装过程一路Next,默认设置即可. ...

  6. wireshark----linux

    1.[root@lc~]# tshark   Running as user "root" and group "root". This could be da ...

  7. App store最新审核标准公布

    本文转载至 http://blog.csdn.net/shuidonglCH/article/details/47083623 导读:苹果近日更新了App Store审核指南的相关章节,对此前版本进行 ...

  8. 使用createprocess()创建进程打开其他文件方法

    #include "stdafx.h"#include "windows.h"#include <iostream>#include "s ...

  9. Bootstrap学习总结笔记(24)-- 基于BootstrapValidator的Form表单验证

    Form表单进行数据验证是十分必要的,我们可以自己写JS脚本或者使用JQuery Validate 插件来实现.对于Bootstrap而言,利用BootstrapValidator来做Form表单验证 ...

  10. 百度编辑器(UEditor)自定义工具栏

    百度编辑器(UEditor)自定义工具栏的自定义 百度编辑器默认功能比较齐全,但是不一定是我们所需要的,有的功能可以去掉,用自己想要的就可以了,可以参考百度官方文档! 百度编辑器默认配置展示界面 如何 ...