Query 3: Using a secondary index with an index range scan
Fetch the bag details for a particular reservation
code.
SELECT fullName,bag.ticketNo, bag.confNo, bag.bagInfo[].tagNum,
bag.bagInfo[].routing FROM BaggageInfo bag WHERE bag.confNo="FH7G1W"
Plan:
{
"iterator kind" : "RECEIVE",
"distribution kind" : "ALL_SHARDS",
"input iterator" :
{
"iterator kind" : "SELECT",
"FROM" :
{
"iterator kind" : "TABLE",
"target table" : "BaggageInfo",
"row variable" : "$$bag",
"index used" : "fixedschema_conf",
"covering index" : false,
"index scans" : [
{
"equality conditions" : {"confNo":"FH7G1W"},
"range conditions" : {}
}
]
},
"FROM variable" : "$$bag",
"SELECT expressions" : [
{
"field name" : "fullName",
"field expression" :
{
"iterator kind" : "FIELD_STEP",
"field name" : "fullName",
"input iterator" :
{
"iterator kind" : "VAR_REF",
"variable" : "$$bag"
}
}
},
{
"field name" : "ticketNo",
"field expression" :
{
"iterator kind" : "FIELD_STEP",
"field name" : "ticketNo",
"input iterator" :
{
"iterator kind" : "VAR_REF",
"variable" : "$$bag"
}
}
},
{
"field name" : "confNo",
"field expression" :
{
"iterator kind" : "FIELD_STEP",
"field name" : "confNo",
"input iterator" :
{
"iterator kind" : "VAR_REF",
"variable" : "$$bag"
}
}
},
{
"field name" : "tagNum",
"field expression" :
{
"iterator kind" : "ARRAY_CONSTRUCTOR",
"conditional" : true,
"input iterators" : [
{
"iterator kind" : "FIELD_STEP",
"field name" : "tagNum",
"input iterator" :
{
"iterator kind" : "ARRAY_FILTER",
"input iterator" :
{
"iterator kind" : "FIELD_STEP",
"field name" : "bagInfo",
"input iterator" :
{
"iterator kind" : "VAR_REF",
"variable" : "$$bag"
}
}
}
}
]
}
},
{
"field name" : "routing",
"field expression" :
{
"iterator kind" : "ARRAY_CONSTRUCTOR",
"conditional" : true,
"input iterators" : [
{
"iterator kind" : "FIELD_STEP",
"field name" : "routing",
"input iterator" :
{
"iterator kind" : "ARRAY_FILTER",
"input iterator" :
{
"iterator kind" : "FIELD_STEP",
"field name" : "bagInfo",
"input iterator" :
{
"iterator kind" : "VAR_REF",
"variable" : "$$bag"
}
}
}
}
]
}
}
]
}
}
Explanation:
- The root iterator of this query plan is a RECEIVE iterator with a single child (input iterator) that is a SELECT iterator.
- The value of the
FROM
field is an iterator; in this case, it is a TABLE iterator. - The index
fixedschema_conf
is used and the index is not covering (as you need to scan the table to fetch columns other than the index entries). - The index scan property contains the start and stop conditions that define the index scans to be performed.
- The FROM variable is the name of a variable ranging over the
records produced by the FROM iterator. Here the FROM
iterator is a TABLE iterator, and the FROM variable
(
$$bag
) is the same as the row variable of the TABLE iterator, as the index used is not covering. - In the SELECT expression four fields
(
fullname,ticketNo,confNo,bag.bagInfo[].tagNum,bag.bagInfo[].routing
) are fetched. These correspond to five field names and field expressions in the SELECT expression clause. For the first three fields, the field expression is computed usingFIELD_STEP
iterator. For the last two fields, anARRAY_CONSTRUCTOR
iterator is used which iterates over the corresponding arrays to fetch the field value.