mysql - mysql分区修剪不适用于连接
问题描述
分区修剪不适用于连接。Posts 表由 tag_id 的 Range 分区。分区修剪没有加入并在 tag_id 字段上应用 where 条件。Mtom Table 只是用户选择的多对多表存储标签。
EXPLAIN PARTITIONS SELECT
posts.post_id,
posts.owner_id
FROM `posts_main` AS posts
JOIN `posts_tags_user_mtom` AS mtom
ON posts.tag_id = mtom.tag_id
ORDER BY posts.post_id DESC
LIMIT 50;
解决方案
通过以下代码实现了这一点:
BEGIN
SELECT GROUP_CONCAT(`tag_id`) INTO @posts_tags FROM posts_tags_user_mtom WHERE `user_id` = 12 AND `active` = 1;
PREPARE stmt FROM CONCAT("EXPLAIN PARTITIONS SELECT posts.post_id,posts.owner_id FROM `posts_main` AS posts WHERE posts.tag_id IN(" ,@posts_tags, ") ORDER BY posts.post_id DESC;");
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
推荐阅读
- c# - 如何使用 C# WinForms 在 Combobox 中选择多个项目
- angular - ngModel 在输入字段中不起作用
- android - Samsung Internet 是否支持本机应用程序安装横幅?
- regex - IF中的Perl多个条件
- css - 控制 Apple Pay 按钮内的字体大小
- java - 如何将 Java 存档 (.WAR) 上传到 Plesk 上的 Windows Server?
- mysql - MySQL查询功能,记住以前的记录
- jquery - 数据表删除行
- svelte - Svelte/Sapper 动态客户端路由
- ios - Swift - 使用 alamofire 发布请求