引用
os:ubuntu 32bit
cpu:model name : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
memory:512M
普通7200 rpm:sata硬盘
BEGIN;
/**
*分组表
*order为了自定义排序
*create_time简化时间排序
*/
CREATE TABLE `contactgroup` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`email` varchar(64) NOT NULL,
`name` varchar(32) NOT NULL,
`create_time` datetime NOT NULL,
`order` integer NOT NULL
)
;
/**
*
*联系人表,和以前的列基本一至
*某些字段的长度可能需要在导入时发现异常情况后重新商议
*
*/
CREATE TABLE `contact` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`uid` integer NULL,
`name` varchar(32) NOT NULL,
`email` varchar(64) NOT NULL,
`important` integer NULL,
`mobile` varchar(15) NULL,
`sinauser` varchar(32) NULL,
`uc` integer NULL,
`letter` varchar(24) NULL,
`birthday` datetime NULL,
`homepage` varchar(128) NULL,
`email_bak` varchar(64) NULL,
`country` varchar(128) NULL,
`city` varchar(128) NULL,
`home_phone` varchar(15) NULL,
`home_addr` varchar(256) NULL,
`home_post` varchar(6) NULL,
`home_fax` varchar(15) NULL,
`company` varchar(128) NULL,
`company_title` varchar(128) NULL,
`company_addr` varchar(256) NULL,
`company_post` varchar(6) NULL,
`company_phone` varchar(15) NULL,
`company_fax` varchar(15) NULL,
`note` varchar(256) NULL,
`uic` integer NULL,
`sinanick` varchar(32) NULL
)
;
/**
*
*关联表
*在关联表里面增加了name & email两个冗余字段,是为了提升查询的速度,在应
用逻辑里面会有相应的代码保证数据一至性
*/
CREATE TABLE `contactgroup_contact` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`group_id` integer NOT NULL REFERENCES `contactgroup` (`id`),
`contact_id` integer NOT NULL REFERENCES `contact` (`id`),
`name` varchar(32) NOT NULL,
`email` varchar(64) NOT NULL,
UNIQUE (`group_id`, `contact_id`)
)
;
COMMIT;
索引另外加
一,准备数据,用python写个脚本,最后只插入了近4000W数据,单表最大1800W记录
root@hanyh-desktop:~# more insert.py
# -*- coding: utf-8 -*-
import MySQLdb
import random
conn = MySQLdb.connect (host = "x.x.x.x",
user = "edu",
passwd = "edu",
db = "addr")
cursor = conn.cursor ()
import datetime
import os
import string
sqls = ("delete from contactgroup_contact","delete from contactgroup","delete from contact")
for sql in sqls:
cursor.execute(sql)
email = ""
c_id = 1
for i in xrange(10000000):
random.seed() #Set the seed based on the system time.
j = (i % 10 )
if j == 0:
name = ''.join(random.choice(string.letters) for i in xrange(j+3))
email = name+str(i)+"@sina.cn"
else:
name = ''.join(random.choice(string.letters) for i in xrange(j+3))
g_id = (i+400)
# print g_id
g = "insert into contactgroup (id,email,name,create_time,`order`) values (%s,\'%s\',\'%s\',\'%s\',\'%s\')" %
(g_id,email,name,datetime.datetime.now(),i)
# print g
cursor.execute (g)
for k in xrange(5):
c_id = c_id+1
c_name = ''.join(random.choice(string.letters) for i in xrange(5))
c_email = name+str(k)+"@sina.com"
c = "insert into contact(id,name,email) values (%s,\'%s\',\'%s\')" %(c_id,c_name,c_email)
# print c
cursor.execute (c)
r = "insert into contactgroup_contact(id,group_id,contact_id,name,email) values (%s,%s,%s,\'%s\',\'%s\'
)" % (c_id,g_id,c_id,c_name,c_email)
cursor.execute(r)
cursor.close ()
conn.close ()
二,主键查询:
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
for($j=0;$j<10;$j++) {
$time_start = microtime_float();
$link = mysql_connect('x.x.x.x', 'edu', 'edu');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('addr', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$contacts = array();
for($i=1;$i<10000;$i++) {
$id = mt_rand(2, 18994235);
$sql = "select name,email from contact where id=$id";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$name = $row[0];
$email = $row[1];
$contacts[] = array($name,$email);
}
mysql_close($link);
$fp = fopen("contacts.dat","w");
fwrite($fp,serialize($contacts));
fclose($fp);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "$time\n";
}
?>
结果:
1W次查询,160s左右,无并发
并发查询,机器负载15+...
$ab -n10000 -c10 -t100 http://localhost/mail_bench/get_email2.php
Time taken for tests: 100.041 seconds
Complete requests: 1659
Failed requests: 1549
(Connect: 0, Receive: 0, Length: 1549, Exceptions: 0)
Write errors: 0
Total transferred: 411493 bytes
HTML transferred: 24946 bytes
Requests per second: 16.58 [#/sec] (mean)
Time per request: 603.022 [ms] (mean)
Time per request: 60.302 [ms] (mean, across all concurrent requests)
Transfer rate: 4.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 5
Processing: 2 600 584.0 857 2816
Waiting: 1 600 584.0 857 2815
Total: 2 600 584.0 857 2816
Percentage of the requests served within a certain time (ms)
50% 855
66% 1059
75% 1122
80% 1169
90% 1275
95% 1345
98% 1419
99% 1474
100% 2816 (longest request)
三,non-index查询:
$contacts = array();
$str = file_get_contents ("contacts.dat");
$contacts = unserialize($str);
print count($contacts);
$i = 1;
foreach($contacts as $c) {
$mail = $c[1];
$sql = "select name,email from contact where email='".$mail."'";
print $i.":".$sql."\n";
$i += 1;
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
....
62:select name,email from contact where email='EHnGVbJWnr3@sina.com'
63:select name,email from contact where email='phxy4@sina.com'
64:select name,email from contact where email='TzInjQksA4@sina.com'
65:select name,email from contact where email='mqWmwfyzX1@sina.com'
66:select name,email from contact where email='LFBElCNLmqXJ3@sina.com'
67:select name,email from contact where email='zPDh1@sina.com'
68:select name,email from contact where email='gHylduTVJWOk0@sina.com'
69:select name,email from contact where email='PzRs1@sina.com'
70:select name,email from contact where email='QyU2@sina.com'
71:select name,email from contact where email='crBbqWByuhru2@sina.com'
72:select name,email from contact where email='hIrYVt2@sina.com'
73:select name,email from contact where email='OCwBTeE3@sina.com'
74:select name,email from contact where email='UuOBSFjIeCo3@sina.com'
75:select name,email from contact where email='ZWV1@sina.com'
执行到65个的时候,速度变得极慢,1分钟能出来3个...实在等不了了.
现在给email字段加index,该表的记录数为:18994235
mysql> alter table contact add index c_mail_idx (email);
执行了26分钟,结果还没出来.....
现在ubuntu上面跑的xfce对keyboard&mouse无反应....
只能ssh
继续等着:
查看状态:
mysql> show table status from contact \G
*************************** 1. row ***************************
Name: contact
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 18994235
Avg_row_length: 55
Data_length: 1063677100
Max_data_length: 281474976710655
Index_length: 194926592
Data_free: 0
Auto_increment: 18994237
Create_time: 2009-05-22 13:32:49
Update_time: 2009-05-22 18:35:24
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
*************************** 2. row ***************************
Name: contactgroup
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 3798847
Avg_row_length: 48
Data_length: 184490432
Max_data_length: 281474976710655
Index_length: 65113088
Data_free: 0
Auto_increment: 3799247
Create_time: 2009-05-22 14:24:51
Update_time: 2009-05-22 18:35:24
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
*************************** 3. row ***************************
Name: contactgroup_contact
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 18994234
Avg_row_length: 41
Data_length: 797757776
Max_data_length: 281474976710655
Index_length: 469504000
Data_free: 0
Auto_increment: 18994236
Create_time: 2009-05-22 13:32:51
Update_time: 2009-05-22 18:35:24
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
mysql> select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size, concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables where TABLE_SCHEMA = 'addr';
+-----------+----------------+-----------+------------+
| data_size | max_data_size | data_free | index_size |
+-----------+----------------+-----------+------------+
| 1951.14MB | 805306367.99MB | 0.00MB | 695.74MB |
+-----------+----------------+-----------+------------+
mysql> select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size, concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables where TABLE_NAME = 'contact';
+-----------+----------------+-----------+------------+
| data_size | max_data_size | data_free | index_size |
+-----------+----------------+-----------+------------+
| 1014.40MB | 536870911.99MB | 0.00MB | 185.89MB |
+-----------+----------------+-----------+------------+
mysql> select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size, concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables where TABLE_NAME = 'contactgroup_contact';
+-----------+----------------+-----------+------------+
| data_size | max_data_size | data_free | index_size |
+-----------+----------------+-----------+------------+
| 760.80MB | 536870911.99MB | 0.00MB | 447.75MB |
+-----------+----------------+-----------+------------+
1 row in set (0.04 sec)
分享到:
相关推荐
Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql测试数据。Mysql...
这份MySQL数据库考试测试试题涵盖了MySQL数据库的多个方面,包括单项选择题、聚合函数、游标、SELECT语句、条件表达式、CREATE TABLE语句、ALTER TABLE语句、DROP TABLE语句、视图、索引、事务处理、子查询、正则...
MySQL查询分析器通常具备多种功能,包括编写、测试、优化以及监控SQL语句,以提升数据库系统的整体效率。 在MySQL的世界里,查询分析器扮演着至关重要的角色。它允许用户输入SQL命令,然后通过解析这些命令来与...
使用MySQL官方测试数据库,你可以实践如何创建、修改和查询数据库中的表,这包括使用`CREATE TABLE`语句来定义表结构,`ALTER TABLE`来修改表结构,以及`SELECT`来检索数据。 数据库通常由多个表组成,每个表都有...
### 两种MySQL递归Tree查询效率分析 #### 一、背景与目的 在数据库操作中,经常需要处理具有层级结构的数据。例如,在处理组织结构、文件系统或是地区划分时,通常会采用递归的方式来查询这些层级关系。MySQL作为...
根据提供的文件信息,我们可以推断出这份文档主要包含MySQL数据库相关的考试练习题目。MySQL是一种广泛使用的开源关系型数据库管理系统(RDBMS),因其性能稳定、易于使用和成本低廉等特点,在互联网应用开发中非常...
1. **性能测试**:通过导入这30W条数据,可以测试MySQL在高并发读写、复杂查询等方面的表现。例如,查看索引的建立是否合理,是否能有效提高查询速度;检查数据库的内存配置是否满足大数据量操作的需求;评估查询...
本文主要探讨的是在MySQL 5.7版本中进行时间范围查询的性能测试,这对于数据库优化和应用程序的高效运行具有重要意义。 首先,我们要理解MySQL 5.7在时间类型处理上的改进。MySQL支持多种时间类型,如DATE、TIME、...
【PHP+mYsql在线考试系统】是一个基于PHP编程语言和MySQL数据库技术构建的网络应用程序,主要功能是提供用户进行线上测试和考核。这样的系统通常包括考生注册、登录、选择考试、答题、提交试卷以及查看成绩等多个...
【MySQL数据库测试工程】 在IT领域,数据库是存储和管理数据的核心工具,而MySQL作为一款开源、免费的关系型数据库管理系统,被广泛应用于各种项目开发中。在这个“mysql数据库测试工程”中,我们将探讨如何结合...
“ceshi.sql”则是一个SQL脚本文件,通常用于测试数据库查询或数据导入。你可以在这个文件中看到一些SQL查询语句,例如创建表、插入数据、更新数据或选择数据等。这些语句可以用于验证“mysql2.e”模块的功能是否...
在本场景中,"MYSQL官方最新测试数据库 test_db.zip" 是一个包含了MySQL官方提供的用于测试目的的数据库文件。这个数据库可能包含了各种示例表、数据和预设的查询,以帮助开发者和管理员熟悉MySQL的功能和性能。 ...
基于QT和MySql的考试练习管理系统.zip基于QT和MySql的考试练习管理系统.zip 基于QT和MySql的考试练习管理系统.zip基于QT和MySql的考试练习管理系统.zip 基于QT和MySql的考试练习管理系统.zip基于QT和MySql的考试练习...
MySQL连接测试程序是一种基于VC(Visual C++)的软件开发工具,用于通过API接口与MySQL数据库进行交互。在本文中,我们将深入探讨如何利用API方式访问MySQL数据库,并提供查询示例,帮助你理解和掌握相关技术。 ...
Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的在线考试系统源码 Django + python + mysql的...
在进行MySQL多表查询与EXISTS查询的性能对比之前,首先需要了解测试环境的相关配置。虽然原文中并未给出具体的测试环境细节,但在实际操作中,这一步骤至关重要。通常会涉及到服务器硬件配置(如CPU、内存)、操作...
示例 演示如何阅读MySQL的查询执行计划。先创建5张表,命令如下(各表的数据量为:t1...附件中的脚本是创建导出结果,下载后,直接在自己的测试数据库中执行“source test_env.sql”命令即可创建自己的mysql测试环境。