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

[BUG] Inconsistent result caused by reordering path patterns in the MATCH clause #3114

Open
HITFAY opened this issue Jun 25, 2023 · 7 comments

Comments

@HITFAY
Copy link

HITFAY commented Jun 25, 2023

Version: Docker image redis/redis-stack:6.2.6-v7
OS: Ubuntu 22.04
API/Driver: Cypher

Hello, the result changes when I change the last match pattern into another one. It is confusing that the same query clauses can get two different results.

To reproduce, I construct a graph that is able to reproduce the bug:

Please look at the following queries, the only difference between them is the Match clauses at the last.

MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20
MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9), (n8 :L0)-[r6 :T5]->(n9) RETURN n10.k20

The result shows that one result is 8, another is 1svfEV

image

I also find that there are some issues similar with what I described, #3093, #3091, #3081

Could you check it, please?

I have attached the graph creation statements below for you to reproduce. If you have any further question, please feel free to contact me, I will replay as soon as possible.

Hope to get reply soon.
reproduce.txt

@gkorland
Copy link
Contributor

@HITFAY did you try to reproduce the issue on the latest version of 2.12?

@Lincyaw
Copy link

Lincyaw commented Sep 19, 2023

Yes, and the result is also different. I use Docker version: redis/redis-stack:6.2.6-v9

127.0.0.1:6381> GRAPH.QUERY validate "MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20"
1) 1) "n10.k20"
2) 1) 1) "P"
3) 1) "Cached execution: 0"
   2) "Query internal execution time: 1.086466 milliseconds"
127.0.0.1:6381> GRAPH.QUERY validate "MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9), (n8 :L0)-[r6 :T5]->(n9) RETURN n10.k20"
1) 1) "n10.k20"
2) 1) 1) "8"
3) 1) "Cached execution: 0"
   2) "Query internal execution time: 1.105804 milliseconds"
127.0.0.1:6381>

@AviAvni
Copy link
Collaborator

AviAvni commented Sep 19, 2023

for

MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20

the result I get is

[['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8']]

and for

MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9), (n8 :L0)-[r6 :T5]->(n9) RETURN n10.k20

the result

[['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV']]

which are the same but different order
how come you get only one record?

@Lincyaw
Copy link

Lincyaw commented Sep 19, 2023

for

MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20

the result I get is

[['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8']]

and for

MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9), (n8 :L0)-[r6 :T5]->(n9) RETURN n10.k20

the result

[['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV'], ['8'], ['P'], ['Kkl'], ['9'], ['1svfEV']]

which are the same but different order how come you get only one record?

I use the following code to load the data into DB, and then I query it in terminal.

import redis
from redisgraph import Graph



class Redis:
    def __init__(self, uri, database, reset=True):
        self.redis_con = redis.Redis(host=uri, port=6381, socket_timeout=10)
        self.graph = Graph(database, self.redis_con)
        if reset:
            self.clear()

    def clear(self):
        self.run("MATCH (n) DETACH DELETE n")

    def get_plan(self, query):
        """Returns tuple of execution plans"""
        query = query.replace(';', '')
        plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.graph.name, query)
        plan = [step.decode('utf-8') if isinstance(step, bytes) else step for step in plan]
        return tuple(plan)

    def run(self, query):
        query = query.replace(';', '')
        result = self.graph.query(query)
        return result.result_set, result.run_time_ms

    def batch_run(self, queries):
        for i in queries:
            i = i.replace(';', '')
            self.run(i)


if __name__ == "__main__":
    r = Redis("localhost", "validate", True)
    with open("query_file/redis.log") as f:
        cmd = f.readlines()
        try:
            r.batch_run(cmd)
        except Exception as e:
            print(e)

And I only get a single result, I don't know what's wrong with it.

127.0.0.1:6381> GRAPH.QUERY validate "MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20"
1) 1) "n10.k20"
2) 1) 1) "P"
3) 1) "Cached execution: 0"
   2) "Query internal execution time: 1.364378 milliseconds"
127.0.0.1:6381> GRAPH.QUERY validate "MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN n10.k20"
1) 1) "n10.k20"
2) 1) 1) "P"
3) 1) "Cached execution: 1"
   2) "Query internal execution time: 0.721388 milliseconds"
127.0.0.1:6381> GRAPH.QUERY validate "MATCH (n1 :L3)<-[r1 :T1]-(n2 :L4), (n3 :L0 :L1 :L4)<-[r2 :T2]-(n4 :L1 :L0)<-[r3 :T5]-(n5 :L3) WITH DISTINCT n4 MATCH (n3 :L4)<-[]-(n4 :L0)<-[]-(n5)  MATCH (n8 :L0)-[r6 :T5]->(n9), (n2 :L0)<-[r10 :T2]-(n12 :L1), (n11 :L3)-[r8 :T1]->(n3), (n10 :L3)-[r7 :T5]->(n9) RETURN COUNT(*)"
1) 1) "COUNT(*)"
2) 1) 1) (integer) 1
3) 1) "Cached execution: 0"
   2) "Query internal execution time: 1.039485 milliseconds"
127.0.0.1:6381>

@AviAvni
Copy link
Collaborator

AviAvni commented Sep 19, 2023

indeed in 2.10 it returns only 1 result in 2.12 it is returning the result I sent

@Lincyaw
Copy link

Lincyaw commented Sep 19, 2023

Can you tell me which docker version is 2.12, Please? I use redis/redis-stack:6.2.6-v9, but it seems is not the correct 2.12. I also tried redis/redis-stack:7.2.0-v2, but there is no graph.so supported.

ps. I have problem in building my own Redis version in local, so I have to choose the docker.

@AviAvni
Copy link
Collaborator

AviAvni commented Sep 19, 2023

2.12 wasn't released in redis-stack you can find it in redislabs/redisgraph:2.12.9
also take a look at https://github.com/FalkorDB/FalkorDB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants