MySQL MyIsam 存储引擎索引长度限制测试记录
MySQL MyIsam 存储引擎在创建索引的时候,索引键长度是有一个较为严格的长度限制的,所有索引键最大长度总和不能超过1000,而且不是实际数据长度的总和,而是索引键字段定义长度的总和。下面做个简单的测试,记录一下。
root@sky:~# mysql -u sky -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.0.51a-log MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
sky@127.0.0.1 : (none) 05:23:08> use test;
Database changed
sky@127.0.0.1 : test 05:23:11>
sky@127.0.0.1 : test 05:23:12>
先创建一个MyIsam表,字符集选择latin1,三个字段均设置为varchar 255,:
sky@127.0.0.1 : test 05:23:12> create table test_ind
-> (a varchar(255),
-> b varchar(255),
-> c varchar(255)
-> ) engine=myisam charset=latin1;
Query OK, 0 rows affected (0.01 sec)
创建效果:
sky@127.0.0.1 : test 05:23:32> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varchar(255) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
三个字段联合索引(长度应该在1000以内)
sky@127.0.0.1 : test 05:23:41> create index test_a_b_c_ind on test_ind(a,b,c);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
我们看到,创建成功了。
下面我们做一次字符集转换,将字符集转换成utf8
sky@127.0.0.1 : test 05:25:54> alter table test_ind convert to charset utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
sky@127.0.0.1 : test 05:26:24>
sky@127.0.0.1 : test 05:28:03> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varcha
相关文档:
1. -static 13%
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static
静态链接提高13%性能
2. -pgcc 1%
CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
CXXFLAGS="-O3 -mpentiumpro -mstack-alig ......
---- 在数据库的应用开发中,常常会遇到性能和代价的之间矛盾。以作者在开发股市行
情查询和交易系统中遇到的问题为例,要在实时记录1000多只股票每分钟更新一次的行
情数据的同时,响应大量并发用户的数据查询请求。考虑到性价比和易维护性,系统又
要求在基于PC服务器,Windows NT平台的软硬件环境下实现。开 ......
mysql set names 问题
mysql_query("set names 'utf8'");
一直以来总以为set names 是用来设置msyql 的字符集的,最近作个东西才发现自己认识上的错误,
查一下手册
SET NAMES ‘x‘语句与这三个语句等价:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> ......
前一直没注意这一点,突然一闪念想起来,下面唠唠:
比方说有一个文章表,我们要实现某个类别下按时间倒序列表显示功能:
SELECT * from articles WHERE category_id = … ORDER BY created DESC LIMIT …
这样的查询很常见,基本上不管什么应用里都能找出一大把类似的SQL来,学院派的读者看到上面的S ......