How can i optimize neo4j query. Neoj4 shows this warning: "This query builds a cartesian product between disconnected patterns" -
i'm trying run query.
match (p:post), (me:user{username: 'someusername'}) ( ( (me)-[:user_posted_post|user_share_post|post_in_gr|post_in_page]-(p) or ( (me)-[{subscribe: '1'}]-()-[:post_in_gr]-(p)-[:user_posted_post|user_share_post]-({status:'active'}) or (me)-[{subscribe: '1'}]-()-[:post_in_page]-(p)-[:user_posted_post|user_share_post]-({status:'active'}) or (me)-[:user_author_page]-()-[:post_in_page]-(p)-[:user_posted_post|user_share_post]-({status:'active'}) or (me)-[{subscribe: '1'}]-({status:'active'})-[:user_posted_post|user_share_post]-(p:post{system_type: 'page'}) or (me)-[{subscribe: '1'}]-({status:'active'})-[:user_posted_post|user_share_post]-(p) , not (p)-[:post_in_gr]-() , not (p)-[:post_in_page]-() or (me)-[:user_create_com]-()-[:com_in_post]-(p) ) , p.access in ['everybody', 'friend'] or (me)-[:user_can_see_post|user_posted_post]-(p) , p.access = 'custom' ) ) , p.hidden_id null , not (me)-[:user_hide_post]-(p) return p order p.updated_at desc
neo4j says: "this query builds cartesian product between disconnected patterns" , runs query slow, 8 seconds. warning means , how can avoid , make work faster?
you building cartesian product
because of part : (p:post), (me:user{username: 'someusername'})
here define pattern disjoint : (p:post)
& (me:user{username: 'someusername'})
. db have create cartesain product between 2 distinct sets.
but assume have unique constraint on :user(username), cartesian in reality 1xn, it'sok (neo4j message warning).
your query slow due yours complex clauses, lot of or
. instead of doing clause, can try put directly in match
part or optional match
.
moreover, think query can cut in multiple simple queries, , can join them union
.
cheers
Comments
Post a Comment