neo4j / cypher:悬挂查询参数

一直以来,我一直在使用neo4j的密码查询语言, 迈克尔一直在告诉我在查询中使用参数,但是查询的性能始终可以接受,因此我没有必要。 但是,最近我正在研究一个数据集,并使用类似于以下的代码创建了约500个节点:

require 'open-uri'open("data/people.cyp", 'w') { |f|(1..500).each do |value|f.puts("CREATE (p:Person{name: \"#{value}\"})")end
}

这将创建一个如下所示的cypher语句文件:

CREATE (:Person{name: "person1"})
CREATE (:Person{name: "person2"})
CREATE (:Person{name: "person3"})
CREATE (:Person{name: "person4"})
CREATE (:Person{name: "person5"})
...

如果我们在neo4j-shell或Web管理员中执行这些语句,则会得到以下输出:

==> +-------------------+
==> | No data returned. |
==> +-------------------+
==> Nodes created: 500
==> Properties set: 500
==> Labels added: 500
==> 27706 ms

据我了解,之所以需要这么长时间是因为密码创建然后为每个create语句缓存了一个查询计划,因为它无法知道它们实际上是相同的。 由于我经常删除/重新加载数据,因此我想使反馈循环更快一些,因此终于可以应用Michael的建议了。 参数的工作方式是在占位符查询中添加占位符,然后提供在执行查询时应用于验证那些占位符的值。 在这种情况下,似乎最简单的方法是利用neography对正在运行的neo4j服务器执行查询。 如果我们想用参数化名称创建一个人,那么我们将编写以下代码:

require 'neography'params = { :name => "Mark" }Neography::Rest.new.execute_query("CREATE (:Person {name: {name} })", params)

如果我们运行查询以检索所有人,我们可以看到他们已经成功创建:

neo4j-sh (0)$ match p:Person return p;
==> +----------------------+
==> | p                    |
==> +----------------------+
==> | Node[1]{name:"Mark"} |
==> +----------------------+
==> 1 row
==> 175 ms

我想传入一个我最初认为可以做到的名称数组,但将params哈希中的值更改为一个数组:

require 'neography'params = { :name => [] }
(1..500).each do |value|params[:name] << "person#{value}"
endNeography::Rest.new.execute_query("CREATE (:Person {name: {name} })", params)

我进行了一次查询以取回我的500个人,但只有一个人返回:

