Browse Source

Merge pull request #1149 from ghalliday/countdisk

Remove no_countfile from the code generator

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 13 years ago
parent
commit
e5602c35b1

+ 1 - 1
ecl/hql/hqlattr.cpp

@@ -250,7 +250,6 @@ unsigned getOperatorMetaFlags(node_operator op)
     case no_within:
     case no_notwithin:
     case no_countcompare:
-    case no_countfile:
 
 //Selectors
     case no_left:
@@ -613,6 +612,7 @@ unsigned getOperatorMetaFlags(node_operator op)
     case no_unused30: case no_unused31: case no_unused32: case no_unused33: case no_unused34: case no_unused35: case no_unused36: case no_unused37: case no_unused38:
     case no_unused40: case no_unused41: case no_unused42: case no_unused43: case no_unused44: case no_unused45: case no_unused46: case no_unused47: case no_unused48: case no_unused49:
     case no_unused50: case no_unused52:
+    case no_unused80:
     case no_is_null:
     case no_position:
     case no_current_time:

+ 1 - 0
ecl/hql/hqlattr.hpp

@@ -38,6 +38,7 @@ extern HQL_API bool maxRecordSizeCanBeDerived(IHqlExpression * record);
 extern HQL_API bool reducesRowSize(IHqlExpression * expr);
 extern HQL_API bool increasesRowSize(IHqlExpression * expr);
 extern HQL_API bool isVariableSizeRecord(IHqlExpression * record);
+inline bool isFixedSizeRecord(IHqlExpression * record) { return !isVariableSizeRecord(record); }
 
 extern HQL_API bool recordRequiresDestructor(IHqlExpression * expr);
 extern HQL_API bool recordRequiresSerialization(IHqlExpression * expr);

+ 0 - 8
ecl/hql/hqlexpr.cpp

@@ -949,7 +949,6 @@ const char *getOpString(node_operator op)
     case no_comma: return ",";
     case no_compound: return ",";
     case no_count: case no_countlist: return "COUNT";
-    case no_countfile: return "COUNTFILE";
     case no_counter: return "COUNTER";
     case no_countgroup: return "COUNT";
     case no_distribution: return "DISTRIBUTION";
@@ -1698,7 +1697,6 @@ int getPrecedence(node_operator op)
     case no_filter:
     case no_limit:
     case no_catchds:
-    case no_countfile:
     case no_distribution:
     case NO_AGGREGATE:
     case no_keyedlimit:
@@ -1810,7 +1808,6 @@ childDatasetType getChildDatasetType(IHqlExpression * expr)
     case no_throughaggregate:
     case no_countcompare:
     case no_fieldmap:
-    case no_countfile:
     case NO_AGGREGATE:
     case no_output:
     case no_buildindex:
@@ -2068,7 +2065,6 @@ inline unsigned doGetNumChildTables(IHqlExpression * dataset)
     case no_aggregate:
     case no_usertable:
     case NO_AGGREGATE:
-    case no_countfile:
     case no_output:
     case no_buildindex:
     case no_distribution:
@@ -3253,8 +3249,6 @@ void CHqlExpression::updateFlagsAfterOperands()
         break;
     case NO_AGGREGATE:
         infoFlags2 |= HEF2containsNewDataset;
-        //fall through
-    case no_countfile:
         if (queryChild(0) && (queryChild(0)->getOperator() == no_null))
             infoFlags2 |= HEF2constant;
         // don't percolate aliases beyond their subqueries at the moment.
