{"id":283,"date":"2023-08-05T16:56:31","date_gmt":"2023-08-05T08:56:31","guid":{"rendered":"https:\/\/reverieland.cn\/?p=283"},"modified":"2025-06-11T00:53:10","modified_gmt":"2025-06-10T16:53:10","slug":"aql%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%88%e4%b8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/reverieland.cn\/index.php\/283\/","title":{"rendered":"AQL\u5b66\u4e60\u7b14\u8bb0\uff08\u4e0b\uff09"},"content":{"rendered":"<h3>ArrangoDB\u6587\u6863\/By aakz0347<\/h3>\n<h4>\u516d\u3001\u56fe<\/h4>\n<h5>\uff08\u4e00\uff09\u56fe\u57fa\u7840<\/h5>\n<p>1.\u79cd\u7c7b\uff1a\u65e0\u5411\u56fe\uff0c\u6709\u5411\u56fe\uff0c\u6709\u5411\u65e0\u73af\u56fe\uff08\u5982\u4e0b\u56fe\u6240\u793a\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-284 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137578-image-20230322150726268-300x125.png\" alt=\"01\" width=\"384\" height=\"160\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137578-image-20230322150726268-300x125.png 300w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137578-image-20230322150726268.png 378w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/p>\n<p>\u5728 ArangoDB \u4e2d\uff0c\u91c7\u7528\u7684\u662f\u6709\u5411\u65e0\u73af\u56fe\uff08Directed Acyclic Graph\uff09\uff1a\u6bcf\u6761\u8fb9\u53ea\u6709\u4e00\u4e2a\u65b9\u5411\uff0c\u4e0d\u80fd\u540c\u65f6\u6307\u5411\u4e24\u4e2a\u65b9\u5411\u3002\u8fb9\u59cb\u7ec8\u662f\u6709\u65b9\u5411\u7684\uff0c\u4f46\u662f\u5f53\u904d\u5386\uff08traversal\uff09\u65f6\u53ef\u80fd\u6cbf\u7740\u7bad\u5934\u53cd\u65b9\u5411\uff0c\u6b64\u65f6\u53ef\u4ee5\u4e0d\u7ba1\u65b9\u5411\u95ee\u9898<\/p>\n<p>2.ArangoDB \u5141\u8bb8\u60a8\u5b58\u50a8\u5404\u79cd\u4e0d\u540c\u5f62\u72b6\u548c\u5927\u5c0f\u7684\u56fe\u5f62\uff0c\u6709\u5faa\u73af\u548c\u65e0\u5faa\u73af\u3002\u60a8\u53ef\u4ee5\u4fdd\u5b58\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u751a\u81f3\u540c\u4e00\u4e2a\u9876\u70b9\u4e4b\u95f4\u7684\u4e00\u6761\u6216\u591a\u6761\u8fb9\u3002\u53e6\u8bf7\u6ce8\u610f\uff0c\u8fb9\u662f<strong>\u5b8c\u6574\u7684 JSON \u6587\u6863<\/strong>\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5728\u8fb9\u4e0a\u5b58\u50a8\u5c3d\u53ef\u80fd\u591a\u7684\u4fe1\u606f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-285 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137611-image-20230322151221146-300x128.png\" alt=\"\" width=\"448\" height=\"191\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137611-image-20230322151221146-300x128.png 300w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137611-image-20230322151221146.png 441w\" sizes=\"auto, (max-width: 448px) 100vw, 448px\" \/><\/p>\n<p>3.\u8282\u70b9<code>Document Collection<\/code>\uff1a\u6bcf\u6761\u4fe1\u606f\u90fd\u662f\u4e00\u4e2aJSON\u5bf9\u8c61\uff0c\u4e14\u5185\u7f6e\u4e3b\u7d22\u5f15\uff1b\u6bcf\u6761\u4fe1\u606f\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684_key<\/p>\n<p>\u8fb9<code>Edge Collection<\/code>\uff1a\u8fb9\u5c5e\u6027\u662f\u5b58\u653e\u5173\u7cfb\u7684\u5730\u65b9\uff0c\u4e5f\u5305\u542b\u4fe1\u606f\uff0c\u5176\u4e2d\u5fc5\u5305\u542b<code>_from<\/code>\u548c<code>_to<\/code>\uff0c\u5206\u522b\u8868\u793a\u6e90\u9876\u70b9\u548c\u76ee\u6807\u9876\u70b9\u7684<code>_id<\/code>\u503c<\/p>\n<p>4.\u56fe\u7684\u5e94\u7528\u573a\u666f\uff1a\u6bcf\u5f53\u641c\u7d22\u6df1\u5ea6\u672a\u77e5\uff08\u8981\u9075\u5faa\u591a\u5c11\u6761\u8fb9\uff09\u65f6\uff0c\u4e0e\u5176\u4ed6\u67e5\u8be2\u6a21\u5f0f\u76f8\u6bd4\uff0c\u56fe\u5f62\u67e5\u8be2\u66f4\u5bb9\u6613\u7f16\u5199\u4e14\u8ba1\u7b97\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<p>360\u00b0 \u89c6\u56fe\uff08\u5e02\u573a\u6570\u636e\u3001\u5ba2\u6237\u3001\u7528\u6237\u2026\u2026\uff09 \u4eba\u5de5\u667a\u80fd \u4f9d\u8d56\u7ba1\u7406 \u6b3a\u8bc8\u8bc6\u522b \u8eab\u4efd\u548c\u8bbf\u95ee\u7ba1\u7406 \u77e5\u8bc6\u56fe\u8c31 \u4e3b\u6570\u636e\u7ba1\u7406<\/p>\n<p>\u7f51\u7edc\u57fa\u7840\u8bbe\u65bd \u63a8\u8350\u5f15\u64ce \u98ce\u9669\u7ba1\u7406 \u793e\u4ea4\u5a92\u4f53\u7ba1\u7406<\/p>\n<h5>\uff08\u4e8c\uff09\u7528ArrangoDB\u7684AQL\u8fdb\u884c\u56fe\u904d\u5386<\/h5>\n<p>\u4ece\u96c6\u5408\u4e2d\u67e5\u627e\u4e00\u6761\u4fe1\u606f\uff1a<code>Document()\u51fd\u6570<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-286 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137634-image-20230322153750568-161x300.png\" alt=\"\" width=\"296\" height=\"551\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137634-image-20230322153750568-161x300.png 161w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137634-image-20230322153750568.png 390w\" sizes=\"auto, (max-width: 296px) 100vw, 296px\" \/><\/p>\n<p>\u8fd9\u662f\u901a\u8fc7 <code>_id<\/code> \u83b7\u53d6John F. Kennedy\u673a\u573a\u7684\u4fe1\u606f\uff0c\u4f7f\u7528\u4e3b\u7d22\u5f15\u6765\u67e5\u8be2\u6587\u6863\u3002<\/p>\n<p>\u6309 <code>_key<\/code> \u8fc7\u6ee4\uff1a<\/p>\n<pre><code class=\"language-mysql\">FOR airport IN airports   \n  FILTER airport._key == \"JFK\"   \n  RETURN airport<\/code><\/pre>\n<p>\u7b5b\u9009\u4e14\u4ec5\u8fd4\u56de\u673a\u573a\u540d\u79f0\uff1a<\/p>\n<pre><code class=\"language-mysql\">FOR a IN airports   \n  FILTER a._key IN [\"JFK\", \"LAX\"]\n  RETURN { fullName: a.name }<\/code><\/pre>\n<h5>\uff08\u4e09\uff09\u904d\u5386\u76f8\u5173<\/h5>\n<p>1.\u904d\u5386\u6df1\u5ea6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-287 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137661-image-20230322154801696-300x242.png\" alt=\"\" width=\"434\" height=\"350\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137661-image-20230322154801696-300x242.png 300w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137661-image-20230322154801696.png 458w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/p>\n<p>2.\u8bed\u6cd5\uff1avertex\u9876\u70b9 outbound\u79bb\u5f00\uff0c\u5411\u5916\uff0c\u8868\u793a\u904d\u5386\u65b9\u5411\u548c\u56fe\u7684\u7bad\u5934\u65b9\u5411\u76f8\u540c\uff1binbound\u8fdb\u5165\uff0c\u5411\u5185\uff0c\u8868\u793a\u904d\u5386\u65b9\u5411\u548c\u56fe\u7684\u7bad\u5934\u65b9\u5411\u76f8\u53cd\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-288 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137685-image-20230322155235252.png\" alt=\"\" width=\"555\" height=\"275\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137685-image-20230322155235252.png 470w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137685-image-20230322155235252-300x149.png 300w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<pre><code class=\"language-mysql\">FOR vertex[, edge[, path]]\n  IN [min[..max]]\n  OUTBOUND|INBOUND|ANY startVertex\n  edgeCollection[, more\u2026]<\/code><\/pre>\n<p>3.\u5b9e\u4f8b<\/p>\n<pre><code class=\"language-mysql\">\/*\u8fd4\u56de\u76f8\u90bb\u673a\u573a\u7684\u540d\u79f0\uff1a\u5b83\u53ef\u4ee5\u4ece\u6d1b\u6749\u77f6\u56fd\u9645\u673a\u573a (LAX) \uff0c\u6cbfflights\u8fb91\u6b65\u5230\u8fbe\u5230\u8fbe*\/\nWITH airports\nFOR airport IN 1..1 \n  OUTBOUND\n  'airports\/LAX' flights\n  RETURN DISTINCT airport.name<\/code><\/pre>\n<p><strong>WITH<\/strong><br \/>\nAn AQL query can start with a WITH keyword followed by a list of collections from which the query implicitly reads. This is required when doing graph traversals in a clustered environment. By implicit, we mean that the collections are not specified explicitly in language constructs like in the previous example.<\/p>\n<p>WITH airports<br \/>\nFOR airport IN 1..1<br \/>\nOUTBOUND<br \/>\n\u2018airports\/LAX\u2019 flights<\/p>\n<p>Here we do explicitly declare the flights collection, but we don\u2019t actually declare the airports in our FOR declaration, and that is why it is included as a part of the WITH statement. Doing this ensures that the query optimizer can maintain performance at runtime in a clustered environment.<\/p>\n<p>Collections that are explicitly used in a query are automatically detected by the AQL query parser. Any additional collections that will be involved in the query but cannot be detected automatically by the query parser can be manually specified using a WITH statement.<\/p>\n<p>WITH + FOR\u662f\u56fa\u5b9a\u642d\u914d\uff0cWITH\u9690\u5f0f\u6307\u51fa\u4e86\u96c6\u5408\uff0c\u4f7f\u5f97\u4e0d\u7528\u5728FOR\u4e2d\u58f0\u660e\u673a\u573aairport<\/p>\n<pre><code class=\"language-mysql\">\/*\u8fd4\u56de\u4efb\u610f 10 \u4e2a\u822a\u73ed\u6587\u4ef6\uff1a\u5b83\u4eec\u5305\u542b\u4eceLAX\u8d77\u98de\u7684\u822a\u73ed\u4fe1\u606f\u3001\u76ee\u7684\u5730\u673a\u573a\u540d\u3002\u5e94\u8be5\u5f62\u5982\u5982\u4e0b\u5f62\u5f0f\uff1a*\/\n'''\n  {\n    \"airport\": {\n      \"_key\": \"CVG\",\n      \"_id\": \"airports\/CVG\",\n      ...\n      \"vip\": false\n    },\n    \"flight\": {\n      \"_key\": \"306520699\",\n      \"_id\": \"flights\/306520699\",\n      \"_from\": \"airports\/LAX\",\n      \"_to\": \"airports\/CVG\",\n      ...\n      \"FlightNum\": 704,\n    }\n  }\n'''\n\n\/*answer*\/\nWITH airports\nFOR airport, flight IN \n  OUTBOUND \n  'airports\/LAX' flights\n  LIMIT 10\n  RETURN {airport, flight}<\/code><\/pre>\n<pre><code class=\"language-mysql\">\/*\u8fd4\u56de 10 \u4e2a\u822a\u73ed\u53f7\uff0c\u98de\u673a\u964d\u843d\u5728 Bismarck Municipal Airport (BIS)\u3002*\/   \/*  airports\/BIS  *\/\nWITH airports               \u8981\u4f7f\u7528\u7684\u96c6\u5408\nFOR airport, flight IN \nINBOUND                     \u8981\u904d\u5386\u7684\u65b9\u5411\uff1a\u5411airports\/BIS\n'airports\/BIS' flights      \u8981\u904d\u5386\u7684\u8fb9\uff1aflights\u662f\u8fb9\u96c6\u5408\u7684\u540d\u79f0\n    LIMIT 10\nRETURN flight.FlightNum<\/code><\/pre>\n<p><code>'airports\/BIS'<\/code>\u662f\u4e00\u4e2a<strong>\u6587\u6863\u53e5\u67c4<\/strong>\uff0c\u5b83\u6307\u5b9a\u4e86\u8981\u67e5\u8be2\u7684\u6587\u6863\u3002\u5728AQL\u4e2d\uff0c\u6587\u6863\u53e5\u67c4\u7531\u96c6\u5408\u540d\u79f0\u548c\u6587\u6863\u952e\u7ec4\u6210\uff0c\u7528<code>\/<\/code>\u5206\u9694\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>airports<\/code>\u662f\u96c6\u5408\u540d\u79f0\uff0c\u800c<code>BIS<\/code>\u662f\u6587\u6863\u952e\u3002<\/p>\n<p><code>WITH airports FOR vertex, edge, path IN OUTBOUND 'airports\/LAX' flights LIMIT 10 RETURN edge<\/code><\/p>\n<p><code>WITH airports FOR airport, flight IN OUTBOUND 'airports\/LAX' flights LIMIT 10 RETURN flight<\/code><\/p>\n<p>\u4e0a\u9762\u4e24\u4e2a\u8bed\u53e5\u7b49\u4ef7\uff1a<\/p>\n<p>\u8fd9\u4e24\u4e2a\u8bed\u53e5\u90fd\u662f\u67e5\u8be2\u4e0e<code>'airports\/LAX'<\/code>\u6587\u6863\u76f8\u5173\u8054\u7684\u524d10\u6761\u8fb9\u3002\u7b2c\u4e00\u4e2a\u8bed\u53e5\u4f7f\u7528\u4e86<code>vertex, edge, path<\/code>\u53d8\u91cf\u6765\u8bbf\u95ee\u904d\u5386\u8fc7\u7a0b\u4e2d\u7684\u9876\u70b9\u3001\u8fb9\u548c\u8def\u5f84\uff0c\u800c\u7b2c\u4e8c\u4e2a\u8bed\u53e5\u53ea\u4f7f\u7528\u4e86<code>airport, flight<\/code>\u53d8\u91cf\u6765\u8bbf\u95ee\u9876\u70b9\u548c\u8fb9\u3002<\/p>\n<p>\u5728\u8fd9\u4e24\u4e2a\u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u90fd\u53ea\u5173\u5fc3\u8fb9\uff0c\u56e0\u6b64\u6211\u4eec<strong>\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u4e00\u4e2a\u53d8\u91cf\u6765\u8fd4\u56de\u8fb9<\/strong>\u3002\u5728\u7b2c\u4e00\u4e2a\u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>RETURN edge<\/code>\u6765\u8fd4\u56de\u8fb9\uff0c\u800c\u5728\u7b2c\u4e8c\u4e2a\u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>RETURN flight<\/code>\u6765\u8fd4\u56de\u8fb9\u3002\u7531\u4e8e\u8fd9\u4e24\u4e2a\u53d8\u91cf\u90fd\u6307\u5411\u76f8\u540c\u7684\u8fb9\uff0c\u56e0\u6b64\u8fd9\u4e24\u4e2a\u8bed\u53e5\u662f\u7b49\u4ef7\u7684\u3002<\/p>\n<h5>\uff08\u56db\uff09\u904d\u5386\u8fdb\u9636<\/h5>\n<h6>\u904d\u5386\u65b9\u6cd5\uff1aBFS\/DFS<\/h6>\n<p>\u5bf9\u4e8e\u6700\u5c0f\u6df1\u5ea6\u22652\u7684\u904d\u5386\uff0c\u4e00\u822c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u6df1\u5ea6\u4f18\u5148<\/strong>\uff08\u9ed8\u8ba4\uff09\uff1a\u7ee7\u7eed\u6cbf\u7740\u8be5\u8def\u5f84\u4e0a\u7684\u8d77\u59cb\u9876\u70b9\u5230\u6700\u540e\u4e00\u4e2a\u9876\u70b9\u7684\u8fb9\u6216\u76f4\u5230\u8fbe\u5230\u6700\u5927\u904d\u5386\u6df1\u5ea6\uff0c\u7136\u540e\u6cbf\u7740\u5176\u4ed6\u8def\u5f84\u8d70\u3002<\/li>\n<li><strong>\u5e7f\u5ea6\u4f18\u5148<\/strong>\uff08\u53ef\u9009\uff09\uff1a\u8ddf\u968f\u4ece\u8d77\u59cb\u9876\u70b9\u5230\u4e0b\u4e00\u5c42\u7684\u6240\u6709\u8fb9\uff0c\u7136\u540e\u8ddf\u968f\u5b83\u4eec\u90bb\u5c45\u7684\u6240\u6709\u8fb9\u5230\u53e6\u4e00\u5c42\u5e76\u7ee7\u7eed\u8fd9\u79cd\u6a21\u5f0f\uff0c\u76f4\u5230\u6ca1\u6709\u66f4\u591a\u7684\u8fb9\u53ef\u4ee5\u8ddf\u968f\u6216\u8fbe\u5230\u6700\u5927\u904d\u5386\u6df1\u5ea6\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-mysql\">  FOR v IN 1..10 OUTBOUND 'verts\/S' edges       \/*1..10\u8868\u793a\u904d\u5386\u6df1\u5ea6\u4e3a10\u5c42*\/\n     OPTIONS {bfs: true}\n     FILTER v._key == 'F'\n     LIMIT 1\n     RETURN v\n \/*\u628a\u67e5\u8be2\u9650\u5236\u4e3a\u5355\u4e2a\u5339\u914d*\/<\/code><\/pre>\n<p>\u8fd9\u662f\u4e00\u4e2a\u6709\u6548\u7684AQL\u67e5\u8be2\uff0c\u5b83\u5c06\u6cbf\u7740<code>edges<\/code>\u96c6\u5408\u4e2d\u6307\u5411<code>'verts\/S'<\/code>\u6587\u6863\u7684\u8fb9\u8fdb\u884c\u904d\u5386\uff0c\u6700\u591a\u904d\u538610\u5c42\u3002\u904d\u5386\u4f7f\u7528\u4e86\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff08BFS\uff09\u7b97\u6cd5\uff0c\u5e76\u4e14\u53ea\u8fd4\u56de\u952e\u4e3a<code>'F'<\/code>\u7684\u9876\u70b9\u3002\u7531\u4e8e\u4f7f\u7528\u4e86<code>LIMIT 1<\/code>\uff0c\u56e0\u6b64\u67e5\u8be2\u6700\u591a\u8fd4\u56de\u4e00\u4e2a\u7ed3\u679c\u3002<\/p>\n<h6>\u552f\u4e00\u6027<\/h6>\n<p>\u552f\u4e00\u6027\uff1a\u5e76\u975e\u6bcf\u4e2a\u56fe\u90fd\u53ea\u6709\u4e00\u6761\u4ece\u6240\u9009\u8d77\u59cb\u9876\u70b9\u5230\u5176\u8fde\u63a5\u9876\u70b9\u7684\u8def\u5f84\u3002\u56fe\u4e2d\u751a\u81f3\u53ef\u80fd\u5b58\u5728\u5faa\u73af\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u518d\u6b21\u9047\u5230\u5df2\u7ecf\u8bbf\u95ee\u8fc7\u7684\u8fb9\uff0c\u5219\u6cbf\u4efb\u4f55\u8def\u5f84\u7684\u904d\u5386\u90fd\u4f1a\u505c\u6b62\u3002\u5b83\u53ef\u4ee5\u9632\u6b62\u904d\u5386\u7ed5\u5708\u5b50\u8fd0\u884c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-289 aligncenter\" src=\"http:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137734-image-20230322170617196-1679475978453-1.png\" alt=\"\" width=\"359\" height=\"516\" srcset=\"https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137734-image-20230322170617196-1679475978453-1.png 456w, https:\/\/reverieland.cn\/wp-content\/uploads\/2023\/10\/1698137734-image-20230322170617196-1679475978453-1-209x300.png 209w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u4e3a\u4e86\u907f\u514d<code>S-B-C-S<\/code>\u8fd9\u4e00\u7ed3\u679c\u91cd\u590d\u8fdb\u884c\uff0c\u53ef\u4ee5\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-mysql\">FOR v, e, p IN 1..5 OUTBOUND 'verts\/S' \u8fb9\n  OPTIONS { \n    uniqueVertices: 'none', \n    uniqueEdges: 'path' \n  } RETURN CONCAT_SEPARATOR ('-&gt;', p.vertices[*]._key)\n<\/code><\/pre>\n<p>uniqueEdges\uff1a'none' \u5c06\u4f7f\u904d\u5386\u5668\u9075\u5faa\u4ece S \u5230B\u5230C\u518d\u5230S\uff0c\u518d\u4eceS\u5230B\u518d\u5230C\u3002\u5b83\u53ea\u4f1a\u505c\u5728\u90a3\u91cc\uff0c\u56e0\u4e3a\u6b64\u65f6\u5df2\u8fbe\u5230\u6700\u5927\u6df1\u5ea6 5\u3002\u5982\u679c\u67e5\u8be2\u7684\u6700\u5927\u6df1\u5ea6\u66f4\u9ad8\uff0c\u5219\u904d\u5386\u5c06\u8fd0\u884c\u5f88\u957f\u65f6\u95f4\uff0c\u7531\u4e8e\u5faa\u73af\u4f1a\u4ea7\u751f\u5927\u91cf\u8def\u5f84\u3002<\/p>\n<p>uniqueVertices: 'path' \u786e\u4fdd\u6bcf\u4e2a\u5355\u72ec\u7684\u8def\u5f84\u4e0a\u6ca1\u6709\u91cd\u590d\u7684\u9876\u70b9\u3002<\/p>\n<p>uniqueVertices: 'global' \u786e\u4fdd\u5728\u6574\u4e2a\u904d\u5386\u8fc7\u7a0b\u4e2d\u8bbf\u95ee\u6bcf\u4e2a\u53ef\u5230\u8fbe\u7684\u9876\u70b9\u4e00\u6b21\u3002<\/p>\n<p>\u5b83\u9700\u8981 bfs: true\uff08\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\uff09\u3002\u6df1\u5ea6\u4f18\u5148\u641c\u7d22dfs\u4e0d\u652f\u6301\u5b83\uff0c\u56e0\u4e3a\u7ed3\u679c\u5c06\u662f\u5b8c\u5168\u4e0d\u786e\u5b9a\u7684\uff08\u5728\u67e5\u8be2\u8fd0\u884c\u4e4b\u95f4\u53d8\u5316\uff09\uff0c\u56e0\u4e3a\u904d\u5386\u5668\u9075\u5faa\u9876\u70b9\u8fb9\u7f18\u7684\u987a\u5e8f\u6ca1\u6709\u89c4\u5219\u3002\u53ea\u8981\u6709\u591a\u6761\u8def\u5f84\u53ef\u4f9b\u9009\u62e9\uff0c\u552f\u4e00\u6027\u89c4\u5219\u5c06\u5bfc\u81f4\u968f\u673a\u6392\u9664\u8def\u5f84\uff0c\u5b83\u4f1a\u4ece\u4e2d\u9009\u62e9\u4e00\u6761\u3002<\/p>\n<pre><code class=\"language-mysql\">WITH airports\nFOR airport IN OUTBOUND 'airports\/LAX' flights\n  OPTIONS { bfs: true, uniqueVertices: 'global' }\n  RETURN airport<\/code><\/pre>\n<pre><code class=\"language-mysql\">WITH airports\nFOR airport IN OUTBOUND 'airports\/LAX' flights\n  RETURN DISTINCT airport<\/code><\/pre>\n<p>\u8fd9\u4e24\u6bb5\u4ee3\u7801\u662f\u7b49\u4ef7\u7684\uff1a\u5b83\u4eec\u90fd\u5c06\u8fd4\u56de\u4e0e<code>'airports\/LAX'<\/code>\u6587\u6863\u76f8\u5173\u8054\u7684\u6240\u6709\u552f\u4e00\u9876\u70b9\u3002<\/p>\n<p>\u7b2c\u4e00\u4e2a\u67e5\u8be2\u4f7f\u7528\u4e86<code>OPTIONS { bfs: true, uniqueVertices: 'global' }<\/code>\u6765\u6307\u5b9a\u904d\u5386\u7b97\u6cd5\u548c\u786e\u4fdd\u6bcf\u4e2a\u9876\u70b9\u53ea\u88ab\u8bbf\u95ee\u4e00\u6b21\u3002\u7b2c\u4e8c\u4e2a\u67e5\u8be2\u4f7f\u7528\u4e86<code>RETURN DISTINCT airport<\/code>\u6765\u53bb\u9664\u91cd\u590d\u7684\u9876\u70b9\u3002\u4f46\u5728\u6570\u636e\u96c6\u8f83\u5927\u65f6\u4f7f\u7528<code>uniqueVertices<\/code>\u7684\u6027\u80fd\u660e\u663e\u66f4\u9ad8\u3002<\/p>\n<h6>\u6700\u77ed\u8def\u5f84\u95ee\u9898<\/h6>\n<p><code>SHORTEST_PATH<\/code>\u662f\u4e00\u4e2aAQL\u51fd\u6570\uff0c\u5b83\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u67e5\u8be2\u56fe\u6570\u636e\uff0c\u5e76\u8fd4\u56de\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002<\/p>\n<p>Find a shortest path between Bismarck Municipal Airport and John F. Kennedy airport and return the airport names on the route<\/p>\n<pre><code class=\"language-mysql\">WITH airports\nFOR v IN OUTBOUND\n  SHORTEST_PATH 'airports\/BIS'\n  TO 'airports\/JFK' flights\n  RETURN v.name<\/code><\/pre>\n<p>\u8fd4\u56de\u4ece BIS \u5230 JFK \u7684\u6700\u5c11\u822a\u73ed<strong>\u6570<\/strong>\uff1a\u4f7f\u7528LET<\/p>\n<pre><code class=\"language-mysql\">WITH airports\nLET airports = (\n  FOR v IN OUTBOUND\n    SHORTEST_PATH 'airports\/BIS'\n    TO 'airports\/JFK' flights\n    RETURN v\n)\nRETURN LENGTH(airports) - 1<\/code><\/pre>\n<h6>\u6a21\u5f0f\u5339\u914d\u8bc6\u522b<\/h6>\n<p>\u7528\u4e8e\u5728\u8003\u8651\u6574\u4e2a\u8def\u5f84\u7684\u904d\u5386\u4e2d\u5e94\u7528\u590d\u6742\u7684\u8fc7\u6ee4\u6761\u4ef6<\/p>\n<p><strong>FOR<\/strong> endVertex, edgeToVertex <strong>IN<\/strong> \u2026 <strong>FOR<\/strong> vertex, edge, path <strong>IN<\/strong> \u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56fe\u64cd\u4f5c\u76f8\u5173<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[30],"tags":[29,28,41],"class_list":["post-283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-30","tag-aql","tag-arangodb","tag-41"],"_links":{"self":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":3,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":528,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions\/528"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reverieland.cn\/index.php\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}