У меня есть один документ couchbase в формате, показанном ниже, типа «организация» в контактной корзине.
"contact": {
"extendedData": [],
"id": "organization_2_1094",
"organizationId": 1094,
"organizationName": "SMART COMSSS",
"organizationRoles": [
{
"addressAssociations": [
{
"activeDate": "2019-08-08T03:51:51.417Z",
"addressAssocTypeId": -2,
"addressId": 749,
"ownershipStatus": 1,
"srvAddressStatus": 1
}
],
"extendedData": [
{
"characteristicId": "1",
"characteristicValue": "Plant_Id",
"extendedDataId": "400"
},
{
"characteristicId": "2",
"characteristicValue": "Plant_Type",
"extendedDataId": "401"
}
],
"name": "Store1",
"organizationRoleId": 928,
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "changed",
"organizationRoleId": 929,
"roleSpecId": -104,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"addressAssociations": [
{
"activeDate": "2019-08-08T23:06:49.748Z",
"addressAssocTypeId": -2,
"addressId": 752,
"ownershipStatus": 1,
"srvAddressStatus": 1
}
],
"extendedData": [
{
"characteristicId": "1",
"characteristicValue": "Plant_Id",
"extendedDataId": "402"
},
{
"characteristicId": "2",
"characteristicValue": "Plant_Type",
"extendedDataId": "403"
}
],
"name": "store11",
"organizationRoleId": 930,
"partyRoleAssocs": [
{
"partyRoleAssocId": "531"
}
],
"relevantEntityId": "S_103",
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "new store group",
"organizationRoleId": 931,
"partyRoleAssocs": [
{
"partyRoleAssocId": "532"
}
],
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "child store",
"organizationRoleId": 932,
"partyRoleAssocs": [
{
"partyRoleAssocId": "533"
}
],
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "MCOTEST",
"organizationRoleId": 933,
"roleSpecId": -104,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "new store child",
"organizationRoleId": 934,
"partyRoleAssocs": [
{
"partyRoleAssocId": "534"
}
],
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"name": "new store child",
"organizationRoleId": 935,
"partyRoleAssocs": [
{
"partyRoleAssocId": "535"
},
{
"partyRoleAssocId": "565",
"toRoleId": 936
}
],
"roleSpecId": -103,
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
},
{
"organizationRoleId": 936,
"partyRoleAssocs": [
{
"toRoleId": 935
}
],
"statusId": 1,
"statusLastChangedDate": "2019-08-22T12:27:51.077Z"
}
],
"statusId": 1,
"statusLastChangedDate": "2019-08-22T09:27:51.072Z",
"tenantId": "2",
"type": "organization"
}
и другой документ couchbase типа «адрес» в корзине контактов
{
"contact": {
"address1": "stret",
"addressId": "1000",
"city": "miryalguda",
"countryCode": 4,
"id": "address_2_1000",
"state": "ap",
"tenantId": "2",
"type": "address",
"zip": "500070"
}
}
Теперь я сделал запрос, чтобы получить некоторые данные из документа организации и некоторые данные из адресного документа, присоединив документы по addressId в соответствии с моими требованиями. Ниже приведен запрос:
SELECT orgrole.name, orgrole.organizationRoleId,orgrole.externalIds as externalIds,orgrole.roleSpecId,a.city as city, a.zip as zip,{a.addressId,a.address1,a.address2,a.address3,a.country,a.city, a.zip,a.state,a.postalCode,a.houseNumber,a.streetName,a.fxGeocode,a.isActive} as address FROM `optima_contact` AS contact UNNEST contact.organizationRoles AS orgrole UNNEST orgrole.addressAssociations AS aa JOIN `optima_contact` AS a ON aa.addressId = TO_NUMBER(a.addressId)
WHERE contact.type = "organization" AND a.type = "address"
, и я сделал один индекс для правой стороны соединения.
CREATE INDEX `ix2` ON `optima_contact`(`addressId`,`address1`,`address2`,`address3`,`country`,`city`,`zip`,`state`,`postalCode`,`houseNumber`,`streetName`,`fxGeocode`,`isActive`) WHERE (`type` = "address")
Есть ли способ еще улучшить время выполнения запроса для этого? Поскольку количество документов для типа организации равно 10, а для типа «адрес» более 70000, у меня время ожидания при выполнении запроса