mysql> show index from tb_user;+---------+------------+----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |+---------+------------+----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+| tb_user |0| PRIMARY |1| id | A |24|NULL|NULL|| BTREE ||| YES |NULL|| tb_user |0| idx_user_phone |1| phone | A |24|NULL|NULL|| BTREE ||| YES |NULL|| tb_user |1| idx_user_name |1| name | A |24|NULL|NULL|| BTREE ||| YES |NULL|| tb_user |1| idx_user_pro_age_sta |1| profession | A |16|NULL|NULL| YES | BTREE ||| YES |NULL|| tb_user |1| idx_user_pro_age_sta |2| age | A |22|NULL|NULL| YES | BTREE ||| YES |NULL|| tb_user |1| idx_user_pro_age_sta |3| status | A |24|NULL|NULL| YES | BTREE ||| YES |NULL|| tb_user |1| idx_email |1| email | A |24|NULL|NULL| YES | BTREE ||| YES |NULL|+---------+------------+----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+7 rows in set(0.00 sec)
mysql>
1.3、查询 phone=‘17799990015’
mysql> select * from tb_user where phone='17799990015';+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+| id | name | phone | email | profession | age | gender | status | createtime |+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+|16| 妲己 |17799990015|2783238293@qq.com | 软件工程 |31|2|0|2001-01-3000:00:00|+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+1 row in set(0.00 sec)
mysql>
1.4、执行计划 phone=‘17799990015’
mysql> explain select * from tb_user where phone='17799990015';+----+-------------+---------+------------+-------+----------------+----------------+---------+-------+------+----------+-------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+-------+----------------+----------------+---------+-------+------+----------+-------+|1| SIMPLE | tb_user |NULL|const| idx_user_phone | idx_user_phone |46|const|1|100.00|NULL|+----+-------------+---------+------------+-------+----------------+----------------+---------+-------+------+----------+-------+1 row in set,1warning(0.00 sec)
mysql>
1.5、查询 substring(phone,10,2) =‘15’
mysql> select * from tb_user where substring(phone,10,2)='15';+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+| id | name | phone | email | profession | age | gender | status | createtime |+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+|16| 妲己 |17799990015|2783238293@qq.com | 软件工程 |31|2|0|2001-01-3000:00:00|+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+1 row in set(0.00 sec)
mysql>
1.6、执行计划 substring(phone,10,2) =‘15’
mysql> explain select * from tb_user where substring(phone,10,2)='15';+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+|1| SIMPLE | tb_user |NULL| ALL |NULL|NULL|NULL|NULL|24|100.00| Using where |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+1 row in set,1warning(0.00 sec)
mysql>
phone索引失效
2、字符串不加引号
字符串类型字段使用时,不加引号,索引将失效。
2.1、查询 phone=17799990015
mysql> select * from tb_user where phone=17799990015;+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+| id | name | phone | email | profession | age | gender | status | createtime |+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+|16| 妲己 |17799990015|2783238293@qq.com | 软件工程 |31|2|0|2001-01-3000:00:00|+----+------+-------------+-------------------+------------+------+--------+--------+---------------------+1 row in set(0.00 sec)
mysql>
2.2、执行计划 phone=17799990015
mysql> explain select * from tb_user where phone=17799990015;+----+-------------+---------+------------+------+----------------+------+---------+------+------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+------+----------------+------+---------+------+------+----------+-------------+|1| SIMPLE | tb_user |NULL| ALL | idx_user_phone |NULL|NULL|NULL|24|10.00| Using where |+----+-------------+---------+------------+------+----------------+------+---------+------+------+----------+-------------+1 row in set,3warnings(0.00 sec)
mysql>
字符串没有加单引号,所以phon索引失效
2.3、执行计划 profession=‘软件工程’ and age=31 and status=0
mysql> explain select * from tb_user where profession='软件工程'and age=31and status=0;+----+-------------+---------+------------+------+----------------------+----------------------+---------+-------------+------+----------+-----------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+------+----------------------+----------------------+---------+-------------+------+----------+-----------------------+|1| SIMPLE | tb_user |NULL| ref | idx_user_pro_age_sta | idx_user_pro_age_sta |49|const,const|1|10.00| Using index condition |+----+-------------+---------+------------+------+----------------------+----------------------+---------+-------------+------+----------+-----------------------+1 row in set,2warnings(0.00 sec)
mysql>
mysql> select * from tb_user where profession like '软件%';+----+--------+-------------+--------------------+------------+------+--------+--------+---------------------+| id | name | phone | email | profession | age | gender | status | createtime |+----+--------+-------------+--------------------+------------+------+--------+--------+---------------------+|5| 花木兰 |17799990004|19980729@sina.com | 软件工程 |23|2|1|2001-04-2200:00:00||1| 吕布 |17799990000| lvbu666@163.com | 软件工程 |23|1|6|2001-02-0200:00:00||16| 妲己 |17799990015|2783238293@qq.com | 软件工程 |31|2|0|2001-01-3000:00:00||15| 貂蝉 |17799990014|84958948374@qq.com | 软件工程 |40|2|3|2001-02-1200:00:00|+----+--------+-------------+--------------------+------------+------+--------+--------+---------------------+4 rows in set(0.00 sec)
mysql>
3.2、执行计划 profession like ‘软件%’
mysql> explain select * from tb_user where profession like '软件%';+----+-------------+---------+------------+-------+----------------------+----------------------+---------+------+------+----------+-----------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+-------+----------------------+----------------------+---------+------+------+----------+-----------------------+|1| SIMPLE | tb_user |NULL| range | idx_user_pro_age_sta | idx_user_pro_age_sta |47|NULL|4|100.00| Using index condition |+----+-------------+---------+------------+-------+----------------------+----------------------+---------+------+------+----------+-----------------------+1 row in set,1warning(0.00 sec)
mysql>
profession的key_len=47 profession命中索引
3.3、执行计划 profession like ‘%软件’
mysql> explain select * from tb_user where profession like '%软件';+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+|1| SIMPLE | tb_user |NULL| ALL |NULL|NULL|NULL|NULL|24|11.11| Using where |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+1 row in set,1warning(0.00 sec)
mysql>
头部模糊匹配,profession索引失效。
3.4、执行计划 profession like ‘%软件%’
mysql> explain select * from tb_user where profession like '%软件%';+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+|1| SIMPLE | tb_user |NULL| ALL |NULL|NULL|NULL|NULL|24|11.11| Using where |+----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+1 row in set,1warning(0.00 sec)
mysql>
DS:《What Are the Data-Centric AI Concepts behind GPT Models?通过三个数据为中心的人工智能目标(训练数据开发、推理数据开发和数据维护)揭示GPT模型背后的数据为中心的人工智能概念》解读—GPT-1/GPT-2/GPT-3系列对比(语料大小参数量解码层数上下文长度隐藏层…
试想一下,当你拨打客服咨询或售后电话时,没有漫长的等待,瞬时在手机中看到清晰的客服人员的脸,你说一句,ta说一句,你们流畅的沟通,仿佛线下面对面交流……
这是VoLTE(Voice over LT…
前言
最近大模型这么火,就想着玩一下,作为非 AI 从业者,最好的方式就是调用云服务的 API 来构建自己的 AI 应用。首选当然是国外的 ChatGPT API,但是说实话那个玩意有点贵,而且最近国内也被封禁不让调用了,…