After further review, I'm really not sure why the first/second queries don't use the index. The problem with the last query is that %Key is the index in the list, not anything about Tag itself.
Here's a solution that performs well in my testing:
Class DC.Demo.Tag Extends (%Persistent, %Populate)
{
Index Tag On Tag [ Unique ];
Property Tag As %String;
}
Class DC.Demo.Tagged Extends (%Persistent, %Populate)
{
Relationship HasTags As DC.Demo.HasTag [ Cardinality = children, Inverse = Tagged ];
ClassMethod Run()
{
Do ..%KillExtent()
Do ##class(DC.Demo.Tag).%KillExtent()
Do ##class(DC.Demo.Tag).Populate(50)
Do ..Populate(5000)
Do ##class(DC.Demo.HasTag).Populate(10000)
}
}
Class DC.Demo.HasTag Extends (%Persistent, %Populate)
{
Relationship Tagged As DC.Demo.Tagged [ Cardinality = parent, Inverse = HasTags ];
Property Tag As DC.Demo.Tag [ Required ];
Index UniqueTag On Tag [ IdKey ];
Index TaggedByTag On (Tag, Tagged);
}- Log in to post comments