1

Suppose I create an index on Object_pair(values).val.data.

Will my index store the “values” field as an array (with elements name for ID and val for data due to object_pair)?

If so, and also if my n1ql query is a covered query (fetching only Object_pair(values).val.data via select clause), will there still be a performance overhead? (because I am under the impression that in the above case, as index would already contain “values” field as an array, no actual object_pair transformation would take place hence avoiding the overhead. Only in the case of a non-covered query will the actual document be accessed and object_pair transformation done on “values” field).

Couchbase document:

    "values": {
        "item_1": {
            "data": [{
                    "name": "data_1",
                    "value": "A"
                },
                {
                    "name": "data_2",
                    "value": "XYZ"
                }
            ]
        },
        "item_2": {
            "data": [{
                    "name": "data_1",
                    "value": "123"
                },
                {
                    "name": "data_2",
                    "value": "A23"
                }
            ]
        }
    }
}```

UPDATE:
suppose if we plan to create index on Object_pair(values)[*].val.data & Object_pair(values)[*].name

Index: CREATE INDEX idx01 ON ent_comms_tracking(ARRAY { value.name, value.val.data} FOR value IN object_pairs(values) END)

Query: SELECT ARRAY { value.name, value.val.data} FOR value IN object_pairs(values) END as values_array FROM bucket

1 Answers1

2

Can you please paste your full create index statement?

Creating index on OBJECT_PAIRS(values).val.data indexes nothing.

You can check it out by creating a primary index and then running below query:

SELECT OBJECT_PAIRS(`values`).val FROM mybucket

Output is:

[
  {}
]

OBJECT_PAIRS(values) returns arrays of values which contain the attribute name and value pairs of the object values -

SELECT OBJECT_PAIRS(`values`) FROM mybucket


[
  {
    "$1": [
      {
        "name": "item_1",
        "val": {
          "data": [
            {
              "name": "data_1",
              "value": "A"
            },
            {
              "name": "data_2",
              "value": "XYZ"
            }
          ]
        }
      },
      {
        "name": "item_2",
        "val": {
          "data": [
            {
              "name": "data_1",
              "value": "123"
            },
            {
              "name": "data_2",
              "value": "A23"
            }
          ]
        }
      }
    ]
  }
]

It's an array, so val of it is not directly referenced

Varun V
  • 327
  • 2
  • 10
  • 1
    hey @varun-v, I have updated the index & query info in the original post above. Yes I am aware of object_pairs transformation logic, maybe the update above would shed more light on what i meant by creating an index on _Object_pair(values).val.data_. – anshul.gairola Feb 21 '20 at 07:20