MySQLUnique Key和Primary KeyMySQL之间的主要区别是什么?
我有一个包含多个视图的模式。我需要检查执行计划以确保适当的索引到位并被使用。
我该怎么做呢?
我宁愿不必将输出复制并粘贴show create view <viewname>到 中explain,尤其是当某些视图构建在其他视图之上时,这将非常痛苦。
我需要一个 MySQL 不提供的聚合函数。
我希望它具有 MySQL 的 SQL 风格(即,不是在 C 中)。
我该怎么做呢?我所坚持的是创建一个聚合函数——文档似乎没有提到这是如何完成的。
product函数的期望用法示例:
mysql> select product(col) as a from `table`;
+------+
| a |
+------+
| 144 |
+------+
1 row in set (0.00 sec)
mysql> select col, product(col) as a from `table` group by col;
+-----+------+
| col | a |
+-----+------+
| 6 | 36 |
| 4 | 4 |
+-----+------+
2 rows in set (0.01 sec)
Run Code Online (Sandbox Code Playgroud) 我有两个疑问,
select some_other_column
from `table`
order by primary_index_column asc
limit 4000000, 10;
Run Code Online (Sandbox Code Playgroud)
和
select some_other_column
from `table`
order by secondary_index_column asc
limit 4000000, 10;
Run Code Online (Sandbox Code Playgroud)
两者都返回 10 行;第一个需要 2.74 秒,第二个需要 7.07 秒。 some_other_column不是任何索引的一部分。 primary_index_column是主键列;secondary_index_column有一个 b 树索引和 200 的基数(根据 MySQL)。
下面是explain结果:
mysql> explain select some_other_column from `table` order by primary_index_column limit 4000000, 10;
+----+-------------+---------+-------+---------------+---------+---------+------+---------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+---------+---------+------+---------+-------+ …Run Code Online (Sandbox Code Playgroud) 在这个查询中:
select count(*) from largetable;
Run Code Online (Sandbox Code Playgroud)
选择二级索引:
mysql> explain select count(*) from largetable;
+----+-------------+------------+-------+---------------+------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+---------------+------+---------+------+----------+-------------+
| 1 | SIMPLE | largetable | index | NULL | iif | 5 | NULL | 50000169 | Using index |
+----+-------------+------------+-------+---------------+------+---------+------+----------+-------------+
1 row in set (0.00 sec)
mysql> select count(*) from largetable;
+----------+
| count(*) |
+----------+
| 50000000 |
+----------+
1 row …Run Code Online (Sandbox Code Playgroud) 我今天在本地 MySQL 安装中发现了这个:
mysql> select host, user from user;
+--------------+---------+
| host | user |
+--------------+---------+
| ::1 | root |
| ... others...| etc. |
+--------------+---------+
Run Code Online (Sandbox Code Playgroud)
什么是主机::1?我应该删除它吗?我只需要从localhost.
我几乎是在重复另一个用户在这里完成的一个问题,但与 MySQL 相关。您认为最好的免费(如果有的话)MySQL 客户端软件是什么?
谢谢!
mysql ×7
performance ×3
aggregate ×1
audit ×1
client ×1
functions ×1
index ×1
index-tuning ×1
innodb ×1
primary-key ×1
security ×1
view ×1