实例配置: gdb.r.large CPU与内存 2核16G 总存储空间 20G
GDB数据量 节点数: 140W 关系数: 9000W
使用环境: python neo4j官方驱动 查询方式为 cypher语法
查询语句如下: cypher
MATCH (from:Product)-[rel:similarity]->(to:Product)
WHERE
from.created_time >= '2020-01-12' and from.created_time <= '2020-11-11'
and
to.created_time >= '2020-01-12' and to.created_time <= '2020-11-11'
and
rel.similarity >20
RETURN from.spu as spu1, to.spu as spu2, from.image as image1, to.image as image2, rel.similarity as similarity,
from.created_time as created_time1, to.created_time as created_time2
*** ORDER BY from.created_time ***
LIMIT 20
上述查询语句执行在未加order by时查询时间为2秒左右,但是一旦加了order by之后,查询则会超时。上述查询语句应该如何更改才能使用order by查询?
解决方法一:子查询里外都排序
解决方法二:在嵌入一个子查询(好像也是里外都排序)
SELECT * FROM ( SELECT * FROM ( SELECT * FROM zs_safe_confess B WHERE B.ENABLE = 1 ORDER BY B.CREATE_TIME DESC, B.UPDATE_TIME DESC LIMIT 0,10) A LEFT JOIN zs_safe_confess_content C ON A.ID = C.CSAFE_ID)D LEFT JOIN zs_resources ON D.ID = zs_resources.ID AND zs_resources.TYPE = 10 AND zs_resources.ENABLE = 1 ORDER BY D.CREATE_TIME DESC, D.UPDATE_TIME DESC
复制代码 SELECT A.*, zs_safe_confess_content.CID, zs_safe_confess_content.CSAFE_ID, zs_safe_confess_content.CSTATUS, zs_safe_confess_content.CCONTENT, zs_safe_confess_content.CCHECK_RESULT, zs_safe_confess_content.CCREATE_TIME, zs_safe_confess_content.CUPDATE_TIME, zs_safe_confess_content.CUSER_ID, zs_safe_confess_content.CUSER_NAME, zs_safe_confess_content.CENABLE, zs_safe_confess_content.CBACKUP_01, zs_safe_confess_content.CBACKUP_02, zs_safe_confess_content.CBACKUP_03, zs_resources.RID AS RID, zs_resources.ID AS ID, zs_resources.TYPE AS RTYPE, zs_resources.URL AS RURL, zs_resources.RESOURCE_CODE AS RRESOURCE_CODE, zs_resources.FILE_NAME AS RFILE_NAME, zs_resources.FILE_SIZE AS RFILE_SIZE, zs_resources.CREATOR AS RCREATOR, zs_resources.CREATETIME AS RCREATETIME, zs_resources.MODIFIER AS RMODIFIER, zs_resources.UPDATETIME AS RUPDATETIME, zs_resources.ENABLE AS RENABLE FROM ( SELECT zs_safe_confess.ID, zs_safe_confess.SAFE_NAME, zs_safe_confess.DEPT_NAME, zs_safe_confess.DEPT_ID, zs_safe_confess.PROJECT_NAME, zs_safe_confess.PROJECT_NUMBER, zs_safe_confess.PROJECT_PERSON, zs_safe_confess.WORK_ADDRESS, zs_safe_confess.WORK_NUMBER, zs_safe_confess.COMPANY_PERSON, zs_safe_confess.COMPANY_PHONE, zs_safe_confess.FACTORY_PERSON, zs_safe_confess.FACTORY_PHONE, zs_safe_confess.DANGER_DISCERN, zs_safe_confess.ENVIRONMENT_DISCREN, zs_safe_confess.DANGER_MEASURES,zs_safe_confess.ENVIRONMENT_MEASURES, zs_safe_confess.DANGER_MANAGER, zs_safe_confess.MANAGER_TIME, zs_safe_confess.SCENE_COMFIRM, zs_safe_confess.SCENE_COMFIRM_TIME, zs_safe_confess.COMFIRM_CHECK_PERSON, zs_safe_confess.COMFIRM_CHECK_TIME, zs_safe_confess.TEST_BEFORE_PERSON, zs_safe_confess.TEST_BEFORE_TIME, zs_safe_confess.TEST_PERSON, zs_safe_confess.TEST_TIME, zs_safe_confess.TEST_AFTER_PERSON,zs_safe_confess.TEST_AFTER_TIME,zs_safe_confess.STATUS,zs_safe_confess.TYPE ,zs_safe_confess.CREATE_TIME,zs_safe_confess.UPDATE_TIME,zs_safe_confess.USER_ID,zs_safe_confess.USER_NAME,zs_safe_confess.ENABLE ,zs_safe_confess.BACKUP_01,zs_safe_confess.BACKUP_02,zs_safe_confess.BACKUP_03 FROM zs_safe_confess WHERE zs_safe_confess.ENABLE = 1 ORDER BY CREATE_TIME DESC, UPDATE_TIME DESC LIMIT 0,10) A LEFT JOIN zs_safe_confess_content ON A.ID = zs_safe_confess_content.CSAFE_ID
LEFT JOIN zs_resources ON A.ID = zs_resources.ID AND zs_resources.TYPE = 10 AND zs_resources.ENABLE = 1 (ORDER BY A.CREATE_TIME DESC, A.UPDATE_TIME DESC)(这是解决方法一) 复制代码
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。