调用 SQL::Translator::Table 的 add_index 函数时如何指定索引值顺序?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否,目前 SQL::Translator::Producer::MySQL (我认为甚至 DBIx::Class 本身)都没有提供执行此操作的方法。
然而,根据 MySQL 手册,这些索引排序规则目前被忽略:
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: