是否可以在MySQL中为int列的最后一位数字创建索引?基于INT列的最后一位数字的MySQL索引
基于int列
CREATE TABLE partition_test(
textfiled INT,
cltext TEXT,
reindexedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
indexedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
status TINYINT(2),
postId INT)
PARTITION BY HASH(MOD(postId, 10))
PARTITIONS 10;
我试图创建的帖子ID为优化查询时间的最后一个数字的指数的最后一位在此基础上answer我已经创建的分区。有没有办法做到这一点或在postId上的简单索引就足够了?
一些失败的尝试:
CREATE INDEX postLastDigit USING HASH ON partition_test (MOD(postId, 10));
(1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'MOD(postId, 10))' at line 1")
和
CREATE INDEX postLastDigit ON partition_test (MOD(postId, 10));
(1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'MOD(postId, 10))' at line 1")
UPDATE: 表有100M以上的行。
我的目标是优化之类的查询:
1)
SELECT cltext FROM partition_tables
WHERE postId in (<INT>, <INT>)
AND status IS NOT NULL
2)
SELECT cltext FROM partition_tables
WHERE postId in (<INT>, <INT>)
AND status IS NOT NULL
AND reindexedAt BETWEEN (<DATE>, <DATE>)
MariaDB的版本:23年1月10日 - MariaDB的-9 + deb9u1
这是一个坏主意。此外,基本上*随机*分区不会改善任何事情。它肯定会损害性能,因为服务器将被迫搜索所有分区。 –