Hi,
I have a question regarding a subquery that works in 4.6.*, but not in 4.5.1. I know that upgrading is the best solution, but I’m wondering if there is a way to make the following query working in 4.5.1
Sample documents tested
test1
{
"id": 1,
"form": "parent",
"children": {
"1": {
"ids": [
"child1"
]
}
}
}
child1
{
"name": "child1",
"form": "child"
}
index used:
CREATE INDEX `covered_parent` ON `test`(`id`,`children`) WHERE (`form` = "parent")
Query:
select
c1.id,
(
select c2.name from test c2 use keys ARRAY_FLATTEN(
object_values(c1.children)[*].ids, 1
)
) as children1
from test c1 use index (`covered_parent`)
where
form='parent' and
c1.id = 1
The query returns the following output in 4.5.1
[
{
"children1": [],
"id": 1
}
]
However, this query works (notice select * in the sub query) as expected
select
c1.id,
(
select * from test c2 use keys ARRAY_FLATTEN(
object_values(c1.children)[*].ids, 1
)
) as children1
from test c1 use index (`covered_parent`)
where
form='parent' and
c1.id = 1
Returns
[
{
"children1": [
{
"c2": {
"form": "child",
"name": "child1"
}
}
],
"id": 1
}
]
in 4.6.1
[
{
"children1": [
{
"name": "child1"
}
],
"id": 1
}
]
As you see, children1 is empty in 4.5.1 unless I select *
Is there a way to workaround this in 4.5.1?
Thanks!
Moon