MySQL存储过程对链表进行排序

发布于 2024-12-17 23:33:39 字数 246 浏览 1 评论 0原文

我有一个表示链接列表的表

id | parent
1  | 1
2  | 1
3  | 2
4  | 3
...

,我知道 mysql 没有内置用于查询的树构建功能,但我想知道是否有人使用存储过程来执行此排序。目前,我正在域代码中执行排序,但表要由外部系统读取,并且性能对外部系统至关重要,因此我想为其提供一个已排序的列表,以免使用其宝贵的 CPU 周期。

欢迎其他建议,因为这仍处于设计阶段。

I have a table with a representation of a linked list

id | parent
1  | 1
2  | 1
3  | 2
4  | 3
...

I know for a fact that mysql does not have the tree building capabilities built in for queries but I was wondering if anyone had used stored procedures to perform this sorting. Currently I am performing the sorting in my domain code but the table as to be read by an external system and performance is paramount on the external system so I would like to provide it with an already sorted list to not use its the precious CPU cycles.

Other advices are welcomed as this is still in the design phase.

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

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

发布评论

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

评论(2

空城仅有旧梦在 2024-12-24 23:33:39

MySQL 没有 Oracle 那样方便的 START WITH / CONNECT BY 语法,但是,您可能需要查看 此链接来自试图模仿 MySQL 中相同功能的人。

MySQL doesn't have the handy START WITH / CONNECT BY syntax that Oracle does, however, you might want to check out this link from someone who tried to mimic this same functionality in MySQL.

°如果伤别离去 2024-12-24 23:33:39

我已经于 2011 年 10 月 24 日在 DBA StackExchange 中解决了这个问题:https://dba.stackexchange.com/questions/7147/find-highest-level-of-a-hierarchical-field-with-vs-without-ctes/7161#7161

在我的回答中,我包含了基于该问题的存储过程和示例数据。

尝试一下!

I already solved this in the DBA StackExchange on October 24, 2011 : https://dba.stackexchange.com/questions/7147/find-highest-level-of-a-hierarchical-field-with-vs-without-ctes/7161#7161

In my answer, I included the stored procedures and sample data based on that question.

Give it a Try !!!

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