@@ -4190,7 +4184,6 @@ bool CHqlExpression::isAggregate()
     {
     case NO_AGGREGATE:
     case NO_AGGREGATEGROUP:
-    case no_countfile:
     case no_distribution:
 
 
@@ -4747,7 +4740,6 @@ void CHqlExpression::cacheTablesUsed()
                 addActiveTable(inScopeTables, this);
                 break;
             case NO_AGGREGATE:
-            case no_countfile:
             case no_createset:
                 {
 #ifdef GATHER_HIDDEN_SELECTORS

+ 1 - 1
ecl/hql/hqlexpr.hpp

@@ -582,7 +582,7 @@ enum _node_operator {
         no_temprow,
         no_activerow,                   // no_activerow(dataset) - used to disambiguate rows that are in scope.
         no_catch,
-        no_countfile,
+    no_unused80,
         no_reference,
         no_callback,                    // only used by code generator to backpatch the source
         no_keyedlimit,

+ 0 - 1
ecl/hql/hqlfold.cpp

@@ -4381,7 +4381,6 @@ IHqlExpression * CExprFolderTransformer::doFoldTransformed(IHqlExpression * unfo
             }
             break;
         }
-    case no_countfile:
     case no_within:
     case no_sum:
         {

+ 0 - 5
ecl/hql/hqlthql.cpp

@@ -2817,11 +2817,6 @@ const char * HqltHql::getEclOpString(node_operator op)
         return "DISKREAD";
     case no_compound_indexread:
         return "INDEXREAD";
-    case no_countfile:
-        if (expandProcessed)
-            return ::getOpString(op);
-        else
-            return "COUNT";
     case no_keyedlimit:
         if (expandProcessed)
             return "KEYEDLIMIT";

+ 0 - 2
ecl/hql/hqltrans.cpp

@@ -3145,7 +3145,6 @@ void ScopedTransformer::analyseChildren(IHqlExpression * expr)
         }
         //fallthrough
     case NO_AGGREGATE:
-    case no_countfile:
     case no_buildindex:
     case no_apply:
     case no_distributer:
@@ -3524,7 +3523,6 @@ IHqlExpression * ScopedTransformer::createTransformed(IHqlExpression * expr)
         throwUnexpected();
     case NO_AGGREGATE:
     case no_joined:
-    case no_countfile:
     case no_buildindex:
     case no_apply:
     case no_distribution:

+ 0 - 2
ecl/hql/hqlutil.cpp

@@ -1491,7 +1491,6 @@ unsigned getNumActivityArguments(IHqlExpression * expr)
     case no_newkeyindex:
     case no_table:
     case no_preload:
-    case no_countfile:
     case no_allnodes:
     case no_thisnode:
     case no_keydiff:
@@ -4174,7 +4173,6 @@ void SplitDatasetAttributeTransformer::analyseExpr(IHqlExpression * expr)
         return;
     case NO_AGGREGATE:
     case no_createset:
-    case no_countfile:
     case no_colon:
     case no_globalscope:
     case no_nothor:

+ 0 - 5
ecl/hqlcpp/hqlcpp.cpp

@@ -1575,7 +1575,6 @@ void HqlCppTranslator::cacheOptions()
         DebugOption(options.foldOptimized,"foldOptimized", false),
         DebugOption(options.globalFold,"globalFold", true),
         DebugOption(options.globalOptimize,"globalOptimize", false),
-        DebugOption(options.optimizeThorCounts,"optimizeThorCounts", true),
         DebugOption(options.applyInstantEclTransformations,"applyInstantEclTransformations", false),        // testing option
         DebugOption(options.calculateComplexity,"calculateComplexity", false),
         DebugOption(options.generateLogicalGraph,"generateLogicalGraph", false),
@@ -1626,7 +1625,6 @@ void HqlCppTranslator::cacheOptions()
         DebugOption(options.optimizeDiskSource,"optimizeDiskSource", true),
         DebugOption(options.optimizeIndexSource,"optimizeIndexSource", true),
         DebugOption(options.optimizeChildSource,"optimizeChildSource", false),
-        DebugOption(options.createCountFile,"countFile", true),
         DebugOption(options.reportLocations,"reportLocations", true),
         DebugOption(options.debugGeneratedCpp,"debugGeneratedCpp", false),
         DebugOption(options.addFilesnamesToGraph,"addFilesnamesToGraph", true),
@@ -2774,9 +2772,6 @@ void HqlCppTranslator::buildExpr(BuildCtx & ctx, IHqlExpression * expr, CHqlBoun
     case no_counter:
         doBuildExprCounter(ctx, expr, tgt);
         return;
-    case no_countfile:
-        doBuildExprCountFile(ctx, expr, tgt);
-        return;
     case no_evaluate:
         doBuildExprEvaluate(ctx, expr, tgt);
         return;

+ 0 - 1
ecl/hqlcpp/hqlcpp.hpp

@@ -67,7 +67,6 @@ The following debug options are currently supported by the code generator:
 "foldAssign"             true   - should transforms be constant folded?
 "foldGraph"              false  - fold expressions at the graph level if optimizeGraph is set.
 "foldOptimized"          false  - fold expressions when internal optimizer called.
-"optimizeThorCounts"     true   - convert count(diskfile) into optimized version.
 "peephole"               true   - peephole optimize memcpy/memsets etc.
 "spotCSE"                true   - Look for common sub-expressions in transforms/filters?
 "spotTopN"               true   - Convert choosen(sort()) into a topN activity.

+ 0 - 5
ecl/hqlcpp/hqlcpp.ipp

@@ -559,7 +559,6 @@ struct HqlCppOptions
     bool                evaluateCoLocalRowInvariantInExtract;
     bool                allowInlineSpill;
     bool                spanMultipleCpp;
-    bool                createCountFile;
     bool                optimizeGlobalProjects;
     bool                optimizeResourcedProjects;
     byte                notifyOptimizedProjects;
@@ -626,7 +625,6 @@ struct HqlCppOptions
     bool                foldOptimized;
     bool                globalFold;
     bool                globalOptimize;
-    bool                optimizeThorCounts;
     bool                applyInstantEclTransformations;
     bool                calculateComplexity;
     bool                generateLogicalGraph;
@@ -1003,7 +1001,6 @@ public:
     void noteXpathUsed(const char * xpath);
     void noteXpathUsed(IHqlExpression * expr);
 
-    bool allowCountFile() { return options.createCountFile; }
     HqlCppOptions const & queryOptions() const { return options; }
     ITimeReporter * queryTimeReporter() const { return timeReporter; }
 
@@ -1238,7 +1235,6 @@ public:
     void doBuildExprCompare(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
     void doBuildExprCompareElement(BuildCtx & ctx, node_operator comp_op, IHqlExpression * lhs, IHqlExpression * rhs, CHqlBoundExpr & tgt);
     void doBuildExprCount(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
-    void doBuildExprCountFile(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
     void doBuildExprCounter(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
     void doBuildExprCppBody(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr * tgt);
     void doBuildExprDivide(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt);
@@ -1758,7 +1754,6 @@ protected:
     void processEmbeddedLibraries(HqlExprArray & exprs, HqlExprArray & internalLibraries, bool isLibrary);
     void pickBestEngine(WorkflowArray & array);
     void pickBestEngine(HqlExprArray & exprs);
-    void optimizeThorCounts(HqlExprArray & exprs);
     IHqlExpression * separateLibraries(IHqlExpression * query, HqlExprArray & internalLibraries);
 
     void doBuildSerialize(BuildCtx & ctx, _ATOM name, IHqlExpression * length, CHqlBoundExpr & bound, const char * bufferName);

+ 0 - 2
ecl/hqlcpp/hqlcse.cpp

@@ -364,7 +364,6 @@ bool CseSpotter::containsPotentialCSE(IHqlExpression * expr)
     case no_activetable:
     case no_filepos:
     case no_file_logicalname:
-    case no_countfile:
     case no_matched:
     case no_matchtext:
     case no_matchunicode:
@@ -1245,7 +1244,6 @@ bool TableInvariantTransformer::isInvariant(IHqlExpression * expr)
     case no_workunit_dataset:
     case no_getresult:
     case no_getgraphresult:
-    case no_countfile:
         invariant = true;
         break;
     case no_select:

+ 30 - 130
ecl/hqlcpp/hqlhtcpp.cpp

@@ -466,7 +466,6 @@ public:
 
         switch (op)
         {
-        case no_countfile:
         case no_createset:
             //not really good enough - need to prevent anything within these from being hoisted.
             return;
@@ -1850,49 +1849,44 @@ ActivityInstance::ActivityInstance(HqlCppTranslator & _translator, BuildCtx & ct
     //count index and count disk need to be swapped to the new (much simpler) mechanism
     //until then, they need to be special cased.
     activityLocalisation = GraphNoAccess;
-    if (kind != TAKcountdisk)
-    {
-        containerActivity = translator.queryCurrentActivity(ctx);
-        parentEvalContext.set(translator.queryEvalContext(ctx));
-        parentExtract.set(static_cast<ParentExtract*>(ctx.queryFirstAssociation(AssocExtract)));
-
-        if (parentExtract)
-        {
-            GraphLocalisation localisation = parentExtract->queryLocalisation();
-            activityLocalisation = translator.isAlwaysCoLocal() ? GraphCoLocal : queryActivityLocalisation(dataset);
+    containerActivity = translator.queryCurrentActivity(ctx);
+    parentEvalContext.set(translator.queryEvalContext(ctx));
+    parentExtract.set(static_cast<ParentExtract*>(ctx.queryFirstAssociation(AssocExtract)));
 
-            if (translator.targetThor() && !translator.insideChildQuery(ctx))
-                executedRemotely = true;
-            else
-                executedRemotely = ((activityLocalisation == GraphNonLocal) || (localisation == GraphRemote));
+    if (parentExtract)
+    {
+        GraphLocalisation localisation = parentExtract->queryLocalisation();
+        activityLocalisation = translator.isAlwaysCoLocal() ? GraphCoLocal : queryActivityLocalisation(dataset);
 
-            isCoLocal = containerActivity && !executedRemotely && (localisation != GraphNonLocal) && (activityLocalisation != GraphNoAccess);    // if we supported GraphNonCoLocal the last test would not be needed
+        if (translator.targetThor() && !translator.insideChildQuery(ctx))
+            executedRemotely = true;
+        else
+            executedRemotely = ((activityLocalisation == GraphNonLocal) || (localisation == GraphRemote));
 
-            //if top level activity within a query library then need to force access to the parent extract
-            if (!containerActivity && translator.insideLibrary())
-            {
-                //there should be no colocal activity (container = null)
-                if (activityLocalisation != GraphNoAccess)
-                    activityLocalisation = GraphNonLocal;
-            }
-            if (activityLocalisation == GraphNoAccess)
-                parentExtract.clear();
+        isCoLocal = containerActivity && !executedRemotely && (localisation != GraphNonLocal) && (activityLocalisation != GraphNoAccess);    // if we supported GraphNonCoLocal the last test would not be needed
 
-            if (isCoLocal)
-                colocalMember.setown(createVariable("colocal", makeVoidType()));
-        }
-        else
+        //if top level activity within a query library then need to force access to the parent extract
+        if (!containerActivity && translator.insideLibrary())
         {
-            if (executedRemotely)
-            {
-                GraphLocalisation localisation = queryActivityLocalisation(dataset);
-                if ((kind == TAKsimpleaction) || (localisation == GraphNoAccess))
-                    executedRemotely = false;
-            }
+            //there should be no colocal activity (container = null)
+            if (activityLocalisation != GraphNoAccess)
+                activityLocalisation = GraphNonLocal;
         }
+        if (activityLocalisation == GraphNoAccess)
+            parentExtract.clear();
+
+        if (isCoLocal)
+            colocalMember.setown(createVariable("colocal", makeVoidType()));
     }
     else
-        executedRemotely = !translator.isAlwaysCoLocal();
+    {
+        if (executedRemotely)
+        {
+            GraphLocalisation localisation = queryActivityLocalisation(dataset);
+            if ((kind == TAKsimpleaction) || (localisation == GraphNoAccess))
+                executedRemotely = false;
+        }
+    }
 
     if (!parentExtract && (translator.getTargetClusterType() == RoxieCluster))
         executedRemotely = isNonLocal(dataset);
@@ -2292,9 +2286,6 @@ void ActivityInstance::buildPrefix()
         containerActivity->noteChildActivityLocation(sourceFileSequence);
 
     classctx.set(helperAtom);
-    //Count index functions are referenced from the calling helper => they need to be defined earlier.
-    if (kind == TAKcountdisk)
-        classctx.setNextPriority(BuildCtx::EarlyPrio);
     classGroupStmt = classctx.addGroupPass(sourceFileSequence);
 
     classctx.associate(*this);
@@ -2371,8 +2362,6 @@ void ActivityInstance::buildPrefix()
     //  if (!isMember)
     //      classGroupStmt->setIncomplete(true);
 
-        if (translator.queryOptions().spanMultipleCpp && (kind == TAKcountdisk))
-            moveDefinitionToHeader();
     }
     else
     {
@@ -7348,90 +7337,6 @@ void HqlCppTranslator::doBuildEvalOnce(BuildCtx & ctx, const CHqlBoundTarget * t
 
 //---------------------------------------------------------------------------
 
-class CHqlBoundTargetItem : public CInterface
-{
-public:
-    CHqlBoundTarget     value;
-};
-
-void HqlCppTranslator::doBuildExprCountFile(BuildCtx & ctx, IHqlExpression * _expr, CHqlBoundExpr & tgt)
-{
-    //NB: This is currently only applied to fixed width unfiltered files
-    LinkedHqlExpr expr = _expr;
-    bool needToCreateGraph = !graph;
-    if (needToCreateGraph)
-    {
-        beginGraph(ctx);
-        expr.setown(spotTableInvariantChildren(expr));
-    }
-
-    Owned<ActivityInstance> instance = new ActivityInstance(*this, ctx, TAKcountdisk, expr, "CountFile");
-    buildActivityFramework(instance);
-
-    buildInstancePrefix(instance);
-
-    IHqlExpression * dataset = expr->queryChild(0);
-    IHqlExpression * filename = dataset->queryChild(0);
-    noteResultAccessed(ctx, queryPropertyChild(dataset, sequenceAtom, 0), filename);
-
-    VirtualFieldsInfo info;
-    info.gatherVirtualFields(dataset->queryRecord(), dataset->hasProperty(_noVirtual_Atom), true);
-    OwnedHqlExpr physicalRecord = info.createPhysicalRecord();
-    assertex(isFixedRecordSize(physicalRecord));
-    OwnedHqlExpr physicalDataset = createDataset(no_anon, LINK(physicalRecord));
-
-    //virtual const char * getIndexFileName() = 0;
-    buildFilenameFunction(*instance, instance->startctx, "getFileName", filename, hasDynamicFilename(dataset));
-
-    //virtual IOutputMetaData * queryIndexRecordSize() = 0; //Excluding fpos and sequence
-    buildMetaMember(instance->classctx, physicalDataset, "queryRecordSize");
-
-    StringBuffer flags;
-    if (dataset->hasProperty(optAtom)) flags.append("|TDRoptional");
-    if (!filename->isConstant()) flags.append("|TDXvarfilename");
-    if (hasDynamicFilename(dataset)) flags.append("|TDXdynamicfilename");
-    if (dataset->hasProperty(_spill_Atom)) flags.append("|TDXtemporary");
-    if (dataset->hasProperty(jobTempAtom)) flags.append("|TDXjobtemp");
-    if (dataset->hasProperty(groupedAtom)) flags.append("|TDXgrouped");
-    if (dataset->hasProperty(__compressed__Atom)) flags.append("|TDXcompress");
-    if (dataset->hasProperty(_workflowPersist_Atom)) flags.append("|TDXupdateaccessed");
-
-    if (flags.length())
-        doBuildUnsignedFunction(instance->classctx, "getFlags", flags.str()+1);
-
-    Owned<ABoundActivity> bound = instance->getBoundActivity();
-    addFileDependency(filename, bound);
-
-    buildInstanceSuffix(instance);
-
-    if (targetRoxie())
-        instance->addAttributeBool("_isOpt", dataset->hasProperty(optAtom));
-
-    //**** The following code should be commoned up.  with the code above.  Probably not 
-    //**** worth doing until generalized remote child datasets come along
-    Owned<IWUActivity> activity = wu()->updateActivity(instance->activityId);
-    activity->setKind(TAKcountdisk);
-    activity->setHelper(instance->factoryName);
-
-    // Create the helper, assign any cursors, and then call the count activity.
-    StringBuffer s,name;
-    getUniqueId(name.append("help"));
-    ctx.addQuoted(s.append(instance->className).append(" & ").append(name).append(" = * new ").append(instance->className).append(";"));
-    OwnedHqlExpr helper = createQuoted(name.str(), makeBoolType());
-
-    // Now call the count function - takes ownership of the helper.
-    HqlExprArray args;
-    args.append(*createConstant((__int64)instance->activityId));
-    args.append(*LINK(helper));
-    OwnedHqlExpr call = bindFunctionCall(countRoxieDiskFileAtom, args);
-    buildExpr(ctx, call, tgt);
-    if (needToCreateGraph)
-        endGraph();
-}
-
-
-//---------------------------------------------------------------------------
-
 void HqlCppTranslator::doBuildExprSizeof(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & tgt)
 {
     if (ctx.getMatchExpr(expr, tgt))
@@ -17671,7 +17576,6 @@ static bool needsRealThor(IHqlExpression *expr, unsigned flags)
             switch (child0->getOperator())
             {
             case no_externalcall:
-            case no_countfile:
             case no_constant:
             case no_all:
                 return false;
@@ -17867,10 +17771,6 @@ o extractWorkflow(exprs)
 --- The following aim to work out where each part of the query will be executed, and gather all parts that will be executed in the same place 
 --- together so increase likely hood for cses and reduce connections to the query engines.
 
-o optimizeThorCounts
-  - A first go at transforming count(table) to a no_countdisk
-  !!This should be deleted/changed once we have aggregate source activities
-
 o migrateExprToNaturalLevel [NewScopeMigrateTransformer]
   - Ensure expressions are evaluated at the best level - e.g., counts moved to most appropriate level.
   * global(x) is extracted to a global set/get result pair.  

+ 0 - 8
ecl/hqlcpp/hqliproj.cpp

@@ -980,12 +980,6 @@ void ImplicitProjectTransformer::analyseExpr(IHqlExpression * expr)
                 {
                     switch (op)
                     {
-                    case no_countfile:
-                        //MORE: Is this the best way to handle this?
-                        allowActivity = false;
-                        Parent::analyseExpr(expr);
-                        allowActivity = true;
-                        return;
                     case NO_AGGREGATE:
                     case no_call:
                     case no_externalcall:
@@ -1202,7 +1196,6 @@ void ImplicitProjectTransformer::gatherFieldsUsed(IHqlExpression * expr, Implici
     /*
     The following can be handled using the default mechanism because we're not tracking newtables.
     case NO_AGGREGATE:
-    case no_countfile:
     case no_createset:
     */
     case no_table:
@@ -1572,7 +1565,6 @@ ProjectExprKind ImplicitProjectTransformer::getProjectExprKind(IHqlExpression *
     case no_assignall:
         return NonActivity;
     case NO_AGGREGATE:
-//  case no_countfile:
     case no_createset:
         return SimpleActivity;
     case no_call:

+ 0 - 1
ecl/hqlcpp/hqlresource.cpp

@@ -2226,7 +2226,6 @@ protected:
                 break;
             }
         case no_sizeof:
-        case no_countfile:
         case no_allnodes:
         case no_nohoist:
             return;

+ 0 - 155
ecl/hqlcpp/hqlttcpp.cpp

@@ -662,7 +662,6 @@ IHqlExpression * HqlThorBoundaryTransformer::createTransformed(IHqlExpression *
     case no_getresult:
     case no_left:
     case no_right:
-    case no_countfile:
         return LINK(expr);
     case no_sizeof:
     case no_offsetof:
@@ -811,7 +810,6 @@ YesNoOption HqlThorBoundaryTransformer::calcNormalizeThor(IHqlExpression * expr)
     case no_all:
     case no_self:
     case no_activerow:
-    case no_countfile:          // could evaluate either place
         return OptionMaybe;
     case no_evaluate:
         throwUnexpected();
@@ -1528,7 +1526,6 @@ IHqlExpression * evalNormalizeAggregateExpr(IHqlExpression * selector, IHqlExpre
         throwUnexpectedOp(expr->getOperator());
 
     case no_count:
-    case no_countfile:
     case no_sum:
     case no_max:
     case no_min:
@@ -3484,8 +3481,6 @@ void CompoundSourceTransformer::analyseGatherInfo(IHqlExpression * expr)
     case no_attr:
     case no_attr_expr:
         break;
-    case no_countfile:
-        break;
     case no_keyedlimit:
     case no_compound_diskread:
     case no_compound_disknormalize:
@@ -7006,7 +7001,6 @@ void NewScopeMigrateTransformer::analyseExpr(IHqlExpression * expr)
     case no_createset:
     case NO_ACTION_REQUIRES_GRAPH:
     case no_extractresult:
-    case no_countfile:
     case no_distributer:
     case no_within:
     case no_notwithin:
@@ -7543,121 +7537,6 @@ void removeTrivialGraphs(WorkflowArray & workflow)
     }
 }
 
-
-//---------------------------------------------------------------------------
-
-//Living on borrowed time.  Don't allow count index activity on filters that we can't cope with
-//really the count index activity should be removed asap
-static bool isOkFilter(IHqlExpression * expr)
-{
-    switch (expr->getOperator())
-    {
-    case no_select:
-        return !expr->hasProperty(newAtom);
-    case no_record:
-    case no_constant:
-        return true;
-    case no_createset:
-        return isIndependentOfScope(expr);
-    }
-    ForEachChild(i, expr)
-    {
-        if (!isOkFilter(expr->queryChild(i)))
-            return false;
-    }
-    return true;
-}
-
-static bool isFilteredIndex(IHqlExpression * expr)
-{
-    loop
-    {
-        switch (expr->getOperator())
-        {
-        case no_filter:
-            {
-                ForEachChild(i, expr)
-                {
-                    if (i && !isOkFilter(expr->queryChild(i)))
-                        return false;
-                }
-                break;
-            }
-        case no_distributed:
-        case no_preservemeta:
-        case no_sorted:
-        case no_stepped:
-        case no_grouped:
-        case no_dataset_alias:
-            break;
-        case no_keyindex:
-        case no_newkeyindex:
-            return true;
-        default:
-            return false;
-        }
-        expr = expr->queryChild(0);
-    }
-}
-
-static HqlTransformerInfo thorCountTransformerInfo("ThorCountTransformer");
-ThorCountTransformer::ThorCountTransformer(HqlCppTranslator & _translator, bool _countDiskFuncOk)
-: NewHqlTransformer(thorCountTransformerInfo), translator(_translator)
-{
-    countDiskFuncOk = _countDiskFuncOk && translator.allowCountFile();
-}
-
-IHqlExpression * ThorCountTransformer::createTransformed(IHqlExpression * expr)
-{
-    switch (expr->getOperator())
-    {
-    case no_constant:
-    case no_field:
-        return LINK(expr);
-    case no_select:
-        {
-            OwnedHqlExpr aggregate = convertToSimpleAggregate(expr);
-            if (aggregate && aggregate->getOperator() == no_count)
-            {
-                OwnedHqlExpr transformed = transform(aggregate);
-                if (transformed->getOperator() != no_count)
-                    return transformed.getClear();
-            }
-            break;
-        }
-    case no_count:
-        {
-            IHqlExpression * ds = expr->queryChild(0);
-            if (ds->getOperator() == no_preservemeta)
-                ds = ds->queryChild(0);
-            if (ds->getOperator()==no_table && ds->numChildren()>=3)
-            {
-                if (queryTableMode(ds) == no_flat)
-                {
-                    OwnedHqlExpr record = getSerializedForm(ds->queryRecord());
-                    if (countDiskFuncOk && !isVariableSizeRecord(record) && ds->queryChild(0)->isConstant())
-                    {
-#if 0
-                        OwnedHqlExpr transformed = NewHqlTransformer::createTransformed(expr);
-                        HqlExprArray children;
-                        unwindChildren(children, transformed);
-                        OwnedHqlExpr ret = createValue(no_countfile, transformed->getType(), children);
-                        return createValue(no_evalonce, ret->getType(), LINK(ret));
-#else
-                        OwnedHqlExpr ret = createValue(no_countfile, expr->getType(), LINK(ds));
-                        return createValue(no_evalonce, ret->getType(), LINK(ret));
-#endif
-                    }
-                }
-            }
-        }
-        break;
-    }
-
-    return NewHqlTransformer::createTransformed(expr);
-}
-
-
 //==============================================================================================================
 
 class FilterCloner
@@ -8110,7 +7989,6 @@ IHqlExpression * NestedSelectorNormalizer::createTransformed(IHqlExpression * ex
         {
         case NO_AGGREGATE:
         case no_joined:
-        case no_countfile:
         case no_buildindex:
         case no_apply:
         case no_distribution:
@@ -8986,7 +8864,6 @@ IHqlExpression * HqlScopeTagger::createTransformed(IHqlExpression * expr)
     case no_select:
         return transformSelect(expr);
     case NO_AGGREGATE:
-    case no_countfile:
     case no_createset:
         {
             beginTableScope();
@@ -11929,26 +11806,6 @@ void HqlCppTranslator::substituteClusterSize(HqlExprArray & exprs)
     replaceArray(exprs, transformed);
 }
 
-void HqlCppTranslator::optimizeThorCounts(HqlExprArray & exprs)
-{
-    if (allowCountFile())
-    {
-        ThorCountTransformer countTransformer(*this, true);
-        HqlExprArray transformed;
-        ForEachItemIn(idx, exprs)
-        {
-            IHqlExpression & cur = exprs.item(idx);
-            ITypeInfo * type = cur.queryType();
-            if (type && (type->isScalar() || type->getTypeCode()==type_void))
-                transformed.append(*countTransformer.transformRoot(&cur));
-            else
-                transformed.append(OLINK(cur));
-        }
-        replaceArray(exprs, transformed);
-        traceExpressions("optimize", exprs);
-    }
-}
-
 IHqlExpression * HqlCppTranslator::separateLibraries(IHqlExpression * query, HqlExprArray & internalLibraries)
 {
     HqlExprArray exprs;
@@ -12098,18 +11955,6 @@ bool HqlCppTranslator::transformGraphForGeneration(IHqlExpression * query, Workf
     }
 
     checkNormalized(workflow);
-    // Do this later so that counts of persistent results are optimized.
-    if (options.optimizeThorCounts)
-    {
-        unsigned startTime = msTick();
-        ForEachItemIn(idx, workflow)
-        {
-            optimizeThorCounts(workflow.item(idx).queryExprs());
-        }
-        DEBUG_TIMER("EclServer: tree transform: optimize thor counts", msTick()-startTime);
-    }
-
-    checkNormalized(workflow);
     //sort(x)[n] -> topn(x, n)[]n, count(x)>n -> count(choosen(x,n+1)) > n and possibly others
     {
         unsigned startTime = msTick();