$result = $conn->query("SELECT * FROM head body");
while ($row = $result->fetch_assoc()) {
$arr['head'][] = $row['head'];
$arr['body'][] = $row['body'];
}
$result = $conn->query('
(
select id, name, "head" as table_name
from head
) union (
select id, name, "body" as table_name
from body
)
');
while ($row = $result->fetch_assoc()) {
$tableName = $row['table_name'];
unset($row['table_name']);
$arr[$tableName][] = $row;
}
$result->free();
$result = $conn->query("SELECT t1.id as id1, t1.name as name1, t2.id as id2, t2.name as name2
FROM head t1 body t2");
while ($row = $result->fetch_assoc()) {
$arr['head'][] = $row['id1'] . $row[name1'] ;
$arr['body'][] = $row['id2'] . $row[name2'] ;
}
select h.id, h.name head_name, b.name body_name, from head h, body b where
where h.id=b.id
Less only in the case of the competent denormalization and placement of the indices in the denormalized table.
So better a few simple queries, which are easier to maintain the sampling result in each easy to cache, and the cache is more effective in reducing the number of queries and amount of retrieved data.
And finally, don't do premature optimization. That's when the battle with real users and data will see that these selections become your bottleneck, then you have to think what to do next: to use a cache, optimize a query, renormalizability table, change the RDBMS, or start to use nosql will become clear only when will start the real usage of the application on live Kazakh. - Baby51 commented on July 9th 19 at 10:22