通过 MySQL 查询插入 Symfony NestedSet 数据
在 Symfony 探索项目中,我有一个使用 NestedSet 行为原则的模型。由于数据是在平面文件中准备的,因此我编写了 转换实用程序生成相应的YAML。事实证明,处理大约 100 条记录(max_深度 = 4)的 NestedSet YML 消耗了超过 40MB 的 PHP 内存,这对我来说是无法使用的。
这个问题有解决方法吗?
我正在考虑两种可能的解决方案。
- 编写一个等效的 PHP 脚本来填充对象和对象保存它们
- 通过 SQL 语句插入数据,挑战在于计算左值和右值。正确的节点
Symfonians 有什么建议?
On a Symfony exploration project, I have a model using doctrine NestedSet behaviour. Since the data is prepared in a flat file, I wrote a conversion utility to generate corresponding YAML. It turns out that processing NestedSet YML of around 100 records (max_depth=4) consumes over 40MB of PHP memory, which is not available to me.
Is there a work-around to this problem?
I'm thinking of 2 possible solutions.
- Write an equivalent PHP script to populate objects & save them
- Insert data via SQL statements, the challenge being to compute the left & right nodes
What do Symfonians suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您多次插入数据,例如从级别 0 开始,每个级别插入一次。
I suggest you insert the data in several times, one time per level starting at level 0, for instance.
选项 2 更好。
我在 Excel 中编写了一个简单的宏来计算前序树所需的 lgt 和 rgt 值。这里提到的逻辑: http://www.sitepoint.com/hierarchical-data-database -2/
同一个 Excel 实用程序会将值转换为可通过文件转储的 SQL 查询。
遍历灯具/对象路径超出了允许的内存限制。
Option 2 was better.
I wrote a simple macro in Excel to compute the lgt and rgt values required for the pre-order tree. Logic as mentioned here: http://www.sitepoint.com/hierarchical-data-database-2/
The same Excel utility would convert values to a SQL query that could be dumped via file.
Going through the fixtures/object route exceeded the allowed memory limit.