Answer the question
In order to leave comments, you need to log in
What is the big O of database fetch methods?
I was wondering how the database selection methods work,
i.e. if you take laravel:
User::find($id);
Or take node js:
Then these methods in both laravel and node js bypass each field in the database (O (n)) or access this field , how to array element(O(1))?
db.collection('users').find({"email": email})
Answer the question
In order to leave comments, you need to log in
These methods neither in Laravel nor in Node bypass any fields, all the work is done by the DBMS. How exactly it does this depends on the DBMS and on the data schema.
If without foreach, then array_filter() can be used.
If the data is taken from the database, then why not immediately select only those where not null?
<?php
$array = array(
[
'id' => '1',
'user_id' => 1,
'child' => [
[
'id' => 1,
'item_id' => 1,
'project_id' => 3
],
[
'id' => 2,
'item_id' => 2,
'project_id' => 0
]
]
]
);
var_dump(array_filter($array[0]['child'], function($v, $k) {
return $k == 'project_id' && $v != 0;
}, ARRAY_FILTER_USE_BOTH));
array(1) {
[0]=>
array(3) {
["id"]=>
int(1)
["item_id"]=>
int(1)
["project_id"]=>
int(3)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question