调用 SQL::Translator::Table 的 add_index 函数时如何指定索引值顺序?

发布于 2024-10-10 10:26:35 字数 556 浏览 0 评论 0原文

我正在使用 DBIx::Class 创建表及其索引,因此调用 SQL::Translator::Table add_index() 但我希望能够在某些列上指定值顺序,如下所示:

CREATE INDEX myindex ON mytable (
    username ASC,
    created  DESC
);

是否可以向 add_table() 提供“ASC”和“DESC”修饰符?

如果不是,我怀疑这个 SQL 效率会很低:

SELECT text FROM mytable WHERE username = ? ORDER BY created DESC LIMIT 20;

在这种情况下,有什么建议的解决方法可以减少数据库开销吗? (我使用的是MySql 5.x

I am using DBIx::Class to create tables and their indexes and so calling SQL::Translator::Table add_index() but I'd like to be able to specify a value order on some of the columns, like this:

CREATE INDEX myindex ON mytable (
    username ASC,
    created  DESC
);

Is it possible to supply the 'ASC' and 'DESC' modifiers to add_table()?

If not, I suspect that this SQL would be inefficient:

SELECT text FROM mytable WHERE username = ? ORDER BY created DESC LIMIT 20;

Any suggested work-around to reduce database overhead in this case? (I'm using MySql 5.x

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2024-10-17 10:26:35

否,目前 SQL::Translator::Producer::MySQL (我认为甚至 DBIx::Class 本身)都没有提供执行此操作的方法。

然而,根据 MySQL 手册,这些索引排序规则目前被忽略:

index_col_name 规范可以
以 ASC 或 DESC 结尾。这些关键词
允许将来延期
用于指定升序或降序
索引值存储。目前,他们
被解析但被忽略;指数值
始终按升序存储。

No, currently SQL::Translator::Producer::MySQL (and even DBIx::Class itself I think) do not provide a way to do this.

However, according to the MySQL manual, these index collations are currently ignored:

An index_col_name specification can
end with ASC or DESC. These keywords
are permitted for future extensions
for specifying ascending or descending
index value storage. Currently, they
are parsed but ignored; index values
are always stored in ascending order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文