详解MySQL 索引+explain

mysql视频教程栏目今天着重介绍索引+explain,为需要面试的准备。

详解MySQL 索引+explain

免费推荐:mysql视频教程

一、索引的介绍

在mysql中,索引就是数据结构,已经在文件中按照索引进行排序好的结构.使用索引可以加快我们的查询速度,但是对我们的数据增删改效率会降低.因为一个网站大部分都是查询,我们主要优化select语句.

二、MySQL中索引的分类

普通索引 key唯一索引 unique key unique key 别名 别名可忽略 别名可忽略主键索引 primary key(字段)全文索引myisam引擎支持(只对英文进行索引,mysql版本5.6也支持),sphinx(中文搜索)混合索引 多个字段组成的索引.如 key key_index(title,email)

三、索引的基本操作

1、给表添加索引

create table t_index(    id int not null auto_increment,    title varchar(30) not null default '',    email varchar(30) not null default '',    primary key(id),    unique key uni_email(email) ,    key key_title(title))engine=innodb charset=utf8;

查看表

desc tablename

mysql> desc t_index;+-------+-------------+------+-----+---------+----------------+| Field | Type        | Null | Key | Default | Extra          |+-------+-------------+------+-----+---------+----------------+| id    | int(11)     | NO   | PRI | NULL    | auto_increment || title | varchar(30) | NO   | MUL |         |                || email | varchar(30) | NO   | UNI |         |                |+-------+-------------+------+-----+---------+----------------+3 rows in set (0.01 sec)

查看表的创建语句

show create table tbalename/G

mysql> show create table t_index/G;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/G' at line 1mysql> show create table t_indexG;*************************** 1. row ***************************       Table: t_indexCreate Table: CREATE TABLE `t_index` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `title` varchar(30) NOT NULL DEFAULT '',  `email` varchar(30) NOT NULL DEFAULT '',  PRIMARY KEY (`id`),  UNIQUE KEY `uni_email` (`email`),  KEY `key_title` (`title`)) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)ERROR: No query specified

2、删除索引

删除主键索引

alter table table_name drop primary key;

注意:

mysql> alter table t_index drop primary key;ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

主键不一定是自增长,但是自增长一定是主键。

删除逐渐之前先要把主键索引的自增长去掉。

mysql> alter table t_index modify  id int not null;Query OK, 0 rows affected (0.05 sec)Records: 0  Duplicates: 0  Warnings: 0

再来删除主键

mysql> alter table t_index drop primary key;Query OK, 0 rows affected (0.04 sec)Records: 0  Duplicates: 0  Warnings: 0
删除普通和唯一的索引

alter table table_name drop key ‘索引的别名’

实际操作

mysql> alter table t_index drop key uni_email;Query OK, 0 rows affected (0.03 sec)Records: 0  Duplicates: 0  Warnings: 0
mysql> alter table t_index drop key key_title;Query OK, 0 rows affected (0.02 sec)Records: 0  Duplicates: 0  Warnings: 0

3、添加索引

alter table t_index add key key_title(title);alter table t_index add key uni_email(email);alter table t_index add primary key(id);

4、有无索引对比

create table article(id int not null auto_increment,no_index int,title varchar(30) not null default '',add_time datetime,primary key(id));

插入数据

mysql> insert into article(id,title,add_time) values(null,'ddsd1212123d',now());mysql> insert into article(title,add_time) select title,now() from article;Query OK, 10 rows affected (0.01 sec)Records: 10  Duplicates: 0  Warnings: 0mysql> update article set no_index=id;

有无索引查询数据对比

mysql> select * from article where no_index=1495298;+---------+----------+-----------+---------------------+| id      | no_index | title     | add_time            |+---------+----------+-----------+---------------------+| 1495298 |  1495298 | ddsd1123d | 2019-05-15 23:13:56 |+---------+----------+-----------+---------------------+1 row in set (0.28 sec)
mysql> select * from article where id=1495298;+---------+----------+-----------+---------------------+| id      | no_index | title     | add_time            |+---------+----------+-----------+---------------------+| 1495298 |  1495298 | ddsd1123d | 2019-05-15 23:13:56 |+---------+----------+-----------+---------------------+1 row in set (0.01 sec)

