type
status
date
slug
summary
tags
category
icon
password
前言
意外發現當使用 floor 切 partition 使用非等值查詢時不會觸發 partition pruning。
在文檔中有如下描述:
In MySQL 8.0, partition pruning is supported for the
TO_DAYS()
, TO_SECONDS()
, YEAR()
, and UNIX_TIMESTAMP()
functions. See Section 24.4, “Partition Pruning”
, for more information.可以看到上述的 function 並未包含
floor
,也就是說雖然可以用 floor
切 partiton 卻無法在非等值查詢使用 partition pruning 優化查詢速度。範例
測試資料:
等值查詢 (
=
, IN
) 會使用 PARTITION pruning:非等值查詢 (
≥
, Between
) 不會使用 PARTITION pruning:解決方案
目前沒有相關的 bug report 及修復計畫,除了避免使用
TO_SECONDS()
, YEAR()
UNIX_TIMESTAMP()
以外的 function 來切 partition 之外也可以使用指定 partition 的方式來改善: