Skip to content

Commit 8f89648

Browse files
committed
Fix 6.x regression when using fts::index and certain inheritance patterns
In #7743, we moved `fts` and some other modules underneath `std`. Unfortunately, index names are not properly normalized to refer to them as such, and so FTS indexes specified as `fts::index` would typically have `fts::index` as their shortname. This is wrong in general, and also specifically wrong since some code paths *do* produce normalized names, causing breakages. Fix it by normalizing the name. I did some testing, and this should be backportable if we use `schema-repair`. I hate `schema-repair` but I think it is safer than some of the non-repair ideas I had, like trying to ignore this particular name difference. Fixes #8465
1 parent 13ce875 commit 8f89648

5 files changed

+72
-10
lines changed

edb/schema/indexes.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def is_index_supporting_tuples(
102102
"std::fts::index",
103103
"ext::pg_trgm::gin",
104104
"ext::pg_trgm::gist",
105-
"pg::gist",
106-
"pg::gin",
107-
"pg::brin",
105+
"std::pg::gist",
106+
"std::pg::gin",
107+
"std::pg::brin",
108108
}
109109

110110

@@ -577,9 +577,18 @@ def _classname_from_ast(
577577
) -> sn.QualName:
578578
# We actually want to override how ReferencedObjectCommand determines
579579
# the classname
580-
shortname = super(
581-
referencing.ReferencedObjectCommand, cls
582-
)._classname_from_ast(schema, astnode, context)
580+
#
581+
# We need to resolve the name so that we get fully
582+
# canonicalized names for things like fts::index, which are
583+
# properly std::fts::index.
584+
# (We have to do that ourselves here because we are skipping
585+
# ReferencedObjectCommand, which would otherwise handle it.)
586+
shortname = utils.resolve_name(
587+
utils.ast_ref_to_name(astnode.name),
588+
modaliases=context.modaliases,
589+
schema=schema,
590+
metaclass=cls.get_schema_metaclass(),
591+
)
583592

584593
referrer_ctx = cls.get_referrer_context(context)
585594
if referrer_ctx is not None:

tests/test_edgeql_data_migration.py

+25
Original file line numberDiff line numberDiff line change
@@ -8361,6 +8361,31 @@ async def test_edgeql_migration_eq_index_04(self):
83618361
}],
83628362
)
83638363

8364+
async def test_edgeql_migration_eq_index_05(self):
8365+
await self.migrate('''
8366+
abstract type Named {
8367+
index fts::index on (
8368+
std::fts::with_options(
8369+
.name, language := std::fts::Language.eng));
8370+
required property name: std::str;
8371+
};
8372+
''')
8373+
8374+
await self.start_migration('''
8375+
abstract type Named {
8376+
index std::fts::index on (
8377+
std::fts::with_options(
8378+
.name, language := std::fts::Language.eng));
8379+
required property name: std::str;
8380+
};
8381+
''')
8382+
8383+
# no changes
8384+
await self.assert_describe_migration({
8385+
'confirmed': [],
8386+
'complete': True,
8387+
})
8388+
83648389
async def test_edgeql_migration_eq_collections_01(self):
83658390
await self.migrate(r"""
83668391
type Base;

tests/test_edgeql_ddl.py

+28
Original file line numberDiff line numberDiff line change
@@ -13565,6 +13565,34 @@ async def test_edgeql_ddl_index_09(self):
1356513565
};
1356613566
""")
1356713567

13568+
async def test_edgeql_ddl_index_fts_01(self):
13569+
await self.con.execute('''
13570+
CREATE ABSTRACT TYPE default::Named {
13571+
CREATE REQUIRED PROPERTY name: std::str;
13572+
CREATE INDEX fts::index ON (
13573+
fts::with_options(.name, language := fts::Language.eng)
13574+
);
13575+
};
13576+
13577+
CREATE ABSTRACT TYPE default::Project EXTENDING default::Named
13578+
{
13579+
ALTER PROPERTY name {
13580+
SET OWNED;
13581+
CREATE CONSTRAINT std::exclusive;
13582+
};
13583+
};
13584+
''')
13585+
13586+
# Names canonicalized as std::fts::index
13587+
await self.assert_query_result(
13588+
'''
13589+
select schema::Index { name }
13590+
filter exists .<indexes[is schema::ObjectType]
13591+
and .name like '%index';
13592+
''',
13593+
[{"name": "std::fts::index"}, {"name": "std::fts::index"}]
13594+
)
13595+
1356813596
async def test_edgeql_ddl_abstract_index_01(self):
1356913597
for _ in range(2):
1357013598
await self.con.execute('''

tests/test_edgeql_explain.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ def get_gist_index_expected_res(self, fname, plan_type, message=None):
13741374
'title': 'index_name',
13751375
'type': 'index',
13761376
'value':
1377-
f"index 'pg::gist' of object type "
1377+
f"index 'std::pg::gist' of object type "
13781378
f"'default::RangeTest' on (.{fname})",
13791379
},
13801380
{
@@ -1410,7 +1410,7 @@ def get_gist_index_expected_res(self, fname, plan_type, message=None):
14101410
'title': 'index_name',
14111411
'type': 'index',
14121412
'value':
1413-
f"index 'pg::gist' of object"
1413+
f"index 'std::pg::gist' of object"
14141414
f" type 'default::RangeTest'"
14151415
f" on (.{fname})",
14161416
},
@@ -1897,7 +1897,7 @@ async def test_edgeql_explain_json_contains_01(self):
18971897
'title': 'index_name',
18981898
'type': 'index',
18991899
'value':
1900-
f"index 'pg::gin' of object"
1900+
f"index 'std::pg::gin' of object"
19011901
f" type 'default::JSONTest'"
19021902
f" on (.val)",
19031903
},

tests/test_indexes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ async def test_index_08(self):
295295
{
296296
'indexes': [
297297
{
298-
'name': 'fts::index',
298+
'name': 'std::fts::index',
299299
'kwargs': [],
300300
'expr': (
301301
'std::fts::with_options(.name, '

0 commit comments

Comments
 (0)