表结构

mysql> show create table articleG;*************************** 1. row ***************************       Table: articleCreate Table: CREATE TABLE `article` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `no_index` int(11) DEFAULT NULL,  `title` varchar(30) NOT NULL DEFAULT '',  `add_time` datetime DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1572824 DEFAULT CHARSET=utf81 row in set (0.00 sec)ERROR: No query specified

四、explain分析

使用explain可以对sql语句进行分析到底有没有使用到索引查询,从而更好的优化它.

我们只需要在select语句前面加上一句explain或者desc.

1、语法

explain|desc select * from tablename G;

2、分析

用刚才的两个有无索引对比看看

mysql> mysql> explain select * from article where no_index=1495298G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE//单表查询        table: article//查询的表名   partitions: NULL         type: ALL//索引的类型,从好到坏的情况是:system>const>range>index>Allpossible_keys: NULL//可能使用到的索引          key: NULL//实际使用到的索引      key_len: NULL//索引的长度          ref: NULL         rows: 1307580//可能进行扫描表的行数     filtered: 10.00        Extra: Using where1 row in set, 1 warning (0.00 sec)ERROR: No query specified
mysql> explain select * from article where id=1495298G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: const//当对主键索引进行等值查询的时候出现constpossible_keys: PRIMARY          key: PRIMARY//实际使用到的所有primary索引      key_len: 4//索引的长度4 = int占4个字节          ref: const         rows: 1//所扫描的行数只有一行     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)ERROR: No query specified

3、explain的type项分析

type项从优到差依次排序:

system:一般系统表只有一行记录的时候才会出现const:当对主键值进行等值查询的时候会出现,如where id=666666range:当对索引的值进行范围查询的时候会出现,如 where id<100000index:当我们查询的字段恰好是我们索引文件中的值,就会出现All:最差的一种情况,需要避免.

实际测试

mysql> use mysql;mysql> explain select * from userG;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: user   partitions: NULL         type: ALLpossible_keys: NULL          key: NULL      key_len: NULL          ref: NULL         rows: 3     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)
mysql> use test;mysql> explain select * from article where id=666666G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: constpossible_keys: PRIMARY          key: PRIMARY      key_len: 4          ref: const         rows: 1     filtered: 100.00        Extra: NULL
mysql> explain select * from article where id>666666G;mysql> explain select * from article where id<666666G;
mysql> explain select id  from article G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: indexpossible_keys: NULL          key: PRIMARY      key_len: 4          ref: NULL         rows: 1307580     filtered: 100.00        Extra: Using index1 row in set, 1 warning (0.00 sec)ERROR: No query specified

如果查询的字段在索引文件存在,那么就会直接从索引文件中进行查询,我们把这种查询称之为索引覆盖查询。

出现all,我们需要避免,因为进行全面扫描。

对于出现all的,可以给该字段增加普通索引查询

mysql> alter table article add key key_no_index(no_index);Query OK, 0 rows affected (1.92 sec)Records: 0  Duplicates: 0  Warnings: 0type为ref,应该是关联,但是ref是constmysql> explain select * from article where no_index=666666G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: refpossible_keys: key_no_index          key: key_no_index      key_len: 5          ref: const         rows: 1     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)速度飞跃mysql> select * from article where no_index=666666;+--------+----------+-----------+---------------------+| id     | no_index | title     | add_time            |+--------+----------+-----------+---------------------+| 666666 |   666666 | ddsd1123d | 2019-05-15 23:13:55 |+--------+----------+-----------+---------------------+1 row in set (0.00 sec)

4、使用索引的场景

1、 经常出现在where后面的字段,我们需要给他加索引
2、order by 语句使用索引的优化
mysql> explain select * from article order by idG;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: indexpossible_keys: NULL          key: PRIMARY      key_len: 4          ref: NULL         rows: 1307580     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)ERROR: No query specifiedmysql> explain select * from article where id >0  order by idG;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: rangepossible_keys: PRIMARY          key: PRIMARY      key_len: 4          ref: NULL         rows: 653790     filtered: 100.00        Extra: Using where1 row in set, 1 warning (0.01 sec)ERROR: No query specified

