Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different results with first(out()) operators #3168

Closed
MarcelPitch opened this issue Dec 11, 2014 · 8 comments
Closed

Different results with first(out()) operators #3168

MarcelPitch opened this issue Dec 11, 2014 · 8 comments
Assignees

Comments

@MarcelPitch
Copy link

Hi,

I'm working with 2.0 M3.

I have a graph like this :

first out

I have different results for a query, depending on the syntax used.

I'd get the first VertexTwo, linked by EdgeOne to the VertexOne where uuid = 3.

I wrote the request like this :

SELECT 
    $myVar
FROM 
    VertexOne
WHERE
    uuid = 3
LET 
    $myVar = first(out('EdgeOne'))

RESULT : I get the #11:0 Vertex. Wrong ...


But when I wrote the request like this :

SELECT 
    $myVar
FROM 
    #10:1
LET 
    $myVar = first(out('EdgeOne'))

RESULT : I get the #11:1 Vertex. Right !!!


And now, when I wrote the request like this :

SELECT 
    first($myVar)
FROM 
    VertexOne
WHERE
    uuid = 3
LET 
    $myVar = out('EdgeOne')

RESULT : I get the #11:1 Vertex. Right !!!


And now, when I wrote the request like that :

SELECT 
    $myVar
FROM 
(
    SELECT
    FROM
        VertexOne
    WHERE
        uuid = 3
)
LET 
    $myVar = first(out('EdgeOne'))

RESULT : I get the #11:1 Vertex. Right !!!


I did the test on 2.0 M2, and same result.

I don't know if it's an anomaly or just a misunderstanding with orient SQL synthax.
I thought I wrote the same request but in different way.

Thank you and have a nice day !

@lvca lvca added this to the 2.0-RC (Release Candidate) milestone Dec 11, 2014
@lvca lvca added the sql label Dec 11, 2014
@lvca
Copy link
Member

lvca commented Dec 11, 2014

LET must go before WHERE.

@MarcelPitch
Copy link
Author

Ok Luca,

I have taken note of my mistake !

But in this case, moving the LET before WHERE doesn't change anything.

@lvca
Copy link
Member

lvca commented Dec 12, 2014

@MarcelPitch could you share your db or a portion of it to run your queries?

@MarcelPitch
Copy link
Author

Here are 2 javascript functions for Orient Studio to recreate the test.

I execute them on a new DB and test the requests in the Studio Browser.

__createClasses

var g = orient.getGraphNoTx();

g.command('sql','CREATE CLASS VertexOne EXTENDS V',[]);
g.command('sql','CREATE PROPERTY VertexOne.uuid INTEGER',[]);

g.command('sql','CREATE CLASS VertexTwo EXTENDS V',[]);
g.command('sql','CREATE PROPERTY VertexTwo.uuid INTEGER',[]);

g.command('sql','CREATE CLASS EdgeOne EXTENDS E',[]);

__createVertices

var g = orient.getGraph();

g.command('sql',"CREATE VERTEX VertexOne SET uuid = 1", []);
g.command('sql',"CREATE VERTEX VertexTwo SET uuid = 2", []);
g.command('sql',"CREATE EDGE EdgeOne FROM (SELECT FROM VertexOne WHERE uuid = 1) TO (SELECT FROM VertexTwo WHERE uuid = 2)", []);


g.command('sql',"CREATE VERTEX VertexOne SET uuid = 3", []);
g.command('sql',"CREATE VERTEX VertexTwo SET uuid = 4", []);
g.command('sql',"CREATE EDGE EdgeOne FROM (SELECT FROM VertexOne WHERE uuid = 3) TO (SELECT FROM VertexTwo WHERE uuid = 4)", []);

If you try the requests by copy/paste from my previous comment, just beware of the (wrong) cluster id.

@lvca
Copy link
Member

lvca commented Dec 12, 2014

Thanks for the test case. I've found the reason. LET block is evaluated before to apply the WHERE conditions. Without an index on "uuid", a full scan is executed, so that why the first rid is #13:0. If you create an index on VertexOne.uuid, the result is the expected. This is because you used the first() function that get only the first element, so in this case #13:0.

I'm thinking that the behavior should be consistent with and without indexes, by executing the LET block AFTER the evaluation of WHERE condition, but this could break old queries that used context variables in filter.

So I'd leave this issue as open to let to the new parser to do this change (2.1). In the meanwhile you can use any of workaround.

@lvca lvca reopened this Dec 12, 2014
@lvca lvca assigned luigidellaquila and unassigned lvca Dec 12, 2014
@lvca lvca modified the milestones: 2.1, 2.0-RC (Release Candidate) Dec 12, 2014
@MarcelPitch
Copy link
Author

OK Luca,

Thanks for the workround.

Have a nice day !

@luigidellaquila
Copy link
Member

@lvca I don't get how this has to be fixed...
If the original behavior has to be preserved, then the index has to be ignored every time there is a LET. I don't like this very much.

IMHO this can be managed in a consistent way only in one of the following:

  1. breaking backward compatibility
  2. defining another function for that

@lvca
Copy link
Member

lvca commented Mar 12, 2015

@luigidellaquila what's your proposal for 1 and 2?

@lvca lvca modified the milestones: 2.1-rc1, 2.1-rc2 Apr 1, 2015
@lvca lvca removed the sql label Apr 6, 2015
@lvca lvca added this to the 2.1 GA milestone May 4, 2015
@lvca lvca removed this from the 2.1-rc2 milestone May 4, 2015
@luigidellaquila luigidellaquila modified the milestones: 2.2, 2.1 GA Jul 7, 2015
@lvca lvca modified the milestones: 2.2.0-beta, 2.2.0-rc1 Dec 13, 2015
@lvca lvca modified the milestones: 2.2.0-rc1, 2.2.0 GA May 7, 2016
@robfrank robfrank modified the milestones: 2.2.0 GA, 2.2.1 May 18, 2016
@robfrank robfrank modified the milestones: 2.2.1, 2.2.x (next hotfix) Jun 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants