
本文共 13426 字,大约阅读时间需要 44 分钟。
������������
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ��������� ������������������������
��������� ��������� ������������������������mysql������������������������������mysql������������������������������������������������������������������������������������������������������������������������ ������������������������������������
���������������������������������������������������������������������������������������������
������������������������������
������
���������������������������������������������������������������������������������������
��� ���������������������������������������������������������������������������������������������������������������������������(Natural Key)������
������������������������������������������������������������������������������������������������������ ������������������������������������������������������������
��� ������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������uuid��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ������������������ ���������a������������������ ���������������������b��� ���������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
��� ���������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������ ���������������������34123322��� ������������������������100%��������������������������������������� + ���������������������������������������������������������������
��������������������������������������� ������+��������� ������������������������������������������������17��������������������������������������������������������� ��������������������������������������������������������������� ������ + ��������� + ������������������������������������������������������������������������������������������ + ������ + ������������ + ������ + ������ + ���������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������
���������������������������������������������������������a���������������b������������������������������������a������������������������b���������������������������������������������������������������������������
��� ��� b ������������������������������������a���
��� ���������������������������b������������
��������������������������������������������������������������������� ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������3���������������������������������������������������������������������
������
���������������������������������������������������������������������������������MySQL���������������������������������������������������������������������������������������������������������������������������������������������������������������������������MySQL������������������������������������������������������������������������������������������������������������������������������
������������������������person���������������2W���������������������2W���������������������������Phone������������������������������������������������������������������������������xxxx������������������
���������������������������������������������������������������������������������������������������������������������
������������������������������������������Phone������������������������������������������������������������������������������������������������������������������������������������������2W���������������������MySQL������������������������������������BTREE���HASH��� ���������������������Hash������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������
������������1������������MySql���������(������������)���������������������������������������������������������������
������������2������������������������������������
���������������
������������1������������������������������������������������������������������������������������������������������������
������������2������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������3������������������������������������������������������������������������������������������������������������������������������
���������������������
��������� ������������������������������
������������1������������������������������������������������������������������������������������������������������������������
������������2������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������3���������������������������(���������)������������������������������������������"������"������������������������������������������������������������������������������������������������������������
������������������������
���������������������������������������������������������������������������������������������java������������������������������������������������������
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, -- ������ `dt` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, -- ������uuid���������������id `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, -- ������������ `age` int(10) NULL DEFAULT NULL, -- ��������������������� `key` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, -- ������������ ������uuid������ PRIMARY KEY (`id`) USING BTREE -- ������������
������������������������������������������
1. ������������ test_primary_a
2. ������������ ��������� test_primary_d
3. ��������� ��������� test_primary_b
4. ������������ ��������� test_primary_c
������java, spring boot + mybatis���������������������������������������������������������������������������������������������
���mybatis���������
insert into test_primary_${code} ( `dt`, `name`, `age`, `key` ) values ( #{item.dt}, #{item.name}, #{item.age}, #{item.key} )
java������������������mybatis������������������������������
@Transactional(readOnly = false) public Object testPrimary (String type) { HashMap result = new HashMap(); // ��������������� ������������ long start = new Date().getTime(); // ��������������� ������������ int len = 0; try{ String[] names = {"������", "������", "������" , "������", "������", "������", "������", "������", "���������" , "���10"}; for (int w = 0; w < 1000; w++) { // ������������������ long startMil = new Date().getTime(); ArrayListitems = new ArrayList<>(); for (int i = 0; i < 10000; i++) { String dt = StringUtils.uuid(); String key = StringUtils.uuid(); int age = (int)((Math.random() * 9 + 1) * 10); // ������������ String name = names[(int)(Math.random() * 9 + 1)]; HashMap item = new HashMap<>(); item.put("dt", dt); item.put("key", key); item.put("age", age); item.put("name", name); items.add(item); } len += tspTagbodyMapper.insertTestData(items, type); long endMil = new Date().getTime(); // ������������������ result.put(w, endMil - startMil); } long end = new Date().getTime(); // ��������� result.put("all", end - start); result.put("len", len); return result; } catch (Exception e) { System.out.println(e.toString()); result.put("e", e.toString()); } return result; }
���������������������������������
1. ������������ test_primary_a ---------- ������������ 960MB
62������������������������������ ��������������������������� 4���
2. ������������ ��������� test_primary_d ������������ 1GB ������������ 1.36GB
75������������������������������ ��������������������������� 4.5���
3. ��������� ��������� test_primary_b ----------- ������������ 960MB
65������������������������������ ��������������������������� 4.2���
4. ������������ ��������� test_primary_c ----------- ������������ 1.54GB
219������������������������������ ��������������������������� 8������ ������������������������ ���������������������������������������������������������������������100��� ������������������������������ ������������������������������������������������1000������������������������������������������������������������15���������
������������
���������������������������name���������������������������������������������������������name
���������������
select name,age from test_primary_a where age=20 -- ������������ ��������� ������������11��� ������3.5���
select name,age from test_primary_a where name='������' and age=20 -- ������������ ��������� ������������11��� ������650������
select name,age from test_primary_b where age=20 -- ��������� ��������� ������������11��� ������7���
select name,age from test_primary_c where age=20 -- ������������ ��������� ������������11��� ������4.5���
���������
������������������
select name,age,`key`,dt from test_primary_a where age=20 and (name='������' or name = '������') and dt like '%abc%' -- ������������ ��������� ������������198 ������4.2���
������ select dt,name,age,`key` from test_primary_d where (name='������' or name = '������') and age=20 and dt like '%abc%' -- ������������ ��������� ������������204 ������650������
select name,age,`key`,dt from test_primary_d where age=20 and (name='������' or name = '������') and dt like '%abc%' -- ��������� ��������� ������������194 ������5.9���
select name,age,`key`,dt from test_primary_c where age=20 and (name='������' or name = '������') and dt like '%abc%' -- ������������ ��������� ������������11��� ������5���
������ ���������������������������������
select name,age,dt from test_primary_c where dt like '%0000%' and name='������' -- ������������ ��������� ������������359 ������8���
select name,age,dt from test_primary_c where dt like '%0000%' and name='������' -- ������������ ��������� ������������400 ������1���
���������
������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
��������������������������� + ���������������������������������2.4G��� ������������������1.54G ������������1���G ��� ������������������������������������������������������������������������������������������������������������������
��������������������������������������� ���������������������������������������������2-3������������������������������������������������������������������������������������������
������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������
发表评论
最新留言
关于作者