可以看出,即使是使用了索引但是几乎还是全表扫描。

加了where就少了一半

3、针对like的模糊查询索引的优化

where title like ‘%keyword%’ ====>全表扫描

where title like ‘keyword%’ ===>会使用到索引查询

给title加上铺索引

Sveil开源商城 Sveil开源商城

Sveil开源商城是专业和创新的开源在线购物车的解决方案,是基于osCommerce 3 alpha 5 独立开发的项目。环境为PHP+MYSQL,使用了先进的AJAX技术和富互联网应用(RIA)的框架ExtJS,由Sveil.com提供重要的可用性改善及与网站交互界面速度更快,更高效。VERSION 1.0–修复bug1、网站在维护2、当搜索引擎被激活,与我们联系功能不起作用。3、当SEO被激

Sveil开源商城 6 查看详情 Sveil开源商城

mysql> alter table article  add key key_index(title);Query OK, 0 rows affected (2.16 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> show create table articleG;*************************** 1. row ***************************       Table: articleCreate Table: CREATE TABLE `article` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `no_index` int(11) DEFAULT NULL,  `title` varchar(30) NOT NULL DEFAULT '',  `add_time` datetime DEFAULT NULL,  PRIMARY KEY (`id`),  KEY `key_no_index` (`no_index`),  KEY `key_index` (`title`)) ENGINE=InnoDB AUTO_INCREMENT=1507299 DEFAULT CHARSET=utf81 row in set (0.00 sec)

因为%没有出现在like关键字查询的最左边,所以可以使用到索引查询

只要是like左边出现了%,就是全表查询

mysql> explain select * from article where title like 'a%'G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: range//范围查询possible_keys: key_index          key: key_index      key_len: 92//          ref: NULL         rows: 1     filtered: 100.00        Extra: Using index condition1 row in set, 1 warning (0.00 sec)mysql> explain select * from article where title like '%a%'G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: ALL//全表查询possible_keys: NULL          key: NULL      key_len: NULL          ref: NULL         rows: 1307580     filtered: 11.11        Extra: Using where1 row in set, 1 warning (0.00 sec)
4、limit语句的索引使用优化

针对于limit语句的优化,我们可以在它前面加order by 索引字段

如果order by的字段是索引,会先去索引文件中查找指定行数的数据

mysql> explain select sql_no_cache  * from article limit 90000,10 G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: ALL//全表possible_keys: NULL          key: NULL      key_len: NULL          ref: NULL         rows: 1307580     filtered: 100.00        Extra: NULL1 row in set, 2 warnings (0.00 sec)ERROR: No query specifiedmysql> explain select sql_no_cache  * from article order by id  limit 90000,10 G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: indexpossible_keys: NULL          key: PRIMARY//使用到了索引      key_len: 4          ref: NULL         rows: 90010     filtered: 100.00        Extra: NULL1 row in set, 2 warnings (0.00 sec)ERROR: No query specified

另外一种针对于limit的优化方法:

索引覆盖+延时关联

原理:主要利用索引覆盖查询,把覆盖索引查询返回的id作为与我们要查询记录的id进行相关联,