neo4j-sh (0)$ MATCH p:Person RETURN p
> ;
==> +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | p                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
==> +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> | Node[1]{name:["person1","person2","person3","person4","person5","person6","person7","person8","person9","person10","person11","person12","person13","person14","person15","person16","person17","person18","person19","person20","person21","person22","person23","person24","person25","person26","person27","person28","person29","person30","person31","person32","person33","person34","person35","person36","person37","person38","person39","person40","person41","person42","person43","person44","person45","person46","person47","person48","person49","person50","person51","person52","person53","person54","person55","person56","person57","person58","person59","person60","person61","person62","person63","person64","person65","person66","person67","person68","person69","person70","person71","person72","person73","person74","person75","person76","person77","person78","person79","person80","person81","person82","person83","person84","person85","person86","person87","person88","person89","person90","person91","person92","person93","person94","person95","person96","person97","person98","person99","person100","person101","person102","person103","person104","person105","person106","person107","person108","person109","person110","person111","person112","person113","person114","person115","person116","person117","person118","person119","person120","person121","person122","person123","person124","person125","person126","person127","person128","person129","person130","person131","person132","person133","person134","person135","person136","person137","person138","person139","person140","person141","person142","person143","person144","person145","person146","person147","person148","person149","person150","person151","person152","person153","person154","person155","person156","person157","person158","person159","person160","person161","person162","person163","person164","person165","person166","person167","person168","person169","person170","person171","person172","person173","person174","person175","person176","person177","person178","person179","person180","person181","person182","person183","person184","person185","person186","person187","person188","person189","person190","person191","person192","person193","person194","person195","person196","person197","person198","person199","person200","person201","person202","person203","person204","person205","person206","person207","person208","person209","person210","person211","person212","person213","person214","person215","person216","person217","person218","person219","person220","person221","person222","person223","person224","person225","person226","person227","person228","person229","person230","person231","person232","person233","person234","person235","person236","person237","person238","person239","person240","person241","person242","person243","person244","person245","person246","person247","person248","person249","person250","person251","person252","person253","person254","person255","person256","person257","person258","person259","person260","person261","person262","person263","person264","person265","person266","person267","person268","person269","person270","person271","person272","person273","person274","person275","person276","person277","person278","person279","person280","person281","person282","person283","person284","person285","person286","person287","person288","person289","person290","person291","person292","person293","person294","person295","person296","person297","person298","person299","person300","person301","person302","person303","person304","person305","person306","person307","person308","person309","person310","person311","person312","person313","person314","person315","person316","person317","person318","person319","person320","person321","person322","person323","person324","person325","person326","person327","person328","person329","person330","person331","person332","person333","person334","person335","person336","person337","person338","person339","person340","person341","person342","person343","person344","person345","person346","person347","person348","person349","person350","person351","person352","person353","person354","person355","person356","person357","person358","person359","person360","person361","person362","person363","person364","person365","person366","person367","person368","person369","person370","person371","person372","person373","person374","person375","person376","person377","person378","person379","person380","person381","person382","person383","person384","person385","person386","person387","person388","person389","person390","person391","person392","person393","person394","person395","person396","person397","person398","person399","person400","person401","person402","person403","person404","person405","person406","person407","person408","person409","person410","person411","person412","person413","person414","person415","person416","person417","person418","person419","person420","person421","person422","person423","person424","person425","person426","person427","person428","person429","person430","person431","person432","person433","person434","person435","person436","person437","person438","person439","person440","person441","person442","person443","person444","person445","person446","person447","person448","person449","person450","person451","person452","person453","person454","person455","person456","person457","person458","person459","person460","person461","person462","person463","person464","person465","person466","person467","person468","person469","person470","person471","person472","person473","person474","person475","person476","person477","person478","person479","person480","person481","person482","person483","person484","person485","person486","person487","person488","person489","person490","person491","person492","person493","person494","person495","person496","person497","person498","person499","person500"]} |
==> +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
==> 1 row

实际上,我实际上是通过使用参数来创建一个人的,并且将其“ name”属性设置为500个名字的数组! 我调整了代码以传递地图数组而不是像这样的字符串:

require 'neography'params = { :people => [] }
(1..500).each do |value|params[:people] << { :name => "person#{value}"}
endNeography::Rest.new.execute_query("CREATE (:Person {people})", params)

我运行了脚本来填充数据库,然后再次查询它:

neo4j-sh (0)$ MATCH p:Person RETURN p;
==> +-----------------------------+
==> | p                           |
==> +-----------------------------+
==> | Node[1]{name:"person1"}     |
==> | Node[2]{name:"person2"}     |
==> | Node[3]{name:"person3"}     |
==> | Node[4]{name:"person4"}     |
==> | Node[5]{name:"person5"}     |
==> | Node[6]{name:"person6"}     |
==> | Node[7]{name:"person7"}     |
==> | Node[8]{name:"person8"}     |
==> | Node[9]{name:"person9"}     |
==> | Node[10]{name:"person10"}   |
==> | Node[11]{name:"person11"}   |
...
==> +-----------------------------+
==> 500 rows
==> 1081 ms

这次我得到了预期的结果,所以唯一要做的就是快速检查将参数化数据输入数据库所花费的时间:

$ time bundle exec ruby people.rb real	0m0.993s
user	0m0.733s
sys	0m0.097s

获胜者是…迈克尔,每次跑步大约26秒。

在此版本中,cypher首次遇到CREATE语句时会创建查询计划,但此后它可以将查询计划用于后续调用,从而极大地提高了性能。

