Here're also the execution plans from the explorer if that helps:
First query (which works):
Query Plan Description
======================
Step 1: Process IndividualContact ($1) instances
------------------------------------------------
[Step 1a]
Scan type com.quasado.foundation.communication.api.model.contact.individual.IndividualContact
locating all the IndividualContact ($1) instances.
[Step 1b]
Evaluate fields in IndividualContact ($1) instances.
Step 2: Process OrganisationContact (v$1) instances
(for every result of step 1)
---------------------------------------------------
[Step 2a]
Iterate over all the instances (v$1) in $1.organisation.
[Step 2b]
Retrieve fields in OrganisationContact (v$1) instances.
[Step 2c]
Filter the results of step 2b
retaining only results that satisfy:
like(v$1.name,'%Q%').
Step 3: Group results
---------------------
Group the results of step 2by:
$1.
[Step 4]
Remove duplicates from the groups of step 3.
[Step 5]
Apply selection and prepare final results.
Second query (which fails):
Query Plan Description
======================
Step 1: Process IndividualContact ($1) instances
------------------------------------------------
[Step 1a]
Scan type com.quasado.foundation.communication.api.model.contact.individual.IndividualContact
locating all the IndividualContact ($1) instances.
[Step 1b]
Evaluate fields in IndividualContact ($1) instances.
Step 2: Process OrganisationContact (v$1) instances
(for every result of step 1)
---------------------------------------------------
Iterate over all the instances (v$1) in $1.organisation.
Step 3: Process IndividualCommunicationInfo (v$2) instances
(for every result tuple of the steps above)
-----------------------------------------------------------
Iterate over all the instances (v$2) in $1.communication.
Step 4: Extract field values
----------------------------
Retrieve fields in IndividualCommunicationInfo (v$2) instances.
Step 5: Process IndividualCommunicationClassification (v$3) instances
(for every result tuple of the steps above)
---------------------------------------------------------------------
Iterate over all the instances (v$3) in v$2.classification.
Step 6: Process IndividualPostalAddress (v$4) instances
(for every result tuple of the steps above)
-------------------------------------------------------
Iterate over all the instances (v$4) in $1.postalAddresses.
Step 7: Extract field values
----------------------------
Retrieve fields in IndividualPostalAddress (v$4) instances.
Step 8: Process DeliveryPointSpecification (v$5) instances
(for every result tuple of the steps above)
----------------------------------------------------------
Iterate over all the instances (v$5) in v$4.deliveryPoint.
Step 9: Extract field values
----------------------------
Retrieve fields in DeliveryPointSpecification (v$5) instances.
Step 10: Process DeliveryPointLocation (v$6) instances
(for every result tuple of the steps above)
-----------------------------------------------------
Iterate over all the instances (v$6) in v$5.deliveryPointLocation.
Step 11: Extract field values
----------------------------
Retrieve fields in DeliveryPointLocation (v$6) instances.
Step 12: Process Thoroughfare (v$7) instances
(for every result tuple of the steps above)
--------------------------------------------
Iterate over all the instances (v$7) in v$6.thoroughfare.
Step 13: Process IndividualOrganisationPosition (v$8) instances
(for every result tuple of the steps above)
--------------------------------------------------------------
Iterate over all the instances (v$8) in $1.position.
Step 14: Process IndividualProfile (v$9) instances
(for every result tuple of the steps above)
-------------------------------------------------
Iterate over all the instances (v$9) in $1.profile.
Step 15: Process IndividualCommunicationClassification (v$10) instances
(for every result tuple of the steps above)
----------------------------------------------------------------------
Iterate over all the instances (v$10) in v$4.classification.
Step 16: Extract field values
----------------------------
Retrieve fields in IndividualProfile (v$9) instances.
Step 17: Process IndividualTitle (v$11) instances
(for every result tuple of the steps above)
------------------------------------------------
Iterate over all the instances (v$11) in v$9.title.
Step 18: Process Locality (v$12) instances
(for every result tuple of the steps above)
-----------------------------------------
Iterate over all the instances (v$12) in v$5.locality.
Step 19: Extract field values
----------------------------
Retrieve fields in Locality (v$12) instances.
Step 20: Extract field values
----------------------------
Retrieve fields in IndividualTitle (v$11) instances.
Step 21: Extract field values
----------------------------
Retrieve fields in IndividualCommunicationClassification (v$10) instances.
Step 22: Extract field values
----------------------------
Retrieve fields in IndividualOrganisationPosition (v$8) instances.
Step 23: Extract field values
----------------------------
Retrieve fields in Thoroughfare (v$7) instances.
Step 24: Extract field values
----------------------------
Retrieve fields in IndividualCommunicationClassification (v$3) instances.
Step 25: Extract field values
----------------------------
Retrieve fields in OrganisationContact (v$1) instances.
Step 26: Process IndividualSalutation (v$13) instances
(for every result tuple of the steps above)
-----------------------------------------------------
[Step 26a]
Iterate over all the instances (v$13) in v$9.salutation.
[Step 26b]
Retrieve fields in IndividualSalutation (v$13) instances.
[Step 26c]
Filter the results of step 26b
retaining only results that satisfy:
or(like(v$13.name,'%Q%'),like(v$2.fax,'%Q%'),like(v$2.instantMessaging,'%Q%'),like(v$9.lastName,'%Q%'),like(v$12.town,'%Q%'),like(v$11.name,'%Q%'),like(v$5.postalCode,'%Q%'),like(v$6.streetNumberOrPlot,'%Q%'),like(v$10.name,'%Q%'),like(v$2.phone,'%Q%'),like(v$9.firstName,'%Q%'),like(v$2.email,'%Q%'),like(v$2.www,'%Q%'),like($1.job,'%Q%'),like(v$8.name,'%Q%'),like(v$2.cellphone,'%Q%'),like(v$7.name,'%Q%'),like(v$3.name,'%Q%'),like(v$1.name,'%Q%')).
Step 27: Group results
---------------------
Group the results of step 26by:
$1.
[Step 28]
Remove duplicates from the groups of step 27.
[Step 29]
Apply selection and prepare final results.