mysql> select sql_no_cache  * from article limit 1000000,10;+---------+----------+----------------+---------------------+| id      | no_index | title          | add_time            |+---------+----------+----------------+---------------------+| 1196579 |  1196579 | ddsd12123123ad | 2019-05-15 23:13:56 || 1196580 |  1196580 | ddsd121231ad   | 2019-05-15 23:13:56 || 1196581 |  1196581 | ddsd1212123d   | 2019-05-15 23:13:56 || 1196582 |  1196582 | ddsd1123123d   | 2019-05-15 23:13:56 || 1196583 |  1196583 | ddsd1123d      | 2019-05-15 23:13:56 || 1196584 |  1196584 | ddsd1123d      | 2019-05-15 23:13:56 || 1196585 |  1196585 | ddsd1123d      | 2019-05-15 23:13:56 || 1196586 |  1196586 | ddsd1123d      | 2019-05-15 23:13:56 || 1196587 |  1196587 | ddsd1123d      | 2019-05-15 23:13:56 || 1196588 |  1196588 | ddsd1123d      | 2019-05-15 23:13:56 |+---------+----------+----------------+---------------------+10 rows in set, 1 warning (0.21 sec)mysql> select t1.* from article as t1 inner join (select id as pid from article  limit 10000,10) as t2 on t1.id=t2.pid;+-------+----------+----------------+---------------------+| id    | no_index | title          | add_time            |+-------+----------+----------------+---------------------+| 13058 |    13058 | ddsd12123123ad | 2019-05-15 23:13:49 || 13059 |    13059 | ddsd121231ad   | 2019-05-15 23:13:49 || 13060 |    13060 | ddsd1212123d   | 2019-05-15 23:13:49 || 13061 |    13061 | ddsd1123123d   | 2019-05-15 23:13:49 || 13062 |    13062 | ddsd1123d      | 2019-05-15 23:13:49 || 13063 |    13063 | ddsd1123d      | 2019-05-15 23:13:49 || 13064 |    13064 | ddsd1123d      | 2019-05-15 23:13:49 || 13065 |    13065 | ddsd1123d      | 2019-05-15 23:13:49 || 13066 |    13066 | ddsd1123d      | 2019-05-15 23:13:49 || 13067 |    13067 | ddsd1123d      | 2019-05-15 23:13:49 |+-------+----------+----------------+---------------------+10 rows in set (0.00 sec)
5、复合(多列)索引的最左原则(面试经常问)

只要查询的时候出现复合索引的最左边的字段才会使用到索引查询

把article表的no_index和title建立复合索引:

//给no_index和title创建一个复合索引mysql> alter table article add key index_no_index_title(no_index,title);Query OK, 0 rows affected (1.18 sec)Records: 0  Duplicates: 0  Warnings: 0//查看创建后的结构mysql> show create table articleG;*************************** 1. row ***************************       Table: articleCreate Table: CREATE TABLE `article` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `no_index` int(11) DEFAULT NULL,  `title` varchar(30) NOT NULL DEFAULT '',  `add_time` datetime DEFAULT NULL,  PRIMARY KEY (`id`),  KEY `key_no_index` (`no_index`),  KEY `key_index` (`title`),  KEY `index_no_index_title` (`no_index`,`title`)) ENGINE=InnoDB AUTO_INCREMENT=1507299 DEFAULT CHARSET=utf81 row in set (0.00 sec)//删除no_index和title的索引mysql> alter table article drop key key_index;Query OK, 0 rows affected (0.05 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> alter table article drop key key_no_index;Query OK, 0 rows affected (0.03 sec)Records: 0  Duplicates: 0  Warnings: 0mysql> show create table articleG;*************************** 1. row ***************************       Table: articleCreate Table: CREATE TABLE `article` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `no_index` int(11) DEFAULT NULL,  `title` varchar(30) NOT NULL DEFAULT '',  `add_time` datetime DEFAULT NULL,  PRIMARY KEY (`id`),  KEY `index_no_index_title` (`no_index`,`title`)) ENGINE=InnoDB AUTO_INCREMENT=1507299 DEFAULT CHARSET=utf81 row in set (0.00 sec)//复合索引使用情况mysql> explain select * from article where title='ddsd1123d' and no_index=77777G;*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: refpossible_keys: index_no_index_title          key: index_no_index_title      key_len: 97          ref: const,const         rows: 1     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)mysql> explain select * from article where  no_index=77777G; *************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: article   partitions: NULL         type: refpossible_keys: index_no_index_title          key: index_no_index_title      key_len: 5          ref: const         rows: 1     filtered: 100.00        Extra: NULL1 row in set, 1 warning (0.00 sec)

五、慢查询日志

1、介绍

我们可以定义(程序员)一个sql语句执行的最大执行时间,如果发现某条sql语句的执行时间超过我们所规定的时间界限,那么这条sql就会被记录下来.

2、慢查询具体操作

先开启慢日志查询

查看慢日志配置

mysql> show variables like '%slow_query%';+---------------------+--------------------------------------------------+| Variable_name       | Value                                            |+---------------------+--------------------------------------------------+| slow_query_log      | OFF                                              || slow_query_log_file | /usr/local/mysql/data/caredeMacBook-Pro-slow.log |+---------------------+--------------------------------------------------+2 rows in set (0.00 sec)

