baum
baum copied to clipboard
19 queries when creating the child node.
When creating a child node of root node it is creating 19 queries to mysql. i dont know it is correct or not. if it creating 19 queries what will the performance of mysql.
$root=Document::find(5);
$child=$root->children()->create([
'name'=>'child name'
]);
This is my code. please tell me if Im doing it wrong or it really want 19 queries to execute.
Some body clarify my doubt..
i dont use that method before maybe try that
$root = Category::root()->first();
$node= Category::create(['name' => 'node 2 ']);
$node->makeChildOf($root);
k, @devmark i will check that and inform you
@devmark , i changed my code as you mentioned then i got this exception "Could not resolve target node"
oop. sorry. i dont test that.
$node = new Category;
$node->name = "my name ";
$node->save();
//setup parent id
$root = Category::root();
$node->makeChildOf($root);
this code should be work. i am using that code on my project.
I'm tested with that code @devmark , but now it executing 15 queries against the database
i opened the db log, it also executes 15 queries(2 duplicated) nested tree need more time to do insertion method, bcz it need resorting, update parent etc... but it will be more faster to get data
But the package like this is only creating 5 quiries when creating the child nodes. actually i dont know how to implement this nested set implementation . if you know please explain diff b/w these packages.
AFAIK, the number of queries is directly linked to the number of data in database and the position where the node will be inserted.
@rscafi is correct @pavankumarkatakam. When doing inserts, left and right values for the entire table needs to be updated. A lot of data is updated and if you have indexes they need rebuilding too. Nested sets have their forte in retreiving data and is slower at inserting data.
Thank You @rscafi and @torkiljohnsen for clearing this.
@phpspider I've been looking for something that can handle "root scopes". Similar to this -- https://github.com/lazychaser/laravel-nestedset#scoping -- but instead of using a shared lft/rgt numbering system across the entire table, the numbering would be "reset" for each root node.
That concept only solves the issue by a single factor, but sometimes that's all it takes.
Apparently this package does that. Huh.