Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在加入couchbase时进行适当的索引?_Couchbase_N1ql - Fatal编程技术网

如何在加入couchbase时进行适当的索引?

如何在加入couchbase时进行适当的索引?,couchbase,n1ql,Couchbase,N1ql,我在contact bucket中有一个couchbase文档,格式如下,类型为“organization” "contact": { "extendedData": [], "id": "organization_2_1094", "organizationId": 1094, "organizationName": "SMART COMSSS&qu

我在contact bucket中有一个couchbase文档,格式如下,类型为“organization”

"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"
  }
以及bucket contact中另一个类型为“address”的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,而类型“address”的文档数超过70000,因此我在执行查询时超时

选项:

Change query to ON TO_STRING(aa.addressId) = a.addressId
Or change index to CREATE INDEX `ix3` ON `optima_contact`(TO_NUMBER(`addressId`), `addressId`,`address1`,`address2`,`address3`,`country`,`city`,`zip`,`state`,`postalCode`,`houseNumber`,`streetName`,`fxGeocode`,`isActive`) WHERE (`type` = "address")
Use Hash JOIN in EE. 
Change the JOIN order
Try one of the following 
第一个应该解决你的问题。ON子句与RHS索引键完全匹配,它将推送该值,否则它需要获取所有索引键并在查询端应用谓词

CB 6.5.0

WITH contact AS (SELECT orgrole.name, orgrole.organizationRoleId,
                        orgrole.externalIds AS externalIds, orgrole.roleSpecId,
                        aa.addressId
                 FROM optima_contact AS c
                 UNNEST c.organizationRoles AS orgrole
                 UNNEST orgrole.addressAssociations AS aa WHERE c.type = "organization")
SELECT {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,
        c1.name, c1.organizationRoleId,
        c1.externalIds, c1.roleSpecId, a.city AS city, a.zip AS zip
FROM optima_contact AS a
UNNEST contact AS c1
WHERE a.type = "address" AND TO_NUMBER(a.addressId) = c1.addressId;
6.5之前

SELECT {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,
        c1.name, c1.organizationRoleId,
        c1.externalIds, c1.roleSpecId, a.city AS city, a.zip AS zip
FROM optima_contact AS a
UNNEST (SELECT orgrole.name, orgrole.organizationRoleId,
                        orgrole.externalIds AS externalIds, orgrole.roleSpecId,
                        aa.addressId
                 FROM optima_contact AS c
                 UNNEST c.organizationRoles AS orgrole
                 UNNEST orgrole.addressAssociations AS aa WHERE c.type = "organization") AS c1
WHERE a.type = "address" AND TO_NUMBER(a.addressId) = c1.addressId;

SELECT a AS address, c1.name, c1.organizationRoleId, c1.externalIds, c1.roleSpecId
FROM optima_contact AS a
UNNEST (SELECT orgrole.name, orgrole.organizationRoleId,
                        orgrole.externalIds AS externalIds, orgrole.roleSpecId,
                        orgrole.addressAssociations[*].addressId AS addresses
                 FROM optima_contact AS c
                 UNNEST c.organizationRoles AS orgrole
                 WHERE c.type = "organization") AS c1
WHERE a.type = "address" AND TO_NUMBER(a.addressId) IN c1.addresses;