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

IC 10 optimization #66

Merged
merged 1 commit into from
Dec 4, 2022
Merged

IC 10 optimization #66

merged 1 commit into from
Dec 4, 2022

Conversation

yixinglu
Copy link

@yixinglu yixinglu commented Dec 4, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Description:


(root@nebula) [sf100]> MATCH (person:Person)-[:KNOWS]-(friend) WHERE id(person) == "p-32985349068465" WITH person, collect(id(friend)) AS friends MATCH (person:Person)-[:KNOWS*2]-(friend)-[:IS_LOCATED_IN]
->(city:Place) WHERE id(friend) != "p-32985349068465" AND id(friend) NOT IN friends WITH person, city, friend, datetime(friend.Person.birthday) as birthday WHERE (birthday.month==3 AND birthday.day>=21) O
R         (birthday.month==(3%12)+1 AND birthday.day<22) WITH DISTINCT friend AS f, city AS c, person AS p OPTIONAL MATCH (f)<-[:POST_HAS_CREATOR]-(post:Post) OPTIONAL MATCH (p)-[:HAS_INTEREST]->(m), (pos
t:Post)-[:HAS_TAG]->(m) with f AS friend, c AS city, post, case when count(m) > 0 then 1 else 0 END as cnt with friend, city, sum(cnt) AS commonPostCount, count(post) AS postCount RETURN toInteger(substr(
id(friend), 2)) AS personId,        friend.Person.firstName AS personFirstName,        friend.Person.lastName AS personLastName,        commonPostCount - (postCount - commonPostCount) AS commonInterestSco
re,        friend.Person.gender AS personGender,        city.Place.name AS personCityName ORDER BY commonInterestScore DESC, personId ASC LIMIT 10
+----------------+-----------------+----------------+---------------------+--------------+----------------+
| personId       | personFirstName | personLastName | commonInterestScore | personGender | personCityName |
+----------------+-----------------+----------------+---------------------+--------------+----------------+
| 447564         | "Monja"         | "Simon"        | 144                 | "female"     | "Antananarivo" |
| 15393163189959 | "Amit"          | "Singh"        | 104                 | "male"       | "Bandra"       |
| 28587302727145 | "R."            | "Khan"         | 96                  | "female"     | "Kasaragod"    |
| 15393162886890 | "Nikhil"        | "Singh"        | 87                  | "female"     | "Kerala"       |
| 21990232659515 | "Rahul"         | "Kumar"        | 86                  | "female"     | "Tirunelveli"  |
| 13194139647349 | "Sanjay"        | "Khan"         | 80                  | "male"       | "Barasat"      |
| 2199023256816  | "K."            | "Bose"         | 57                  | "female"     | "Pondicherry"  |
| 24189256000791 | "K."            | "Sharma"       | 48                  | "female"     | "Gaya"         |
| 6597069783855  | "Rahul"         | "Singh"        | 41                  | "female"     | "Aligarh"      |
| 13194139771673 | "R."            | "Singh"        | 40                  | "female"     | "Kanpur"       |
+----------------+-----------------+----------------+---------------------+--------------+----------------+
Got 10 rows (time spent 5.587754s/5.589362496s)

Execution Plan (optimize time 1117 us)


Sun, 04 Dec 2022 23:15:44 CST

(root@nebula) [sf100]> """
                    -> MATCH (person:Person)-[:KNOWS]-(friend)
                    -> WHERE id(person) == "p-32985349068465"
                    -> WITH person, collect(id(friend)) AS friends
                    -> MATCH (person:Person)-[:KNOWS*2]-(friend)-[:IS_LOCATED_IN]->(city:Place)
                    -> WHERE id(friend) != "p-32985349068465" AND id(friend) NOT IN friends
                    -> WITH person, city, friend, datetime(friend.Person.birthday) as birthday
                    -> WHERE (birthday.month==3 AND birthday.day>=21) OR
                    ->         (birthday.month==(3%12)+1 AND birthday.day<22)
                    -> WITH DISTINCT friend AS f, city AS c, person AS p
                    -> OPTIONAL MATCH (f)<-[:POST_HAS_CREATOR]-(post:Post)
                    -> OPTIONAL MATCH (p)-[:HAS_INTEREST]->(m)<-[:HAS_TAG]-(post)
                    -> with f AS friend, c AS city, post, case when count(m) > 0 then 1 else 0 END as cnt
                    -> with friend, city, sum(cnt) AS commonPostCount, count(post) AS postCount
                    -> RETURN toInteger(substr(id(friend), 2)) AS personId,
                    ->        friend.Person.firstName AS personFirstName,
                    ->        friend.Person.lastName AS personLastName,
                    ->        commonPostCount - (postCount - commonPostCount) AS commonInterestScore,
                    ->        friend.Person.gender AS personGender,
                    ->        city.Place.name AS personCityName
                    -> ORDER BY commonInterestScore DESC, personId ASC
                    -> LIMIT 10
                    -> """
+----------------+-----------------+----------------+---------------------+--------------+----------------+
| personId       | personFirstName | personLastName | commonInterestScore | personGender | personCityName |
+----------------+-----------------+----------------+---------------------+--------------+----------------+
| 447564         | "Monja"         | "Simon"        | 144                 | "female"     | "Antananarivo" |
| 15393163189959 | "Amit"          | "Singh"        | 104                 | "male"       | "Bandra"       |
| 28587302727145 | "R."            | "Khan"         | 96                  | "female"     | "Kasaragod"    |
| 15393162886890 | "Nikhil"        | "Singh"        | 87                  | "female"     | "Kerala"       |
| 21990232659515 | "Rahul"         | "Kumar"        | 86                  | "female"     | "Tirunelveli"  |
| 13194139647349 | "Sanjay"        | "Khan"         | 80                  | "male"       | "Barasat"      |
| 2199023256816  | "K."            | "Bose"         | 57                  | "female"     | "Pondicherry"  |
| 24189256000791 | "K."            | "Sharma"       | 48                  | "female"     | "Gaya"         |
| 6597069783855  | "Rahul"         | "Singh"        | 41                  | "female"     | "Aligarh"      |
| 13194139771673 | "R."            | "Singh"        | 40                  | "female"     | "Kanpur"       |
+----------------+-----------------+----------------+---------------------+--------------+----------------+
Got 10 rows (time spent 2m34.217948s/2m34.214210283s)

Execution Plan (optimize time 1054 us)


Sun, 04 Dec 2022 23:19:21 CST

How do you solve it?

Special notes for your reviewer, ex. impact of this fix, design document, etc:

@yixinglu yixinglu merged commit a0abc9c into nebula1.2.0 Dec 4, 2022
@yixinglu yixinglu deleted the opt-ic-10 branch December 4, 2022 15:24
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

Successfully merging this pull request may close these issues.

1 participant