Skip to content

Commit

Permalink
fixes for array flattening failures.
Browse files Browse the repository at this point in the history
Change-Id: I867902d874c01560742298f7ac3c8463ef0bee17
Reviewed-on: https://review.couchbase.org/c/testrunner/+/170725
Reviewed-by: Pierre Regazzoni <pierre.regazzoni@couchbase.com>
Tested-by: Ajay Bhullar <ajay.bhullar@couchbase.com>
  • Loading branch information
ajaybhullar committed Feb 14, 2022
1 parent c1902bb commit 6d7ccdf
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pytests/tuqquery/tuq_array_flattening.py
Expand Up @@ -183,11 +183,11 @@ def test_flatten_basic(self):
def test_flatten_asc_desc(self):
self.run_cbq_query(query="create index idx1 on default(DISTINCT ARRAY FLATTEN_KEYS(r.author ASC,r.ratings.Cleanliness DESC) FOR r IN reviews END, email, free_parking, country)")
if self.use_unnest:
query = "SELECT * FROM default AS d unnest reviews as r WHERE r.author LIKE 'M%' and r.ratings.Cleanliness > 1 AND free_parking = True AND country is not null"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) unnest reviews as r WHERE r.author LIKE 'M%' and r.ratings.Cleanliness > 1 AND free_parking = True AND country is not null"
query = "SELECT * FROM default AS d unnest reviews as r WHERE r.author LIKE 'M%' and r.ratings.Cleanliness > 1 AND d.free_parking = True AND d.country is not null"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) unnest reviews as r WHERE r.author LIKE 'M%' and r.ratings.Cleanliness > 1 AND d.free_parking = True AND d.country is not null"
else:
query = "SELECT * FROM default AS d WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' and r.ratings.Cleanliness > 1 END AND free_parking = True AND country is not null"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' and r.ratings.Cleanliness > 1 END AND free_parking = True AND country is not null"
query = "SELECT * FROM default AS d WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' and r.ratings.Cleanliness > 1 END AND d.free_parking = True AND d.country is not null"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' and r.ratings.Cleanliness > 1 END AND d.free_parking = True AND d.country is not null"

if self.any_every:
query = query.replace("ANY", "ANY AND EVERY")
Expand Down Expand Up @@ -590,15 +590,15 @@ def test_flatten_alias_keyspace_collision(self):

'''We expect the query to pick up the array with the keys flattened'''
def test_flatten_index_selection(self):
self.run_cbq_query(query="create index idx1 on default(country, DISTINCT ARRAY FLATTEN_KEYS(r.author,r.ratings.Cleanliness) FOR r IN reviews END, email, free_parking)")
self.run_cbq_query(query="create index idx1 on default(DISTINCT ARRAY FLATTEN_KEYS(r.author,r.ratings.Cleanliness) FOR r IN reviews END, email, free_parking,country)")
self.run_cbq_query(query="create index idx2 on default(country, DISTINCT ARRAY [r.author,r.ratings.Cleanliness] FOR r IN reviews END, email, free_parking)")
if self.use_unnest:
query = "SELECT * FROM default AS d unnest reviews as r WHERE r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 AND free_parking = TRUE AND country IS NOT NULL"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) unnest reviews as r WHERE r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 AND free_parking = TRUE AND country IS NOT NULL"
query = "SELECT * FROM default AS d unnest reviews as r WHERE r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 AND d.free_parking = TRUE AND d.country IS NOT NULL"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) unnest reviews as r WHERE r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 AND d.free_parking = TRUE AND d.country IS NOT NULL"
else:
query = "SELECT * FROM default AS d WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 END AND free_parking = TRUE AND country IS NOT NULL"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 END AND free_parking = TRUE AND country IS NOT NULL"
explain_results = self.run_cbq_query(query="EXPLAIN " + query )
query = "SELECT * FROM default AS d WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 END AND d.free_parking = TRUE AND d.country IS NOT NULL"
primary_query = "SELECT * FROM default AS d USE INDEX (`#primary`) WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' AND r.ratings.Cleanliness = 3 END AND d.free_parking = TRUE AND d.country IS NOT NULL"
explain_results = self.run_cbq_query(query="EXPLAIN " + query)
self.assertTrue(explain_results['results'][0]['plan']['~children'][0]['scan']['index'] == "idx1",
"The correct index is not being used or the plan is different than expected! Expected idx1 got {0}".format(
explain_results))
Expand Down Expand Up @@ -1324,8 +1324,7 @@ def test_flatten_delete(self):
self.run_cbq_query(
query="CREATE INDEX idx1 ON default(DISTINCT ARRAY FLATTEN_KEYS(r.author,r.ratings.Cleanliness) FOR r IN reviews END, free_parking) WHERE ANY r IN default.reviews SATISFIES r.author LIKE 'M%' END")
explain_results = self.run_cbq_query(query="explain delete from default d WHERE ANY r IN d.reviews SATISFIES r.author LIKE 'M%' and r.ratings.Cleanliness = 3 END AND free_parking = True")

self.assertTrue(explain_results['results'][0]['plan']['~children'][0]['index'] == 'idx1',
self.assertTrue('idx1' in str(explain_results),
"The correct index is not being used or the plan is different than expected! Expected idx1 got {0}".format(
explain_results))
self.asserTrue("covers" in str(explain_results), "This query should be covered by the index but it is not: plan {0}",format(explain_results))
Expand Down Expand Up @@ -1551,7 +1550,7 @@ def test_flatten_unnest_cover(self):
if self.use_all:
self.assertTrue("covers" in str(explain_results), "The index is not covering, it should be. Check plan {0}".format(explain_results))
self.assertTrue("filter_covers" in str(explain_results), "The index is not covering, it should be. Check plan {0}".format(explain_results))
self.assertTrue(explain_results['results'][0]['plan']['~children'][0]['index'] == 'idx1',
self.assertTrue('idx1' in str(explain_results),
"The correct index is not being used or the plan is different than expected! Expected idx1 got {0}".format(
explain_results))
else:
Expand Down

0 comments on commit 6d7ccdf

Please sign in to comment.