Alistair指出,查询参数方法在应用程序中使用时非常好,因为您不必担心字符串连接,您只需更改映射中的值即可。

基于这种经验,我现在可以确认上周Max De Marzi的推文:

@ neo4j和Cypher 新手的公共服务公告:请在查询中使用参数http://docs.neo4j.org/chunked/milestone/cypher-parameters.html #MuchFaster

参考: neo4j / cypher:从Mark Needham博客博客的JCG合作伙伴 Mark Needham 获取更多的查询参数 。

翻译自: https://www.javacodegeeks.com/2013/08/neo4jcypher-getting-the-hang-of-query-parameters.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/367090.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java调用浏览器组件来_Java 网页浏览器组件介绍

在使用 Java 开发客户端程序时&#xff0c;有时会需要在界面中使用网页浏览器组件&#xff0c;用来显示一段 HTML 或者一个特定的网址。本文将介绍在界面中使用浏览器组件的四种方法&#xff0c;给出示例的代码&#xff0c;并且分析每种方法的优点与不足&#xff0c;便于 Java …

前端入行两年--教会了我这些道理

1.前言 光阴似箭&#xff0c;日月如梭。不得不感慨时间过得很快&#xff0c;2017差不多结束了&#xff0c;一下子我从事前端开发的时间已经两年了。这两年可以说是一波三折&#xff0c;回想这两年的经历&#xff0c;让我忍不住了写下了这篇文章&#xff0c;记录自己在这两年经历…

解决Nginx: [error] open() Nginx.pid

使用nginx -c的参数指定nginx.conf文件的位置 sudo /usr/sbin/nginx -c /etc/nginx/nginx.conf 转载于:https://www.cnblogs.com/vannn/p/9756132.html

巴霍巴利王

巴霍巴利王 惊心动魄的宫廷政变&#xff0c;必然铸就新的王朝更迭。时代的婉转&#xff0c;终究选上得民心的君主。我们的故事就这样悄无声息的将你带入幽深的宫廷内院。 夜幕之中&#xff0c;面对寒冷与杀戮&#xff0c;一位身负重伤王室女人&#xff0c;抱着一个新生儿&#…

Java中的观察者设计模式-示例教程

观察者模式是行为设计模式之一 。 当您对对象的状态感兴趣并希望在发生任何更改时得到通知时&#xff0c;观察者设计模式很有用。 在观察者模式中&#xff0c;监视另一个对象状态的对象称为Observer &#xff0c;而正在监视的对象称为Subject 。 根据GoF&#xff0c;观察者模式…

华为大数求和 java_大数乘积java

