Neo4j:使用大量数据进行慢速选择操作

时间:2017-03-09 09:38:43

标签: neo4j cypher

我每次都会随机尝试Graph中的节点。数据库中的节点数为24600968。以下查询

    List<String> bindCodes = new ArrayList<>();
    bindCodes.add("CM0001");
    bindCodes.add("CE7563");
    bindCodes.add("DR6785");

    Scan scan = new Scan();
    scan.setCaching(50);//set get batch numbers
    //set Column
    scan.addColumn(HTableColumnEnum.GPS_CF_1.getCfName().getBytes(), LOCATION_CREATE_DATE_ARRAY);
    //set Family
    scan.addFamily(HTableColumnEnum.GPS_CF_1.getCfName().getBytes());

    //create filterList
    FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
    //put mulit prefix row key
    bindCodes.forEach(s -> {
        filterList.addFilter(new PrefixFilter(Bytes.toBytes(s)));
    });

    //set filterList to scan
    scan.setFilter(filterList);

需要很长时间。时间是

MATCH (n:Employee)
WITH n AS emp,rand() AS ids ORDER BY ids LIMIT 10

MATCH (n:Company)
WITH emp, n AS com,rand() AS ids ORDER BY ids LIMIT 10
RETURN emp.guid,com.guid

如何加快这一过程。

1 个答案:

答案 0 :(得分:2)

  1. 运行2个单独的陈述

  2. 试试这个

  3. 通过随机的一组ID查找节点,并检查他们是否是员工

    MATCH (n) WITH count(*) as total
    WITH [_ IN range(1,10000) | toInt(rand()*total)] as ids
    MATCH (emp) WHERE id(emp) IN ids AND emp:Employee
    RETURN emp LIMIT 10
    

    您的查询生成一个24M随机值的列表并对其进行排序(两次),同时还将图中的许多节点拉入内存(不确定您有多少内存)