bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.33k stars 148 forks source link

CTE and subquery return different result #467

Open callin2 opened 5 years ago

callin2 commented 5 years ago

CTE query

with ta as (
  MATCH (n:ip)
    RETURN properties(n) as prop
  limit 100
)
select
         ta.prop->'cid',
         ta.prop->'sid',
         ta.prop->'value',
         ta.prop->'created',
         ta.prop->'description'
from  ta
"21415fc2223dd1541624b90daceff161d49d1234"  "observed-data--9bcafe76-e198-494c-8d8f-bdedb2fa4dbf"   "60.29.153.3"   1538091804688   ""
"def83d2dc3a04a1a38947d67d9df92d8c11d8fdd"  "observed-data--17ae1d84-4149-4261-bdfd-ee5eb6ace905"   "24.55.82.58"   1538091804688   ""
"84c9ae2bf864bc60c14890b3b810622a745859fd"  "observed-data--e20dd8c2-c663-4918-b13e-ed42a4f54e40"   "23.254.162.134"    1538091804688   ""
"6c549fb88b897a073d8c1b8549c36e99c7922a13"  "observed-data--2450035d-3b7e-4936-89b6-c99f89199a1b"   "46.109.158.4"  1538091804688   ""
"32483d4d0aae7b2355a7b9e94847df4a0a10b3ba"  "observed-data--b7e4aa29-3315-4269-909e-0ef57241f849"   "24.41.230.50"  1538091804688   ""
"9d4d23d7f9f95af32c6f3e0e2b9fafd4c2c22ef9"  "observed-data--e00ff032-ad3f-46d5-9fec-effd51bf6030"   "27.195.214.104"    1538091804688   ""
"82102bd56f1813f11bc6aae874e375fe6c26a38f"  "observed-data--d40eb622-a648-4694-8317-e5fa1b09ee5e"   "27.147.146.70" 1538091804688   ""
"86654a35ed9fd1b0d438e3165a62c0bffd0678c0"  "observed-data--9b7ba288-d8a1-40fa-b4a2-4c9e45b34f97"   "54.37.81.144"  1538091804688   ""
"f29c6c0d2c9737be086bdf82199ab3b72adc5cfa"  "observed-data--743b02e5-d9ce-4912-ac35-a4d4bfde9bb8"   "24.41.230.22"  1538091804688   ""
"4fb8d82d690a335289bc3b6ac018a33879f2d391"  "observed-data--83daa7e4-d85d-4d9c-bf70-3de0774bb201"   "46.246.123.55" 1538091804688   ""
"eac9759ed1f36c48b0562ee574776863298fa5b2"  "observed-data--16072136-b36f-45d6-8d58-f3cbb4db36d0"   "46.249.95.124" 1538091804688   ""

subquery

select
         ta.prop->'cid',
         ta.prop->'sid',
         ta.prop->'value',
         ta.prop->'created',
         ta.prop->'description'
from (
  MATCH (n:ip)
    RETURN properties(n) as prop
  limit 100
) as ta
"91aa5469972dfcd4c90dea0a90da346a42db88ab"              
"1a6c4fe598716f668dc6384618632d336143c841"              
"80e84824fb99a6388033c6b1d010db57b0a937d2"              
"c07683b7c3b16596a8c0b2f523bee4b830ae209d"              
"f747f75524060919b5a0e4bf9b10212539e2fe81"              
"e6ec638c294f380703f10efd3cb9eb8a2d8398ae"              
"e6ec638c294f380703f10efd3cb9eb8a2d8398ae"              
"e6ec638c294f380703f10efd3cb9eb8a2d8398ae"              
"e6ec638c294f380703f10efd3cb9eb8a2d8398ae"              
"79afc8567e087104fd9e927ddbc59ec125ef9a6b"              
"0f9bd534e72b1ce31b67d5b4561685f71b408d70"              

I expect same result. but subquery's result is not what I expect!

protodef commented 5 years ago

Thank you for the report. I've tried to reproduce this by running the following query. The first query gives me server closed the connection unexpectedly ... error. The second query gives me the expected result.

CREATE GRAPH g;
CREATE ({cid: '1c', sid: '1s', value: '192.168.0.1'});
CREATE ({cid: '2c', sid: '2s', value: '192.168.0.2'});
CREATE ({cid: '3c', sid: '3s', value: '192.168.0.3'});
CREATE ({cid: '4c', sid: '4s', value: '192.168.0.4'});
CREATE ({cid: '5c', sid: '5s', value: '192.168.0.5'});
CREATE ({cid: '6c', sid: '6s', value: '192.168.0.6'});
CREATE ({cid: '7c', sid: '7s', value: '192.168.0.7'});
CREATE ({cid: '8c', sid: '8s', value: '192.168.0.8'});
CREATE ({cid: '9c', sid: '9s', value: '192.168.0.9'});

-- 1
WITH ta AS (
  MATCH (n) RETURN properties(n) AS prop LIMIT 5
)
SELECT ta.prop->'cid', ta.prop->'sid', ta.prop->'value' FROM ta;

server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

-- 2
SELECT ta.prop->'cid', ta.prop->'sid', ta.prop->'value'
FROM (MATCH (n) RETURN properties(n) AS prop LIMIT 5) AS ta;

 ?column? | ?column? |   ?column?    
----------+----------+---------------
 "1c"     | "1s"     | "192.168.0.1"
 "2c"     | "2s"     | "192.168.0.2"
 "3c"     | "3s"     | "192.168.0.3"
 "4c"     | "4s"     | "192.168.0.4"
 "5c"     | "5s"     | "192.168.0.5"
(5 rows)
joefagan commented 5 years ago

For me both of these return the same results. AgensGraph v2.1.0 on windows. CREATE GRAPH g; SET graph_path = g; CREATE ({cid: '1c', sid: '1s', value: '192.168.0.1'}); CREATE ({cid: '2c', sid: '2s', value: '192.168.0.2'}); CREATE ({cid: '3c', sid: '3s', value: '192.168.0.3'}); CREATE ({cid: '4c', sid: '4s', value: '192.168.0.4'}); CREATE ({cid: '5c', sid: '5s', value: '192.168.0.5'}); CREATE ({cid: '6c', sid: '6s', value: '192.168.0.6'}); CREATE ({cid: '7c', sid: '7s', value: '192.168.0.7'}); CREATE ({cid: '8c', sid: '8s', value: '192.168.0.8'}); CREATE ({cid: '9c', sid: '9s', value: '192.168.0.9'}); --1 with ta as (MATCH (n) RETURN properties(n) as prop limit 5) select ta.prop->'cid', ta.prop->'sid', ta.prop->'value' from ta; ?column? | ?column? | ?column? ----------+----------+--------------- "1c" | "1s" | "192.168.0.1" "2c" | "2s" | "192.168.0.2" "3c" | "3s" | "192.168.0.3" "4c" | "4s" | "192.168.0.4" "5c" | "5s" | "192.168.0.5" (5 rows) --2 select ta.prop->'cid', ta.prop->'sid', ta.prop->'value' from (MATCH (n) RETURN properties(n) as prop limit 5) as ta;

?column? | ?column? | ?column? ----------+----------+--------------- "1c" | "1s" | "192.168.0.1" "2c" | "2s" | "192.168.0.2" "3c" | "3s" | "192.168.0.3" "4c" | "4s" | "192.168.0.4" "5c" | "5s" | "192.168.0.5" (5 rows)