Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect result of B-tree secondary index search in index-only … #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ private boolean isMatched(IAType type1, IAType type2, boolean useListDomain) thr
if (type1 == null || type2 == null) {
return false;
}
if (ATypeHierarchy.isSameTypeDomain(Index.getNonNullableType(type1).first.getTypeTag(),
Index.getNonNullableType(type2).first.getTypeTag(), useListDomain)) {
if (ATypeHierarchy.isSameTypeDomain(Index.getNonNullableType(type1, null).first.getTypeTag(),
Index.getNonNullableType(type2, null).first.getTypeTag(), useListDomain)) {
return true;
}
return ATypeHierarchy.canPromote(Index.getNonNullableType(type1).first.getTypeTag(),
Index.getNonNullableType(type2).first.getTypeTag());
return ATypeHierarchy.canPromote(Index.getNonNullableType(type1, null).first.getTypeTag(),
Index.getNonNullableType(type2, null).first.getTypeTag());
}

private Set<Index> fetchSecondaryIndexPreferences(IAccessMethod accessMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ public boolean acceptsFunction(AbstractFunctionCallExpression functionExpr, Inde
if (!CAST_NULL_TYPE_CONSTRUCTORS.contains(funId)) {
return false;
}
IAType nonNullableType = Index.getNonNullableType(indexedFieldType).first;
IAType nonNullableType = Index.getNonNullableType(indexedFieldType, index.getIndexType()).first;
Pair<FunctionIdentifier, IAObject> constructorWithFmt =
IndexUtil.getTypeConstructorDefaultNull(index, nonNullableType, functionExpr.getSourceLocation());
FunctionIdentifier indexedFieldConstructorFun = constructorWithFmt.first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public boolean isPrimaryKeyIndex() {
return indexType == IndexType.BTREE && ((ValueIndexDetails) indexDetails).keyFieldNames.isEmpty();
}

public static Pair<IAType, Boolean> getNonNullableType(IAType keyType) {
public static Pair<IAType, Boolean> getNonNullableType(IAType keyType, IndexType indexType) {
boolean nullable = false;
IAType actualKeyType = keyType;
if (NonTaggedFormatUtil.isOptional(keyType)) {
Expand All @@ -166,7 +166,7 @@ public static Pair<IAType, Boolean> getNonNullableType(IAType keyType) {
public static Pair<IAType, Boolean> getNonNullableOpenFieldType(Index index, IAType fieldType,
List<String> fieldName, ARecordType recType) throws AlgebricksException {
if (IndexUtil.castDefaultNull(index)) {
Pair<IAType, Boolean> nonNullableType = getNonNullableType(fieldType);
Pair<IAType, Boolean> nonNullableType = getNonNullableType(fieldType, index.getIndexType());
nonNullableType.second = true;
return nonNullableType;
}
Expand All @@ -185,21 +185,21 @@ public static Pair<IAType, Boolean> getNonNullableOpenFieldType(Index index, IAT
}

if (subType == null) {
keyPairType = Index.getNonNullableType(fieldType);
keyPairType = Index.getNonNullableType(fieldType, index.getIndexType());
break;
}
}
if (subType != null) {
keyPairType = Index.getNonNullableKeyFieldType(fieldName, recType);
keyPairType = Index.getNonNullableKeyFieldType(fieldName, recType, index.getIndexType());
}
keyPairType.second = keyPairType.second || nullable;
return keyPairType;
}

public static Pair<IAType, Boolean> getNonNullableKeyFieldType(List<String> expr, ARecordType recType)
throws AlgebricksException {
public static Pair<IAType, Boolean> getNonNullableKeyFieldType(List<String> expr, ARecordType recType,
IndexType indexType) throws AlgebricksException {
IAType keyType = Index.keyFieldType(expr, recType);
Pair<IAType, Boolean> pair = getNonNullableType(keyType);
Pair<IAType, Boolean> pair = getNonNullableType(keyType, indexType);
pair.second = pair.second || recType.isSubFieldNullable(expr);
return pair;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.List;

import org.apache.asterix.common.config.DatasetConfig;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.common.exceptions.CompilationException;
import org.apache.asterix.common.exceptions.ErrorCode;
Expand Down Expand Up @@ -166,14 +167,14 @@ public static Pair<IAType, Boolean> getNonNullableOpenFieldType(IAType fieldType
}

if (subType == null) {
keyPairType = Index.getNonNullableType(fieldType);
keyPairType = Index.getNonNullableType(fieldType, DatasetConfig.IndexType.ARRAY);
break;
}
}

if (subType != null) {
IAType keyType = ArrayIndexUtil.getSubFieldType(recType, unnestList, projectList);
Pair<IAType, Boolean> pair = Index.getNonNullableType(keyType);
Pair<IAType, Boolean> pair = Index.getNonNullableType(keyType, DatasetConfig.IndexType.ARRAY);
pair.second = pair.second || ArrayIndexUtil.isSubFieldNullable(recType, unnestList, projectList);
keyPairType = pair;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
: metaType;
addSKEvalFactories(itemType, numSecondaryKeys, true);
Pair<IAType, Boolean> keyTypePair;
keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType);
keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType());
IAType type = keyTypePair.first;
ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type);
secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde;
Expand Down Expand Up @@ -535,7 +535,7 @@ private void addFilterFieldToBuilder(ARecordType recordType) throws AlgebricksEx
IScalarEvaluatorFactory sef = metadataProvider.getDataFormat().getFieldAccessEvaluatorFactory(
metadataProvider.getFunctionManager(), recordType, filterFieldName, numPrimaryKeys, sourceLoc);
evalFactoryAndRecDescStackBuilder.addFilter(sef,
Index.getNonNullableKeyFieldType(filterFieldName, recordType).first);
Index.getNonNullableKeyFieldType(filterFieldName, recordType, index.getIndexType()).first);
}

class EvalFactoryAndRecDescInvoker implements ArrayIndexUtil.TypeTrackerCommandExecutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
sourceColumn = recordColumn + 1;
enforcedType = enforcedMetaType;
}
IAType filterType = Index.getNonNullableKeyFieldType(filterFieldName, sourceType).first;
IAType filterType =
Index.getNonNullableKeyFieldType(filterFieldName, sourceType, index.getIndexType()).first;
IScalarEvaluatorFactory filterAccessor = createFieldAccessor(sourceType, sourceColumn, filterFieldName);
secondaryFieldAccessEvalFactories[numSecondaryKeys] =
createFieldCast(filterAccessor, isOverridingKeyFieldTypes, enforcedType, sourceType, filterType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
sourceColumn = recordColumn + 1;
enforcedType = enforcedMetaType;
}
IAType filterType = Index.getNonNullableKeyFieldType(filterFieldName, sourceType).first;
IAType filterType =
Index.getNonNullableKeyFieldType(filterFieldName, sourceType, index.getIndexType()).first;
IScalarEvaluatorFactory filterAccessor = createFieldAccessor(sourceType, sourceColumn, filterFieldName);
secondaryFieldAccessEvalFactories[numSecondaryKeys] =
createFieldCast(filterAccessor, isOverridingKeyTypes, enforcedType, sourceType, filterType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
secondaryFieldAccessEvalFactories[numSecondaryKeys] = metadataProvider.getDataFormat()
.getFieldAccessEvaluatorFactory(metadataProvider.getFunctionManager(), filterItemType,
filterFieldName, recordColumn, sourceLoc);
Pair<IAType, Boolean> keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType);
Pair<IAType, Boolean> keyTypePair =
Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, indexType);
IAType type = keyTypePair.first;
ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type);
secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
rtreeFields[i] = i;
}

Pair<IAType, Boolean> typePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType);
Pair<IAType, Boolean> typePair =
Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType());
IAType type = typePair.first;
ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(type);
secondaryRecFields[numPrimaryKeys + numNestedSecondaryKeyFields] = serde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
secondaryFieldAccessEvalFactories[numSecondaryKeys] = metadataProvider.getDataFormat()
.getFieldAccessEvaluatorFactory(metadataProvider.getFunctionManager(), filterItemType,
filterFieldName, numPrimaryKeys, sourceLoc);
Pair<IAType, Boolean> keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType);
Pair<IAType, Boolean> keyTypePair =
Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, indexType);
IAType type = keyTypePair.first;
ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type);
secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException {
rtreeFields[i] = i;
}

Pair<IAType, Boolean> typePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType);
Pair<IAType, Boolean> typePair =
Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType());
IAType type = typePair.first;
ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(type);
secondaryRecFields[numPrimaryKeys + numNestedSecondaryKeyFields] = serde;
Expand Down