Query that worked in 2.2.29 doesn't work in 3.0.24
OrientDB Version: 3.0.24
Java Version: 1.8.0_221
OS: Windows 10
Expected behavior
A query I had running in Orient 2.2.29 doesn't behave the same as in 3.0.24
Actual behavior
UnionAll appears to behave differently. Is there something I need to check in this query?
Steps to reproduce
SELECT DISTINCT * FROM (SELECT EXPAND(intersect((SELECT EXPAND(intersect((SELECT EXPAND(unionall((SELECT FROM $scope WHERE n_3aname = :literal_0 AND n_3aname IS NOT NULL), (SELECT FROM $scope WHERE n_3aname = :literal_1 AND n_3aname IS NOT NULL)))), (SELECT EXPAND(unionall((SELECT EXPAND(in('n_3aparent')) FROM (SELECT FROM (SELECT EXPAND(out('n_3aparent')) FROM $scope) WHERE n_3aname = :literal_2 AND n_3aname IS NOT NULL)), (SELECT EXPAND(in('n_3aparent')) FROM (SELECT FROM (SELECT EXPAND(out('n_3aparent')) FROM $scope) WHERE n_3aname = :literal_3 AND n_3aname IS NOT NULL)))))))), $scope)) LET $scope = (SELECT FROM (TRAVERSE out('scopedEdge') FROM #9:5) WHERE $depth > 0))
This query doesn't work the way it used to. The explanation seems to be fine though.
- FETCH FROM SUBQUERY
- LET (once) $scope = +------------------------- | + FETCH FROM SUBQUERY | + FETCH FROM RIDs | [#9:5] | + DEPTH-FIRST TRAVERSE | [out('scopedEdge')] | + FILTER ITEMS WHERE | $depth > 0 +-------------------------
- LET (once) $$$SUBQUERY$$_0 = +------------------------- | + LET (once) | $$$SUBQUERY$$_0 = | +------------------------- | | + LET (once) | | $$$SUBQUERY$$_0 = | | +------------------------- | | | + FETCH FROM VARIABLE | | | $scope | | | + FILTER ITEMS WHERE | | | n_3aname = 'BW1' | | +------------------------- | | + LET (once) | | $$$SUBQUERY$$_1 = | | +------------------------- | | | + FETCH FROM VARIABLE | | | $scope | | | + FILTER ITEMS WHERE | | | n_3aname = 'NW1' | | +------------------------- | | + GENERATE 1 EMPTY RECORD | | + CALCULATE PROJECTIONS | | unionall(($$$SUBQUERY$$_0), ($$$SUBQUERY$$_1)) | | + EXPAND | +------------------------- | + LET (once) | $$$SUBQUERY$$_1 = | +------------------------- | | + LET (once) | | $$$SUBQUERY$$_0 = | | +------------------------- | | | + FETCH FROM SUBQUERY | | | + FETCH FROM SUBQUERY | | | + FETCH FROM VARIABLE | | | $scope | | | + CALCULATE PROJECTIONS | | | out('n_3aparent') | | | + EXPAND | | | + FILTER ITEMS WHERE | | | n_3aname = 'PointsA' | | | + CALCULATE PROJECTIONS | | | in('n_3aparent') | | | + EXPAND | | +------------------------- | | + LET (once) | | $$$SUBQUERY$$_1 = | | +------------------------- | | | + FETCH FROM SUBQUERY | | | + FETCH FROM SUBQUERY | | | + FETCH FROM VARIABLE | | | $scope | | | + CALCULATE PROJECTIONS | | | out('n_3aparent') | | | + EXPAND | | | + FILTER ITEMS WHERE | | | n_3aname = 'PointsB' | | | + CALCULATE PROJECTIONS | | | in('n_3aparent') | | | + EXPAND | | +------------------------- | | + GENERATE 1 EMPTY RECORD | | + CALCULATE PROJECTIONS | | unionall(($$$SUBQUERY$$_0), ($$$SUBQUERY$$_1)) | | + EXPAND | +------------------------- | + GENERATE 1 EMPTY RECORD | + CALCULATE PROJECTIONS | intersect(($$$SUBQUERY$$_0), ($$$SUBQUERY$$_1)) | + EXPAND +-------------------------
- GENERATE 1 EMPTY RECORD
- LET (for each record) $scope = ($scope)
- CALCULATE PROJECTIONS intersect(($$$SUBQUERY$$_0), $scope)
- EXPAND
- CALCULATE PROJECTIONS *
- DISTINCT
Hi @ErikShiken
The old executor has a lot of hard-coded behaviours, so it's possible that something is slightly different. I tend to say that if the execution plan is correct, also the result is supposed to be correct, but we can investigate. What's the difference in the results?
Thanks
Luigi
We're expecting 4 items to come back but we only get 2 of the 4 we expect and its based on the n_3aname property being either 'PointsA' or 'PointsB' in $$$SUBQUERY$$_0.$$$SUBQUERY$$_1.$$$SUBQUERY$$_1. Changing $$$SUBQUERY$$_0.$$$SUBQUERY$$_1.$$$SUBQUERY$$_1 directly impacts the query results but changes to $$$SUBQUERY$$_0.$$$SUBQUERY$$_1.$$$SUBQUERY$$_0 doesn't seem to do anything. That leads me to suspect $$$SUBQUERY$$_0.$$$SUBQUERY$$_1.$$$SUBQUERY$$_0 could be ignored in this query. Also, when I take those two subqueries and union them myself in Orient Studio, I get the results I expect.
Hi @ErikShiken
it's hard to say what's going on, I'm afraid I'll need a reproducer, any chance to have a dataset to test the query?
Thanks
Luigi
This query is run in test code so I can provide the test data we run this query on. Do I just paste it here? How do I export the data from Orient?
Hi @ErikShiken
Yes, thank you. For the DB, I'd suggest to just zip the db folder and share it with a file sharing platform (eg. google drive).
Thanks
Luigi
Sorry for the delay. I'm unable to provide a link due to company firewall restrictions. I'll set something up when I get home from work.
Here is a link to the zipped DB. Let me know if you need help accessing it. User = admin PW = admin
Hi @ErikShiken
I cannot see the link...
Thanks
Luigi
Sorry about that.
https://drive.google.com/file/d/0B3yTkYjSpDnddnhabEkzVmJ2TVZjbHRkaHJzTzVvLUZFbmZV/view?usp=sharing
Hi just checking in since the holidays are over. Are there any questions or concerns I can address?
Hi @ErikShiken
I managed to check and reproduce it, but the query is pretty convoluted and needs some deep analysis. I'm on it, I'll let you know as soon as I have a clue
Thanks
Luigi
Yea there doesn't seem to be a way around this query. Its getting translated from a different query language to Orient SQL
Hi, What's the status of this? can we close this issue?
Regards
There's definitely something wrong with either the union or intersect function. We're using a hack to work around the broken code
On Mon, Jun 1, 2020, 8:55 AM tglman [email protected] wrote:
Hi, What's the status of this? can we close this issue?
Regards
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientdb/issues/9083#issuecomment-636844987, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEPGPK64JFCYPH443M7IBLRUOQLBANCNFSM4JYLH5YA .