{"data":{"id":"8000-000000437045-0","name":"SEO专题页栏目分发组","type":"1","position":"8000-000000004003-0","status":1,"linkList":[{"id"…

IdnentiyServer-使用客户端凭据访问API

情景如下&#xff1a;一个客户端要访问一个api&#xff0c;不需要用户登录&#xff0c;但是又不想直接暴露api给外部使用&#xff0c;这时可以使用identityserver添加访问权限。 客户端通过clientid和secrect访问identitserver的Token Endpoint,获取accesstoken&#xff1b; 接…

重要·Flutter 首个预览版 发布

今天&#xff0c;InfoQ China 主办的 GMTC 全球大前端技术大会在北京举行&#xff0c;在这次大会中 Google 宣布发布 Flutter 首个预览版。这无疑让 Flutter 迈上了一个新的台阶。于此同时推出了 Flutter 社区中文资源 。可能有些同学还不了解 Flutter&#xff0c;这里再普及一…

复习做UWP时涉及到的几种加密签名相关

复习做UWP时涉及到的几种加密签名相关 原文:复习做UWP时涉及到的几种加密签名相关本人菜鸟一枚&#xff0c;大学里凭兴趣学了一点WP的皮毛&#xff0c;后来又幸运&#xff08;或者不幸&#xff09;的进了一家专注于Windows生态的公司做了一段时间的UWP。在博客园写点自己遇到的…

Java中的中介器设计模式-示例教程

中介者模式是行为设计模式之一 &#xff0c;因此它处理对象的行为。 中介器设计模式用于在系统中不同对象之间提供集中式通信介质。 根据GoF&#xff0c;中介者模式意图是&#xff1a; 通过封装不同对象集相互交互和通信的方式&#xff0c;允许松散耦合。 允许每个对象集的动作…

java gc full gc_Java中full gc什么意思?

慕雪6442864除直接调用System.gc外&#xff0c;触发Full GC执行的情况有如下四种。1. 旧生代空间不足旧生代空间只有在新生代对象转入及创建为大对象、大数组时才会出现不足的现象&#xff0c;当执行Full GC后空间仍然不足&#xff0c;则抛出如下错误&#xff1a;java.lang.Out…

springboot-RequestMappingHandlerMapping

作用&#xff1a;查看应用请求对应的ur和方法l情况 实例&#xff1a; RequestMappingHandlerMapping mapping applicationContext.getBean("requestMappingHandlerMapping",RequestMappingHandlerMapping.class);Map<RequestMappingInfo, HandlerMethod> map …

JavaScript中Ajax的用法

XMLHttpRequest 对象的属性和方法&#xff1a; open(method,url,async)  规定请求的类型、URL 以及是否异步处理请求  send(string)        将请求发送到服务器。  responseText       获得字符串形式的响应数据。  responseXML        获得 XM…

axios请求超时,设置重新请求的完美解决方法

自从使用Vue2之后&#xff0c;就使用官方推荐的axios的插件来调用API&#xff0c;在使用过程中&#xff0c;如果服务器或者网络不稳定掉包了, 你们该如何处理呢? 下面我给你们分享一下我的经历。 具体原因 最近公司在做一个项目, 服务端数据接口用的是Php输出的API, 有时候在…

从代码内部:骆驼路由引擎第一部分

因此&#xff0c;最近我重新燃起了对Apache Camel工作原理的兴趣。 Camel是一种功能强大的集成工具&#xff0c;用途非常广泛&#xff0c;但是只要我投入使用&#xff0c;我都会忍不住想&#xff1a;“嗯&#xff0c;这到底是怎么做到的&#xff01;” …猜想我只是有一个诀窍&…

java比较时间sql_如何正确比较日期 java.sql.Date

import java.sql.Date;...............例如今天是2010-12-2Date d1 new Date(System.currentTimeMili());Date d2 new Date(System.currentTimeMili()1);//比d1晚1毫秒日期上&#xff0c;我们认为d1和d2是相等的但是System.out.println(d1.before(d2));输出结果是true;其实我…

各种推导式合集

推导式的套路 之前我们已经学习了最简单的列表推导式和生成器表达式。但是除此之外&#xff0c;其实还有字典推导式、集合推导式等等。 下面是一个以列表推导式为例的推导式详细格式&#xff0c;同样适用于其他推导式。 variable [out_exp_res for out_exp in input_list if o…

javascript总结36:DOM-点击按钮切换图片案例

<!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><title>Title</title> </head><body><a href"http://www.baidu.com" id"link">点击切换</a> <br&g…

一个9年的技术最近一直担心找不到工作

我是一个从早期ASP ACCESS程序员慢慢转到一名从设计、前端到PHP后台MYSQL数据库都做的技术。07年末初入上海第一份工作1350RMB/月做ASP开发。到了春节离职了&#xff0c;当时只因同事间的关系没那么和谐&#xff0c;感觉不开心才提出的离职&#xff0c;试用期3个月&#xff0c;…

Spring MVC控制器的单元测试:REST API

Spring MVC提供了一种创建REST API的简便方法。 但是&#xff0c;为这些API编写全面而快速的单元测试一直很麻烦。 Spring MVC测试框架的发布使我们可以编写可读&#xff0c;全面且快速的单元测试。 这篇博客文章描述了如何使用Spring MVC Test框架编写REST API的单元测试。 在…