{"id":23396578,"url":"https://github.com/mneedham/cypher-query-tuning","last_synced_at":"2026-03-12T03:32:27.017Z","repository":{"id":11663814,"uuid":"14172306","full_name":"mneedham/cypher-query-tuning","owner":"mneedham","description":"Mini test bench to time cypher queries","archived":false,"fork":false,"pushed_at":"2013-11-13T15:40:23.000Z","size":208,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T14:57:04.368Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mneedham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-06T12:48:26.000Z","updated_at":"2021-02-25T12:34:46.000Z","dependencies_parsed_at":"2022-09-08T12:22:17.020Z","dependency_job_id":null,"html_url":"https://github.com/mneedham/cypher-query-tuning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mneedham/cypher-query-tuning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mneedham%2Fcypher-query-tuning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mneedham%2Fcypher-query-tuning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mneedham%2Fcypher-query-tuning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mneedham%2Fcypher-query-tuning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mneedham","download_url":"https://codeload.github.com/mneedham/cypher-query-tuning/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mneedham%2Fcypher-query-tuning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30414310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T00:40:14.898Z","status":"online","status_checked_at":"2026-03-12T02:00:07.260Z","response_time":114,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-22T07:36:30.071Z","updated_at":"2026-03-12T03:32:27.003Z","avatar_url":"https://github.com/mneedham.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Tuning them cypher queries\n\nInstall the following python libraries:\n\n    pip install py2neo numpy\n\nI'm using version 1.6 on py2neo so get that version if you can.\n\nYou'll also need to replace the following function in 'util.py' of py2neo in order that UTF-8 characters get handled correctly:\n\n````python\ndef is_collection(obj):\n    \"\"\" Returns true for any iterable which is not a string or byte sequence.\n    \"\"\"\n    if isinstance(obj, bytes):\n        return False\n    try:\n        iter(obj)\n    except TypeError:\n        return False\n    try:\n        if type(obj) is list:\n            hasattr(None, obj)\n        else:\n            hasattr(None, obj.encode(\"utf-8\"))\n    except TypeError:\n        return True\n    return False\n````    \n\nThe data set is on dropbox and you can download it with this command:\n\n    curl -L https://www.dropbox.com/s/y4gp00gfryc9syx/football.zip -o football.zip\n\nThe zip contains the 'data' directory so you can unpack that into your neo4j folder:\n\n\tunzip football.zip -d /path/to/neo4j/\n\nYou can then run an example query which has been tuned:\n\n    python top-away-scorers.py\n    \n    \u003csnip\u003e\n\n    MATCH (game:Game)\u003c-[:away_team]-(team)\n    WITH game, team\n    MATCH (player:Player)-[:played]-\u003estats-[:in]-\u003egame, stats-[:for]-\u003eteam\n    RETURN player.name, SUM(stats.goals) AS goals\n    ORDER BY goals DESC\n    LIMIT 10\n    Min 0.615420103073 Mean 0.618293762207 95% 0.622805333138 Max 0.623574018478\n\n    MATCH (game)\u003c-[:away_team]-(team:Team)\n    WITH game, team\n    MATCH (player:Player)-[:played]-\u003estats-[:in]-\u003egame, stats-[:for]-\u003eteam\n    RETURN player.name, SUM(stats.goals) AS goals\n    ORDER BY goals DESC\n    LIMIT 10\n    Min 0.57263302803 Mean 0.585222005844 95% 0.597485733032 Max 0.598978042603\n\n#### Creating a new benchmark\n\nThis is the template to follow:\n\n    import query_profiler as qp\n\n    attempts = [\n    {\"query\": '''MATCH (p:Player) RETURN COUNT(p)''', \"params\": {\"define\": \"if you want\"}},\n    {\"query\": '''MATCH (player:Player) RETURN COUNT(player)'''},\n    ]\n\n    qp.profile(attempts, iterations=5, runs=3)\n\n#### Stuck?\n\nPing me on twitter [@markhneedham](https://twitter.com/markhneedham) or mark@markhneedham.com","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmneedham%2Fcypher-query-tuning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmneedham%2Fcypher-query-tuning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmneedham%2Fcypher-query-tuning/lists"}