Dmitry Lychagin has submitted this change and it was merged. Change subject: [ASTERIXDB-1959][COMP] Fixed wrong result with non-enforced index ......................................................................
[ASTERIXDB-1959][COMP] Fixed wrong result with non-enforced index - user model changes: no - storage format changes: no - interface changes: no Details: - Fixed issue when data is not inserted into a non-enforced secondary index during ingestion if multiple non-enforced secondary indexes are defined on the same field but with different indexed types Change-Id: I0fe3c9c8045411939d3ad946f6e3b6105ebe1f5a Reviewed-on: https://asterix-gerrit.ics.uci.edu/1872 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> BAD: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Yingyi Bu <[email protected]> --- M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AccessMethodUtils.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.2.update.ddl A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml 7 files changed, 122 insertions(+), 13 deletions(-) Approvals: Yingyi Bu: Looks good to me, approved Jenkins: Verified; No violations found; No violations found; Verified diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java index a39c84b..ec3ec26 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java @@ -266,6 +266,7 @@ hasSecondaryIndex = true; // Get the secondary fields names and types List<List<String>> secondaryKeyFields = index.getKeyFieldNames(); + List<IAType> secondaryKeyTypes = index.getKeyFieldTypes(); List<LogicalVariable> secondaryKeyVars = new ArrayList<>(); List<Mutable<ILogicalExpression>> secondaryExpressions = new ArrayList<>(); List<Mutable<ILogicalExpression>> beforeOpSecondaryExpressions = new ArrayList<>(); @@ -273,7 +274,7 @@ for (int i = 0; i < secondaryKeyFields.size(); i++) { IndexFieldId indexFieldId = new IndexFieldId(index.getKeyFieldSourceIndicators().get(i), - secondaryKeyFields.get(i)); + secondaryKeyFields.get(i), secondaryKeyTypes.get(i).getTypeTag()); LogicalVariable skVar = fieldVarsForNewRecord.get(indexFieldId); secondaryKeyVars.add(skVar); secondaryExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(skVar))); @@ -550,7 +551,8 @@ List<List<String>> skNames = index.getKeyFieldNames(); List<Integer> indicators = index.getKeyFieldSourceIndicators(); for (int i = 0; i < index.getKeyFieldNames().size(); i++) { - IndexFieldId indexFieldId = new IndexFieldId(indicators.get(i), skNames.get(i)); + IndexFieldId indexFieldId = + new IndexFieldId(indicators.get(i), skNames.get(i), skTypes.get(i).getTypeTag()); if (fieldAccessVars.containsKey(indexFieldId)) { // already handled in a different index continue; @@ -684,27 +686,41 @@ return filterExpression; } - private class IndexFieldId { - private int indicator; - private List<String> fieldName; + private final class IndexFieldId { + private final int indicator; + private final List<String> fieldName; + private final ATypeTag fieldType; - public IndexFieldId(int indicator, List<String> fieldName) { + private IndexFieldId(int indicator, List<String> fieldName, ATypeTag fieldType) { this.indicator = indicator; this.fieldName = fieldName; + this.fieldType = fieldType; } @Override public int hashCode() { - return 31 * indicator + fieldName.hashCode(); + int result = indicator; + result = 31 * result + fieldName.hashCode(); + result = 31 * result + fieldType.hashCode(); + return result; } @Override public boolean equals(Object o) { - if (o instanceof IndexFieldId) { - IndexFieldId oIndexFieldId = (IndexFieldId) o; - return indicator == oIndexFieldId.indicator && fieldName.equals(oIndexFieldId.fieldName); + if (this == o) { + return true; } - return false; + if (o == null || getClass() != o.getClass()) { + return false; + } + IndexFieldId that = (IndexFieldId) o; + if (indicator != that.indicator) { + return false; + } + if (!fieldName.equals(that.fieldName)) { + return false; + } + return fieldType == that.fieldType; } } } diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AccessMethodUtils.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AccessMethodUtils.java index 24bad15..fcc2d8b 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AccessMethodUtils.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AccessMethodUtils.java @@ -444,8 +444,8 @@ IAType probeType = TypeComputeUtils.getActualType(optFuncExpr.getFieldType(probeVarIndex)); ATypeTag probeTypeTypeTag = probeType.getTypeTag(); if (probeTypeTypeTag != indexedFieldTypeTag) { - ScalarFunctionCallExpression castFunc = - new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE_LAX)); + ScalarFunctionCallExpression castFunc = new ScalarFunctionCallExpression( + FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE_LAX)); castFunc.getArguments().add(new MutableObject<>(probeExpr)); TypeCastUtils.setRequiredAndInputTypes(castFunc, indexedFieldType, probeType); boolean realTypeConvertedToIntegerType = diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.1.ddl.sqlpp new file mode 100644 index 0000000..e381c48 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.1.ddl.sqlpp @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/* +* Description : [ASTERIXDB-1959] Multiple non-enforced indexes +* : on the same field, created before data loading +* Expected Res : Success +* Date : 29 Jun 2017 +*/ +drop dataverse test if exists; +create dataverse test; +use test; + +create type GleambookUserType as { id: int }; + +create dataset GleambookUsers(GleambookUserType) +primary key id; + +create index gbUserSinceIdxDateTime on GleambookUsers(userSince: datetime?); + +create index gbUserSinceIdxInt on GleambookUsers(userSince: int?); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.2.update.ddl b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.2.update.ddl new file mode 100644 index 0000000..98b8d87 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.2.update.ddl @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use test; + +insert into GleambookUsers +([ +{ "id":1, "alias":"Bram", "userSince":datetime("2010-10-16T10:10:00") }, +{ "id":2, "alias":"Donald", "userSince":"yesterday" }, +{ "id":3, "alias":"Hillery", "userSince":2016 } +]); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.query.sqlpp new file mode 100644 index 0000000..846ce4b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.query.sqlpp @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use test; + +select value user +from GleambookUsers user +where user.userSince > 900; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.adm new file mode 100644 index 0000000..bd7fb48 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/open-index-non-enforced/index-selection/btree-index-03/btree-index-03.3.adm @@ -0,0 +1 @@ +{ "id": 3, "alias": "Hillery", "userSince": 2016 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index a2f6d7d..df0c6b5 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -3589,6 +3589,11 @@ <output-dir compare="Text">btree-index-02</output-dir> </compilation-unit> </test-case> + <test-case FilePath="open-index-non-enforced/index-selection"> + <compilation-unit name="btree-index-03"> + <output-dir compare="Text">btree-index-03</output-dir> + </compilation-unit> + </test-case> <test-case FilePath="open-index-non-enforced/correlated-index-selection"> <compilation-unit name="btree-index-01"> <output-dir compare="Text">btree-index-01</output-dir> -- To view, visit https://asterix-gerrit.ics.uci.edu/1872 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0fe3c9c8045411939d3ad946f6e3b6105ebe1f5a Gerrit-PatchSet: 3 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Dmitry Lychagin <[email protected]> Gerrit-Reviewer: Dmitry Lychagin <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]> Gerrit-Reviewer: Yingyi Bu <[email protected]>
