* ValidateMatchForOrderbyQuals walks the order by operator * clauses and ensures that every clause is valid for the * current index. */
| 946 | * current index. |
| 947 | */ |
| 948 | static bool |
| 949 | ValidateMatchForOrderbyQuals(IndexPath *path) |
| 950 | { |
| 951 | ListCell *orderbyCell; |
| 952 | int index = 0; |
| 953 | foreach(orderbyCell, path->indexorderbys) |
| 954 | { |
| 955 | Expr *orderQual = (Expr *) lfirst(orderbyCell); |
| 956 | |
| 957 | /* Order by on RUM only supports OpExpr clauses */ |
| 958 | if (!IsA(orderQual, OpExpr)) |
| 959 | { |
| 960 | return false; |
| 961 | } |
| 962 | |
| 963 | /* Validate that it's a supported operator */ |
| 964 | OpExpr *opQual = (OpExpr *) orderQual; |
| 965 | if (EnableOrderByIndexTerm && |
| 966 | opQual->opfuncid != BsonOrderByFunctionOid() && |
| 967 | opQual->opfuncid != BsonOrderByIndexFunctionOid() && |
| 968 | opQual->opfuncid != BsonOrderByIndexWithCollationFunctionOid() && |
| 969 | opQual->opfuncid != BsonOrderByIndexWithCollationReverseFunctionOid() && |
| 970 | opQual->opfuncid != BsonOrderByIndexReverseFunctionOid()) |
| 971 | { |
| 972 | return false; |
| 973 | } |
| 974 | else if (opQual->opfuncid != BsonOrderByFunctionOid()) |
| 975 | { |
| 976 | return false; |
| 977 | } |
| 978 | |
| 979 | /* OpExpr for order by always has 2 args */ |
| 980 | Assert(list_length(opQual->args) == 2); |
| 981 | Expr *secondArg = lsecond(opQual->args); |
| 982 | if (!IsA(secondArg, Const)) |
| 983 | { |
| 984 | return false; |
| 985 | } |
| 986 | |
| 987 | Const *secondConst = (Const *) secondArg; |
| 988 | int indexColInt = list_nth_int(path->indexorderbycols, index); |
| 989 | bytea *options = path->indexinfo->opclassoptions[indexColInt]; |
| 990 | if (options == NULL) |
| 991 | { |
| 992 | return false; |
| 993 | } |
| 994 | |
| 995 | /* Validate that the path can be pushed to the index. */ |
| 996 | if (!ValidateIndexForQualifierValue(options, secondConst->constvalue, |
| 997 | BSON_INDEX_STRATEGY_DOLLAR_ORDERBY)) |
| 998 | { |
| 999 | return false; |
| 1000 | } |
| 1001 | |
| 1002 | index++; |
| 1003 | } |
| 1004 | |
| 1005 | return true; |
no test coverage detected