Browse Source

Merge pull request #4909 from ghalliday/issue10031

HPCC-10031 Don't create index count if index read has ONFAIL limit

Reviewed-By: Jamie Noss <james.noss@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 years ago
parent
commit
f8c1378ed9

+ 4 - 1
ecl/hql/hqlattr.cpp

@@ -2063,10 +2063,13 @@ bool isLimitedDataset(IHqlExpression * expr, bool onFailOnly)
         {
         case no_choosen:
         case no_limit:
-//      case no_keyedlimit: // not included because it is done before everything else, so filters can be merged in
             if (!onFailOnly || expr->hasAttribute(onFailAtom))
                 return true;
             break;
+        case no_keyedlimit:
+            if (onFailOnly && expr->hasAttribute(onFailAtom))
+                return true;
+            break;
         case no_table:
         case no_newkeyindex:
             return false;

+ 7 - 2
ecl/hql/hqlexpr.cpp

@@ -15054,16 +15054,21 @@ bool recordTypesMatch(ITypeInfo * left, ITypeInfo * right)
     return false;
 }
 
-bool assertRecordTypesMatch(ITypeInfo * left, ITypeInfo * right)
+void assertRecordTypesMatch(ITypeInfo * left, ITypeInfo * right)
 {
     if (recordTypesMatch(left, right))
-        return true;
+        return;
 
     EclIR::dbglogIR(2, left, right);
     throwUnexpected();
 }
 
 
+void assertRecordTypesMatch(IHqlExpression * left, IHqlExpression * right)
+{
+    assertRecordTypesMatch(left->queryRecordType(), right->queryRecordType());
+}
+
 bool recordTypesMatch(IHqlExpression * left, IHqlExpression * right)
 {
     return recordTypesMatch(left->queryRecordType(), right->queryRecordType());

+ 2 - 1
ecl/hql/hqlexpr.hpp

@@ -1590,7 +1590,8 @@ extern HQL_API bool hasUninheritedAttribute(IHqlExpression * field);
 extern HQL_API IHqlExpression * extractChildren(IHqlExpression * value);
 extern HQL_API IHqlExpression * queryOnlyField(IHqlExpression * record);
 extern HQL_API bool recordTypesMatch(ITypeInfo * left, ITypeInfo * right);
-extern HQL_API bool assertRecordTypesMatch(ITypeInfo * left, ITypeInfo * right);
+extern HQL_API void assertRecordTypesMatch(ITypeInfo * left, ITypeInfo * right);
+extern HQL_API void assertRecordTypesMatch(IHqlExpression * left, IHqlExpression * right);
 extern HQL_API bool recordTypesMatch(IHqlExpression * left, IHqlExpression * right);
 extern HQL_API bool recordTypesMatchIgnorePayload(IHqlExpression *left, IHqlExpression *right);
 extern HQL_API IHqlExpression * queryOriginalRecord(IHqlExpression * expr);

+ 1 - 1
ecl/hqlcpp/hqlhtcpp.cpp

@@ -12050,7 +12050,7 @@ BoundRow * HqlCppTranslator::buildTransformCursors(BuildCtx & ctx, IHqlExpressio
     if (transform->getOperator() == no_skip)
         return NULL;
 
-    assertex(recordTypesMatch(self->queryRecord(), transform->queryRecord()));
+    assertRecordTypesMatch(self->queryRecord(), transform->queryRecord());
 
     if (left)
         ctx.addQuoted("const unsigned char * left = (const unsigned char *) _left;");

+ 8 - 0
ecl/hqlcpp/hqlttcpp.cpp

@@ -3545,6 +3545,7 @@ void CompoundSourceInfo::reset()
     isFiltered = false;
     isPostFiltered = false;
     isCreateRowLimited = false;
+    hasOnFail = false;
 }
 
 
@@ -3623,6 +3624,7 @@ bool CompoundSourceInfo::inherit(const CompoundSourceInfo & other, node_operator
     isPostFiltered = other.isPostFiltered;
     isPreloaded = other.isPreloaded;
     isCreateRowLimited = other.isCreateRowLimited;
+    hasOnFail = other.hasOnFail;
     mode = other.mode;
     uid.set(other.uid);
 
@@ -3818,6 +3820,8 @@ void CompoundSourceTransformer::analyseGatherInfo(IHqlExpression * expr)
             {
                 extra->inherit(*parentExtra);
                 extra->ensureCompound();
+                if (expr->hasAttribute(onFailAtom))
+                    extra->hasOnFail = true;
             }
             break;
         }
@@ -3963,6 +3967,10 @@ void CompoundSourceTransformer::analyseGatherInfo(IHqlExpression * expr)
                 if (!parentExtra->isBinary())
                     break;
 
+                //ONFAIL isn't supported for compound aggregates at the moment - although it could be....
+                if (parentExtra->hasOnFail)
+                    break;
+
                 IHqlExpression * root = queryRoot(dataset);
                 if (!root || isGrouped(root) || expr->hasAttribute(localAtom))
                     break;

+ 1 - 0
ecl/hqlcpp/hqlttcpp.ipp

@@ -260,6 +260,7 @@ public:
     bool isFiltered:1;
     bool isPostFiltered:1;
     bool isCreateRowLimited:1;
+    bool hasOnFail:1;
 };
 
 enum

+ 22 - 0
ecl/regress/issue10031.ecl

@@ -0,0 +1,22 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
+
+    Licensed 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.
+############################################################################## */
+
+i := index({ string15 name, unsigned8 filepos} , '~local::rkc::person');
+
+f := i(name = 'Smith');
+l := limit(f, 100, keyed, onfail(transform(recordof(i), SELF := [])));
+output(count(l));