开启慢日志查询

mysql> set global slow_query_log=on;Query OK, 0 rows affected (0.00 sec)

再次检查慢日志配置

mysql> show variables like '%slow_query%';+---------------------+--------------------------------------------------+| Variable_name       | Value                                            |+---------------------+--------------------------------------------------+| slow_query_log      | ON                                               || slow_query_log_file | /usr/local/mysql/data/caredeMacBook-Pro-slow.log |+---------------------+--------------------------------------------------+2 rows in set (0.00 sec)

去mysql配置文件my.ini中指定sql语句的界限时间和慢日志文件的路径

慢日志的名称,默认保存在mysql目录下面的data目录下面

log-slow-queries = 'man.txt'

设置一个界限时间

long-query-time=5

重启

六、profile工具

1、介绍

通过profile工具分析一条sql语句的时间消耗在哪里

2、具体操作

开启profile

执行一条SQL,(开启之后执行的所有SQL语句都会被记录下来

,以查看某条sql语句的具体执行时间耗费哪里)

根据query_id查找到具体的SQL

实例:

//查看profile设置mysql> show variables like '%profil%';+------------------------+-------+| Variable_name          | Value |+------------------------+-------+| have_profiling         | YES   || profiling              | OFF   |//未开启状态| profiling_history_size | 15    |+------------------------+-------+3 rows in set (0.00 sec)//开启操作mysql> set profiling = on;Query OK, 0 rows affected, 1 warning (0.00 sec)//查看是否开启成功mysql> show variables like '%profil%';+------------------------+-------+| Variable_name          | Value |+------------------------+-------+| have_profiling         | YES   || profiling              | ON    |//开启成功| profiling_history_size | 15    |+------------------------+-------+3 rows in set (0.00 sec)

具体查询

mysql> select * from article where no_index=666666;+--------+----------+-----------+---------------------+| id     | no_index | title     | add_time            |+--------+----------+-----------+---------------------+| 666666 |   666666 | ddsd1123d | 2019-05-15 23:13:55 |+--------+----------+-----------+---------------------+1 row in set (0.02 sec)mysql> show profiles;+----------+------------+---------------------------------------------+| Query_ID | Duration   | Query                                       |+----------+------------+---------------------------------------------+|        1 | 0.00150700 | show variables like '%profil%'              ||        2 | 0.01481100 | select * from article where no_index=666666 |+----------+------------+---------------------------------------------+2 rows in set, 1 warning (0.00 sec)mysql> show profile for query 2;+----------------------+----------+| Status               | Duration |+----------------------+----------+| starting             | 0.000291 || checking permissions | 0.000007 || Opening tables       | 0.012663 |//打开表| init                 | 0.000050 || System lock          | 0.000009 || optimizing           | 0.000053 || statistics           | 0.001566 || preparing            | 0.000015 || executing            | 0.000002 || Sending data         | 0.000091 |//磁盘上的发送数据| end                  | 0.000004 || query end            | 0.000007 || closing tables       | 0.000006 || freeing items        | 0.000037 || cleaning up          | 0.000010 |+----------------------+----------+15 rows in set, 1 warning (0.01 sec)

以上就是详解MySQL 索引+explain的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/778030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
win10系统中计算器常用快捷键有那些?
上一篇 2025年11月26日 08:29:22
vscode怎么全局搜索日志文件_vscode全局搜索日志类型文件内容的实用教程
下一篇 2025年11月26日 08:29:24

