hungzz 2020-04-10
1、索引
# 给 name 字段创建索引 aa mysql> create index aa on t_student(name); # 查看索引 mysql> show index from t_student; +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-----------+------------+----------+--------------+-------------+-----------+--- | t_student | 1 | aa | 1 | name | A | 2 | NULL | NULL | YES | BTREE | | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
# 删除索引 aa mysql> drop index aa on t_student;
# 给 name 字段创建唯一索引 mysql> create unique index bb on t_student(name); mysql> show index from t_student; +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | t_student | 0 | bb | 1 | name | A | 2 | NULL | NULL | YES | BTREE | | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
# 给 score 字段添加主键索引 mysql> alter table t_course add primary key(score); mysql> show index from t_course; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | t_course | 0 | PRIMARY | 1 | score | A | 6 | NULL | NULL | | BTREE | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2、视图
# 创建视图 v_stu mysql> create view v_stu as (select id,name,age from t_student);
# 查看创建的视图 v_stu mysql> show tables; +-------------------+ | Tables_in_student | +-------------------+ | t_course | | t_student | | v_stu | +-------------------+ mysql> select * from v_stu; +----+----------+------+ | id | name | age | +----+----------+------+ | 1 | zhangsan | 18 | | 2 | wangwu | 20 | | 3 | zhaoliu | 19 | | 4 | lisi | 22 | +----+----------+------+
mysql> alter view v_stu as (select id,name from t_student); mysql> select * from v_stu; +----+----------+ | id | name | +----+----------+ | 4 | lisi | | 2 | wangwu | | 1 | zhangsan | | 3 | zhaoliu | +----+----------+
# 删除视图 v_cou mysql> drop view v_cou; mysql> show tables; +-------------------+ | Tables_in_student | +-------------------+ | t_course | | t_student | | v_stu | +-------------------+
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。