From 34ec7ab9e0f24bf55346a80acbe22dbe2a5a16b7 Mon Sep 17 00:00:00 2001
From: pengshiyu <1940607002@qq.com>
Date: Sun, 8 May 2022 22:16:17 +0800
Subject: [PATCH] fix
---
blog/mysq-advance/mysql-index.md | 420 +++++++++++++++++++++++++++++++
blog/php-mysql/index.md | 2 +-
blog/php-mysql/sql-function.md | 13 +-
index.html | 35 +++
static/js/prism-python.min.js | 1 +
5 files changed, 468 insertions(+), 3 deletions(-)
create mode 100644 static/js/prism-python.min.js
diff --git a/blog/mysq-advance/mysql-index.md b/blog/mysq-advance/mysql-index.md
index 69e0dae..f80da2f 100644
--- a/blog/mysq-advance/mysql-index.md
+++ b/blog/mysq-advance/mysql-index.md
@@ -867,3 +867,423 @@ mysql> explain select count(*) from tb_user;
1 row in set, 1 warning (0.00 sec)
```
+索引使用
+
+
+创建测试表
+
+```sql
+create table tb_sku(
+ id int primary key auto_increment,
+ uuid char(36)
+);
+```
+
+## 6、索引使用
+
+### 6.1、验证索引效率
+
+生成测试数据(1000万条记录)
+
+方式一:使用MySQL的自定义函数
+
+速度较慢,适合较少的数据
+
+```sql
+-- 1、定义个生成测试数据的函数
+-- 修改语句结束符
+delimiter $$
+
+-- 创建函数
+create function init_data(total int) returns int
+begin
+ -- 声明局部变量
+ declare i int default 0;
+
+ -- 循环处理
+ while i < total do
+ -- 生成测试数据
+ insert into tb_sku (`uuid`) values (uuid());
+ set i = i + 1;
+ end while;
+
+ -- 返回值
+ return i;
+end
+
+-- 结束
+$$
+
+-- 修改语句结束符
+delimiter ;
+
+
+-- 2、调用函数生成数据(100W)
+mysql> select init_data(1000000);
++--------------------+
+| init_data(1000000) |
++--------------------+
+| 1000000 |
++--------------------+
+1 row in set (1 min 16.08 sec)
+
+-- 3、删除函数
+drop function init_data;
+```
+
+方式二:
+
+使用Python脚本生成,适合生成大量数据
+
+```python
+# pip install records mysqlclient
+import records
+import uuid
+
+db = records.Database('mysql://root:123456@localhost/data?charset=utf8')
+
+# 100 * 100000 = 1000万条数据
+for i in range(100):
+ data = [{'uuid': str(uuid.uuid4())} for i in range(100000)]
+ db.bulk_query("insert into tb_sku(uuid) values(:uuid)", data)
+
+```
+
+```sql
+mysql> select count(*) from tb_sku;
++----------+
+| count(*) |
++----------+
+| 10000000 |
++----------+
+1 row in set (0.38 sec)
+
+
+mysql> select * from tb_sku limit 1;
++----+--------------------------------------+
+| id | uuid |
++----+--------------------------------------+
+| 1 | 166fa508-2911-494d-aed2-2a2ee81a2a64 |
++----+--------------------------------------+
+1 row in set (0.00 sec)
+```
+
+
+验证索引效率
+```sql
+-- 为建立索引之前,执行如下SQL,查看SQL的耗时
+mysql> select * from tb_sku where uuid = '166fa508-2911-494d-aed2-2a2ee81a2a64';
++----+--------------------------------------+
+| id | uuid |
++----+--------------------------------------+
+| 1 | 166fa508-2911-494d-aed2-2a2ee81a2a64 |
++----+--------------------------------------+
+1 row in set (2.15 sec)
+
+-- 创建索引
+mysql> create index idx_sku_uuid on tb_sku (uuid);
+Query OK, 0 rows affected (21.85 sec)
+Records: 0 Duplicates: 0 Warnings: 0
+
+-- 再次执行相同的SQL语句,查看SQL耗时
+mysql> select * from tb_sku where uuid = '166fa508-2911-494d-aed2-2a2ee81a2a64';
++----+--------------------------------------+
+| id | uuid |
++----+--------------------------------------+
+| 1 | 166fa508-2911-494d-aed2-2a2ee81a2a64 |
++----+--------------------------------------+
+1 row in set (0.01 sec)
+
+-- 通过主键查询
+mysql> select * from tb_sku where id = 1;
++----+--------------------------------------+
+| id | uuid |
++----+--------------------------------------+
+| 1 | 166fa508-2911-494d-aed2-2a2ee81a2a64 |
++----+--------------------------------------+
+1 row in set (0.00 sec)
+
+-- 查看执行计划
+mysql> explain select * from tb_sku where uuid = '166fa508-2911-494d-aed2-2a2ee81a2a64';
++----+-------------+--------+------------+------+---------------+--------------+---------+-------+------+----------+-------------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+--------+------------+------+---------------+--------------+---------+-------+------+----------+-------------+
+| 1 | SIMPLE | tb_sku | NULL | ref | idx_sku_uuid | idx_sku_uuid | 145 | const | 1 | 100.00 | Using index |
++----+-------------+--------+------------+------+---------------+--------------+---------+-------+------+----------+-------------+
+1 row in set, 1 warning (0.00 sec)
+```
+
+
+### 6.2、最左前缀法则
+
+如果索引了多列(联合索引),要遵守最左前缀法则。
+
+最左前缀法则指的是查询从索引的最左侧列开始,并且不跳过索引中的列。
+
+如果跳过某一列,索引将部分失效(后面的字段索引失效)
+
+```sql
+-- 查看表数据
+select * from tb_user;
++----+--------+-------------+------------+------+--------+-------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+-------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
+| 2 | 关羽 | 15210231297 | 物理 | 24 | 1 | 3339@qq.com |
+| 3 | 刘备 | 15214231297 | 数学 | 25 | 0 | 666@qq.com |
+| 4 | 孙权 | 15215231297 | 语文 | 20 | 1 | 111@qq.com |
++----+--------+-------------+------------+------+--------+-------------+
+4 rows in set (0.01 sec)
+
+-- 查看表中的索引
+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 | 4 | NULL | NULL | | BTREE | | | YES | NULL |
+| tb_user | 0 | idx_user_phone | 1 | phone | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_name | 1 | name | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 1 | profession | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 2 | age | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 3 | status | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_email | 1 | email | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
++---------+------------+--------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
+7 rows in set (0.06 sec)
+
+-- 查询数据
+select * from tb_user where profession = '美术' and age = 23 and status = 1;
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+-- 查看用到的索引:profession、age、status
+explain select * from tb_user where profession = '美术' and age = 23 and status = 1;
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+| 1 | SIMPLE | tb_user | NULL | ref | idx_user_profession_age_status | idx_user_profession_age_status | 53 | const,const,const | 1 | 100.00 | NULL |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+1 row in set, 1 warning (0.00 sec)
+
+-- 查询profession和age,使用到了索引
+explain select * from tb_user where profession = '美术' and age = 23;
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------+------+----------+-------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------+------+----------+-------+
+| 1 | SIMPLE | tb_user | NULL | ref | idx_user_profession_age_status | idx_user_profession_age_status | 48 | const,const | 1 | 100.00 | NULL |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------+------+----------+-------+
+1 row in set, 1 warning (0.00 sec)
+
+-- 单独查询profession,使用到了索引
+explain select * from tb_user where profession = '美术';
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-------+
+| 1 | SIMPLE | tb_user | NULL | ref | idx_user_profession_age_status | idx_user_profession_age_status | 43 | const | 1 | 100.00 | NULL |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-------+
+1 row in set, 1 warning (0.01 sec)
+
+-- 查询age和status,没有使用到索引
+explain select * from tb_user where age = 23 and status = 1;
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+| 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 | 4 | 25.00 | Using where |
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+1 row in set, 1 warning (0.01 sec)
+
+-- 单独查询status,没有使用到索引
+explain select * from tb_user where status = 1;
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+| 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 | 4 | 25.00 | Using where |
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+1 row in set, 1 warning (0.00 sec)
+
+-- 跳过中间的age字段,只用到了profession,而status没有用到索引
+explain select * from tb_user where profession = '美术' and status = 1;
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-----------------------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-----------------------+
+| 1 | SIMPLE | tb_user | NULL | ref | idx_user_profession_age_status | idx_user_profession_age_status | 43 | const | 1 | 25.00 | Using index condition |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------+------+----------+-----------------------+
+1 row in set, 1 warning (0.00 sec)
+
+-- 索引字段可以交换顺序,也能使用到索引
+explain select * from tb_user where age = 23 and status = 1 and profession = '美术';
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+| 1 | SIMPLE | tb_user | NULL | ref | idx_user_profession_age_status | idx_user_profession_age_status | 53 | const,const,const | 1 | 100.00 | NULL |
++----+-------------+---------+------------+------+--------------------------------+--------------------------------+---------+-------------------+------+----------+-------+
+1 row in set, 1 warning (0.00 sec)
+```
+
+### 6.3、范围查询
+
+联合索引中,出现范围查询(>、<),范围查询右侧的列索引失效
+
+```sql
+select * from tb_user where profession = '美术' and age > 22 and status = 1;
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+-- age使用了大于号>,只有profession和age用到了索引
+explain select * from tb_user where profession = '美术' and age > 22 and status = 1;
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+| 1 | SIMPLE | tb_user | NULL | range | idx_user_profession_age_status | idx_user_profession_age_status | 48 | NULL | 1 | 25.00 | Using index condition |
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+1 row in set, 1 warning (0.01 sec)
+
+-- 三个字段都用到了索引
+explain select * from tb_user where profession = '美术' and age >= 22 and status = 1;
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+| 1 | SIMPLE | tb_user | NULL | range | idx_user_profession_age_status | idx_user_profession_age_status | 53 | NULL | 1 | 25.00 | Using index condition |
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+1 row in set, 1 warning (0.00 sec)
+```
+
+## 7、索引失效的场景
+
+### 7.1、索引列运算
+
+不要在索引列上进行运算操作,否则索引将失效
+
+```sql
+-- 查看数据
+mysql> select * from tb_user;
++----+--------+-------------+------------+------+--------+-------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+-------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
+| 2 | 关羽 | 15210231297 | 物理 | 24 | 1 | 3339@qq.com |
+| 3 | 刘备 | 15214231297 | 数学 | 25 | 0 | 666@qq.com |
+| 4 | 孙权 | 15215231297 | 语文 | 20 | 1 | 111@qq.com |
++----+--------+-------------+------------+------+--------+-------------+
+4 rows in set (0.00 sec)
+
+-- 查看索引
+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 | 4 | NULL | NULL | | BTREE | | | YES | NULL |
+| tb_user | 0 | idx_user_phone | 1 | phone | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_name | 1 | name | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 1 | profession | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 2 | age | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_profession_age_status | 3 | status | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
+| tb_user | 1 | idx_user_email | 1 | email | A | 4 | NULL | NULL | YES | BTREE | | | YES | NULL |
++---------+------------+--------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
+7 rows in set (0.01 sec)
+
+-- 按照手机号查询数据
+mysql> select * from tb_user where phone = '15210231227';
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+-- 分析索引使用情况
+explain select * from tb_user where phone = '15210231227';
++----+-------------+---------+------------+-------+----------------+----------------+---------+-------+------+----------+-------+
+| 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 | 47 | const | 1 | 100.00 | NULL |
++----+-------------+---------+------------+-------+----------------+----------------+---------+-------+------+----------+-------+
+1 row in set, 1 warning (0.00 sec)
+
+-- 查询手机号后两位
+select * from tb_user where substring(phone, 10, 2) = '27';
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+-- 查看执行效率
+explain select * from tb_user where substring(phone, 10, 2) = '27';
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+| 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 | 4 | 100.00 | Using where |
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+1 row in set, 1 warning (0.01 sec)
+```
+
+### 7.2、字符串不加引号
+
+字符串类型字段使用时,不加引号,索引将失效
+
+```sql
+-- 字符串查询可以不加引号
+select * from tb_user where phone = 15210231227;
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+-- 不加引号的字符串查询没有走索引
+explain select * from tb_user where phone = 15210231227;
++----+-------------+---------+------------+------+----------------+------+---------+------+------+----------+-------------+
+| 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 | 4 | 25.00 | Using where |
++----+-------------+---------+------------+------+----------------+------+---------+------+------+----------+-------------+
+1 row in set, 3 warnings (0.00 sec)
+```
+
+### 7.3、模糊查询
+
+- 如果仅仅是尾部模糊匹配,索引不会失效;
+- 如果是头部模糊匹配,索引失效
+
+```sql
+-- 尾部模糊查询
+select * from tb_user where profession like '美%';
++----+--------+-------------+------------+------+--------+------------+
+| id | name | phone | profession | age | status | email |
++----+--------+-------------+------------+------+--------+------------+
+| 1 | 张飞 | 15210231227 | 美术 | 23 | 1 | 123@qq.com |
++----+--------+-------------+------------+------+--------+------------+
+1 row in set (0.00 sec)
+
+
+-- 尾部模糊匹配,索引不会失效;
+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_profession_age_status | idx_user_profession_age_status | 43 | NULL | 1 | 100.00 | Using index condition |
++----+-------------+---------+------------+-------+--------------------------------+--------------------------------+---------+------+------+----------+-----------------------+
+1 row in set, 1 warning (0.00 sec)
+
+
+-- 头部模糊匹配,索引失效
+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 | 4 | 25.00 | Using where |
++----+-------------+---------+------------+------+---------------+------+---------+------+------+----------+-------------+
+1 row in set, 1 warning (0.01 sec)
+```
+
+
diff --git a/blog/php-mysql/index.md b/blog/php-mysql/index.md
index 005fb3c..94ab4c4 100644
--- a/blog/php-mysql/index.md
+++ b/blog/php-mysql/index.md
@@ -60,7 +60,7 @@
[流程结构 if while](blog/php-mysql/sql-if-while.md)
-[函数 function](blog/php-mysql/sql-function.md)
+[内置函数和自定义函数 function](blog/php-mysql/sql-function.md)
[存储过程 procedure](blog/php-mysql/sql-procedure.md)
diff --git a/blog/php-mysql/sql-function.md b/blog/php-mysql/sql-function.md
index e87b18a..e471d17 100644
--- a/blog/php-mysql/sql-function.md
+++ b/blog/php-mysql/sql-function.md
@@ -1,4 +1,4 @@
-# 函数 function
+# 内置函数和自定义函数 function
函数分为两类:系统函数和自定义函数
@@ -19,9 +19,12 @@ length | 判断字符串的字节数,与字符集有关
concat | 连接字符串
insrt | 检查字符是否在目标字符串中,存在返回其位置,不存在返回 0
lcase | 全部小写
-left | 左侧开始截取字符串,直到指定位置
ltrim | 消除左边的空格
+left(str, length) | 左侧开始截取字符串,直到指定位置
+right(str, length) | 右侧开始截取字符串,直到指定位置
mid | 从中间指定位置开始截取,如果不指定截取长度,直接到最后
+`substring(str, index, [length]`) | 从指定位置开始,指定截取长度
+substring_index(str, delim, count) | 按照关键字截取
示例
@@ -39,9 +42,15 @@ select instr('你好中国', '我'); // 0
select lcase('aBcd'); // abcd
select left('aBcd', 2); // aB
+select right('abcdef', 2); // ef
+select substring('abcdef', 2, 3); // bcd
+select substring('abcdef', -2, 3); // ef
select ltrim(' abc d '); // abc d
select mid('你好中国', 3); // 中国
+
+select substring_index('www.baidu.com', '.', 2); // www.baidu
+select substring_index('www.baidu.com', '.', -2); // baidu.com
```
### 1.2、时间函数
diff --git a/index.html b/index.html
index bc51b94..fa5825b 100644
--- a/index.html
+++ b/index.html
@@ -18,6 +18,15 @@
href="static/js/vue@4.12.2.min.css">
@@ -85,12 +116,16 @@
+
+
+
+
diff --git a/static/js/prism-python.min.js b/static/js/prism-python.min.js
new file mode 100644
index 0000000..96932b0
--- /dev/null
+++ b/static/js/prism-python.min.js
@@ -0,0 +1 @@
+Prism.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern://,alias:"punctuation"},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:"string"},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:["annotation","punctuation"],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},Prism.languages.python["string-interpolation"].inside.interpolation.inside.rest=Prism.languages.python,Prism.languages.py=Prism.languages.python;
\ No newline at end of file
--
GitLab