相关推荐

  • composer require-dev和require有什么不同_Composer Require与Require-Dev区别解析

    require用于声明项目运行必需的依赖,如框架、数据库组件和第三方SDK,这些包会随项目部署到生产环境;2. require-dev用于声明仅在开发和测试阶段需要的工具,如PHPUnit、PHPStan、Faker等,不会默认部署到生产环境;3. 安装时composer install根据环境决定…

    2026年5月10日
    1000
  • 开源免费PHP工具 PHP开发效率提升利器

    推荐开源免费PHP开发工具以提升效率:VS Code、Sublime Text轻量高效,PhpStorm专业强大;调试用Xdebug、Kint、Ray;依赖管理选Composer;代码质量工具包括PHPStan、Psalm、PHP_CodeSniffer;数据库管理可用%ignore_a_1%MyA…

    2026年5月10日
    000
  • Golang JSON序列化:控制敏感字段暴露的最佳实践

    本教程探讨golang中如何高效控制结构体字段在json序列化时的可见性。当需要将包含敏感信息的结构体数组转换为json响应时,通过利用`encoding/json`包提供的结构体标签,特别是`json:”-“`,可以轻松实现对特定字段的忽略,从而避免敏感数据泄露,确保api…

    2026年5月10日
    000
  • 怎么在PHP代码中实现图片上传功能_PHP图片上传功能实现与安全处理教程

    首先创建含enctype的HTML表单,再用PHP接收文件,检查目录、移动临时文件,验证类型与大小,生成唯一文件名,并调整php.ini限制以确保上传成功。 如果您尝试在PHP项目中添加图片上传功能,但服务器无法正确接收或保存文件,则可能是由于表单配置、文件处理逻辑或安全限制的问题。以下是实现该功能…

    2026年5月10日
    100
  • 获取日期中的周数:CodeIgniter 教程

    本教程旨在帮助开发者在 CodeIgniter 框架中,从日期字符串中准确提取周数。我们将使用 PHP 内置的 DateTime 类,并提供详细的代码示例和注意事项,确保您能够轻松地在项目中实现此功能。 使用 DateTime 类获取周数 PHP 的 DateTime 类提供了一种便捷的方式来处理日…

    2026年5月10日
    100
  • 比特币新手教程 比特币交易平台有哪些

    比特币是一种去中心化的数字货币,基于区块链技术实现点对点交易,具有匿名性、有限发行和不可篡改等特点;新手可通过交易所购买,P2P交易获得比特币,常用平台包括Binance、OKX和Huobi;交易流程包括注册账户、实名认证、绑定支付方式、充值法币并下单购买,可选择市价单或限价单;比特币存储方式有交易…

    2026年5月10日
    000
  • c++中的SFINAE技术是什么_c++模板编程中的SFINAE原理与应用

    SFINAE 是“替换失败不是错误”的原则,指模板实例化时若参数替换导致错误,只要存在其他合法候选,编译器不报错而是继续重载决议。它用于条件启用模板、类型检测等场景,如通过 decltype 或 enable_if 控制函数重载,实现类型特征判断。尽管 C++20 引入 Concepts 简化了部分…

    2026年5月10日
    000
  • Go语言mgo查询构建:深入理解bson.M与日期范围查询的正确实践

    本文旨在解决go语言mgo库中构建复杂查询时,特别是涉及嵌套`bson.m`和日期范围筛选的常见错误。我们将深入剖析`bson.m`的类型特性,解释为何直接索引`interface{}`会导致“invalid operation”错误,并提供一种推荐的、结构清晰的代码重构方案,以确保查询条件能够正确…

    2026年5月10日
    100
  • Golang goroutine与channel调试技巧

    使用go run -race检测数据竞争,结合runtime.NumGoroutine监控协程数量,通过pprof分析阻塞调用栈,利用select超时避免永久阻塞,有效排查goroutine泄漏、死锁和数据竞争问题。 Go语言的goroutine和channel是并发编程的核心,但它们也带来了调试上…

    2026年5月10日
    000
  • 使用 Jupyter Notebook 进行探索性数据分析

    Jupyter Notebook通过单元格实现代码与Markdown结合,支持数据导入(pandas)、清洗(fillna)、探索(matplotlib/seaborn可视化)、统计分析(describe/corr)和特征工程,便于记录与分享分析过程。 Jupyter Notebook 是进行探索性…

    2026年5月10日
    000
  • 《魔兽世界》将于6月11日开启国服回归技术测试

    《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试《魔兽世界》将于6月11日开启国服回归技术测试

    《%ign%ignore_a_1%re_a_1%》官方宣布,将于6月11日开启国服回归技术测试,时间为7天,并称可以在6月内正式开服,玩家们可以访问官网下载战网客户端并预下载“巫妖王之怒”客户端,技术测试详情见下图。 WordAi WordAI是一个AI驱动的内容重写平台 53 查看详情 以上就是《…

    2026年5月10日 用户投稿
    200
  • php常量怎么用_PHP常量(define/const)定义与使用方法

    PHP中可通过define函数和const关键字定义常量,用于存储不可变值。define适用于全局作用域,支持动态名称和条件定义,如define(‘SITE_NAME’, ‘MyWebsite’);const在编译时生效,语法简洁但限制多,只能在类或全…

    2026年5月10日
    000
  • 如何在HTML中插入表单元素_HTML表单控件与输入类型使用指南

    HTML表单通过标签构建,包含action和method属性定义数据提交目标与方式,常用input类型如text、password、email等适配不同输入需求,配合label、required、placeholder提升可用性,结合textarea、select、button等控件实现完整交互,是…

    2026年5月10日
    100
  • 创建指定大小并填充特定数据的Golang文件教程

    本文将介绍如何使用Golang创建一个指定大小的文件,并用特定数据填充它。我们将使用 `os` 包提供的函数来创建和截断文件,从而实现快速生成大文件的目的。示例代码展示了如何创建一个10MB的文件,并将其填充为全零数据。掌握这些方法,可以方便地在例如日志系统或磁盘队列等场景中,预先创建测试文件或初始…

    2026年5月10日
    000
  • Python命令怎样使用profile分析脚本性能 Python命令性能分析的基础教程

    使用Python的cProfile模块分析脚本性能最直接的方式是通过命令行执行python -m cProfile your_script.py,它会输出每个函数的调用次数、总耗时、累积耗时等关键指标,帮助定位性能瓶颈;为进一步分析,可将结果保存为文件python -m cProfile -o ou…

    2026年5月10日
    000
  • 如何插入查询结果数据_SQL插入Select查询结果方法

    如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法如何插入查询结果数据_SQL插入Select查询结果方法

    使用INSERT INTO…SELECT语句可高效插入数据,通过NOT EXISTS、LEFT JOIN、MERGE语句或唯一约束避免重复;表结构不一致时可通过别名、类型转换、默认值或计算字段处理;结合存储过程可提升可维护性,支持参数化与动态SQL。 将查询结果数据插入到另一个表中,可以…

    2026年5月10日 用户投稿
    000
  • 使用 WebCodecs VideoDecoder 实现精确逐帧回退

    本文档旨在解决在使用 WebCodecs VideoDecoder 进行视频解码时,实现精确逐帧回退的问题。通过比较帧的时间戳与目标帧的时间戳,可以避免渲染中间帧,从而提高用户体验。本文将提供详细的解决方案和示例代码,帮助开发者实现精确的视频帧控制。 在使用 WebCodecs VideoDecod…

    2026年5月10日
    000
  • PHP动态生成表单输入与POST数据获取实践指南

    本教程详细阐述了如何在php中根据动态数据源(如数据库值)生成多个表单输入框,并演示了如何通过post方法准确无误地获取这些动态生成的输入值。文章强调了正确的输入框命名策略,避免了常见的命名误区,并提供了完整的代码示例,确保开发者能够高效处理动态表单数据。 动态生成表单输入 在Web开发中,我们经常…

    2026年5月10日
    000
  • Discord.py 交互按钮超时与持久化解决方案

    本教程旨在解决Discord.py中交互按钮在一段时间后出现“This Interaction Failed”错误的问题。我们将深入探讨视图(View)的超时机制,并提供通过正确设置timeout参数以及利用bot.add_view()方法实现按钮持久化的具体方案,确保您的机器人交互功能稳定可靠,即…

    2026年5月10日
    000
  • Debian Copilot的社区活跃度如何

    debian copilot是codeberg社区维护的ai助手,旨在为debian用户提供服务。尽管搜索结果中没有直接提供关于debian copilot社区支持活跃度的具体数据,但我们可以通过debian社区的整体活跃度和特点来推断其活跃性。 Debian社区的一般情况: Debian拥有详尽的…

    2026年5月10日
    000

发表回复

登录后才能评论
关注微信