Skip to content

Commit 60eeda1

Browse files
committed
Fix and improve index.sql addendum (apache#2301)
NOTE: This PR was created with the help of AI tools and a human. Added additional requested regression tests - *EXPLAIN for pattern with WHERE clause *EXPLAIN for pattern with filters on both country and city modified: regress/expected/index.out modified: regress/sql/index.sql
1 parent 2108171 commit 60eeda1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

regress/expected/index.out

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,19 @@ $$) as (name agtype);
626626
"Tijuana"
627627
(6 rows)
628628

629+
-- EXPLAIN for pattern with WHERE clause
630+
SELECT * FROM cypher('cypher_index', $$
631+
EXPLAIN (costs off) MATCH (a:City)
632+
WHERE a.country_code = 'US' AND a.west_coast = true
633+
RETURN a
634+
$$) as (plan agtype);
635+
QUERY PLAN
636+
-------------------------------------------------------------------------------------------------------------
637+
Index Scan using city_west_coast_idx on "City" a
638+
Index Cond: (agtype_access_operator(VARIADIC ARRAY[properties, '"west_coast"'::agtype]) = 'true'::agtype)
639+
Filter: (agtype_access_operator(VARIADIC ARRAY[properties, '"country_code"'::agtype]) = '"US"'::agtype)
640+
(3 rows)
641+
629642
-- Test WHERE with multiple conditions (AND)
630643
SELECT * FROM cypher('cypher_index', $$
631644
MATCH (a:City)
@@ -700,6 +713,27 @@ $$) as (name agtype);
700713
"Mexico"
701714
(1 row)
702715

716+
-- EXPLAIN for pattern with filters on both country and city
717+
SELECT * FROM cypher('cypher_index', $$
718+
EXPLAIN (costs off) MATCH (country:Country)<-[:has_city]-(city:City)
719+
WHERE country.country_code = 'CA' AND city.west_coast = true
720+
RETURN city.name
721+
$$) as (plan agtype);
722+
QUERY PLAN
723+
-------------------------------------------------------------------------------------------------------------------------
724+
Nested Loop
725+
-> Nested Loop
726+
-> Index Scan using city_west_coast_idx on "City" city
727+
Index Cond: (agtype_access_operator(VARIADIC ARRAY[properties, '"west_coast"'::agtype]) = 'true'::agtype)
728+
-> Bitmap Heap Scan on has_city _age_default_alias_0
729+
Recheck Cond: (start_id = city.id)
730+
-> Bitmap Index Scan on has_city_start_id_idx
731+
Index Cond: (start_id = city.id)
732+
-> Index Scan using "Country_pkey" on "Country" country
733+
Index Cond: (id = _age_default_alias_0.end_id)
734+
Filter: (agtype_access_operator(VARIADIC ARRAY[properties, '"country_code"'::agtype]) = '"CA"'::agtype)
735+
(11 rows)
736+
703737
-- Test WHERE in combination with pattern matching
704738
SELECT * FROM cypher('cypher_index', $$
705739
MATCH (country:Country)<-[:has_city]-(city:City)

regress/sql/index.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ SELECT * FROM cypher('cypher_index', $$
357357
ORDER BY a.city_id
358358
$$) as (name agtype);
359359

360+
-- EXPLAIN for pattern with WHERE clause
361+
SELECT * FROM cypher('cypher_index', $$
362+
EXPLAIN (costs off) MATCH (a:City)
363+
WHERE a.country_code = 'US' AND a.west_coast = true
364+
RETURN a
365+
$$) as (plan agtype);
366+
360367
-- Test WHERE with multiple conditions (AND)
361368
SELECT * FROM cypher('cypher_index', $$
362369
MATCH (a:City)
@@ -404,6 +411,13 @@ SELECT * FROM cypher('cypher_index', $$
404411
RETURN c.name
405412
$$) as (name agtype);
406413

414+
-- EXPLAIN for pattern with filters on both country and city
415+
SELECT * FROM cypher('cypher_index', $$
416+
EXPLAIN (costs off) MATCH (country:Country)<-[:has_city]-(city:City)
417+
WHERE country.country_code = 'CA' AND city.west_coast = true
418+
RETURN city.name
419+
$$) as (plan agtype);
420+
407421
-- Test WHERE in combination with pattern matching
408422
SELECT * FROM cypher('cypher_index', $$
409423
MATCH (country:Country)<-[:has_city]-(city:City)

0 commit comments

Comments
 (0)