merge asterix_lsm_stabilization into asterix_lsm_stabilization_managix r1473:1496

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_lsm_stabilization_managix@1497 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
index f0880ec..efe01a5 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/algebra/operators/physical/BTreeSearchPOperator.java
@@ -47,9 +47,11 @@
     private final List<LogicalVariable> highKeyVarList;
     private final boolean isPrimaryIndex;
     private final boolean isEqCondition;
+    private Object implConfig;
 
     public BTreeSearchPOperator(IDataSourceIndex<String, AqlSourceId> idx, boolean requiresBroadcast,
-            boolean isPrimaryIndex, boolean isEqCondition, List<LogicalVariable> lowKeyVarList, List<LogicalVariable> highKeyVarList) {
+            boolean isPrimaryIndex, boolean isEqCondition, List<LogicalVariable> lowKeyVarList,
+            List<LogicalVariable> highKeyVarList) {
         super(idx, requiresBroadcast);
         this.isPrimaryIndex = isPrimaryIndex;
         this.isEqCondition = isEqCondition;
@@ -57,6 +59,14 @@
         this.highKeyVarList = highKeyVarList;
     }
 
+    public void setImplConfig(Object implConfig) {
+        this.implConfig = implConfig;
+    }
+
+    public Object getImplConfig() {
+        return implConfig;
+    }
+
     @Override
     public PhysicalOperatorTag getOperatorTag() {
         return PhysicalOperatorTag.BTREE_SEARCH;
@@ -89,16 +99,16 @@
             VariableUtilities.getLiveVariables(unnestMap, outputVars);
         }
         Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> btreeSearch = metadataProvider.buildBtreeRuntime(
-                builder.getJobSpec(), outputVars, opSchema, typeEnv,  context, jobGenParams.getRetainInput(),
-                dataset, jobGenParams.getIndexName(), lowKeyIndexes, highKeyIndexes, jobGenParams.isLowKeyInclusive(),
-                jobGenParams.isHighKeyInclusive());
+                builder.getJobSpec(), outputVars, opSchema, typeEnv, context, jobGenParams.getRetainInput(), dataset,
+                jobGenParams.getIndexName(), lowKeyIndexes, highKeyIndexes, jobGenParams.isLowKeyInclusive(),
+                jobGenParams.isHighKeyInclusive(), implConfig);
         builder.contributeHyracksOperator(unnestMap, btreeSearch.first);
         builder.contributeAlgebricksPartitionConstraint(btreeSearch.first, btreeSearch.second);
 
         ILogicalOperator srcExchange = unnestMap.getInputs().get(0).getValue();
         builder.contributeGraphEdge(srcExchange, 0, unnestMap, 0);
     }
-    
+
     public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op,
             IPhysicalPropertiesVector reqdByParent) {
         if (requiresBroadcast) {
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
index 053028a..3f434b7 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/base/RuleCollections.java
@@ -30,6 +30,7 @@
 import edu.uci.ics.asterix.optimizer.rules.InlineUnnestFunctionRule;
 import edu.uci.ics.asterix.optimizer.rules.IntroduceDynamicTypeCastRule;
 import edu.uci.ics.asterix.optimizer.rules.IntroduceEnforcedListTypeRule;
+import edu.uci.ics.asterix.optimizer.rules.IntroduceInstantLockSearchCallbackRule;
 import edu.uci.ics.asterix.optimizer.rules.IntroduceSecondaryIndexInsertDeleteRule;
 import edu.uci.ics.asterix.optimizer.rules.IntroduceStaticTypeCastRule;
 import edu.uci.ics.asterix.optimizer.rules.LoadRecordFieldsRule;
@@ -58,6 +59,7 @@
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ConsolidateAssignsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ConsolidateSelectsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.EliminateSubplanRule;
+import edu.uci.ics.hyracks.algebricks.rewriter.rules.EnforceOrderByAfterSubplan;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.EnforceStructuralPropertiesRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonExpressionsRule;
 import edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule;
@@ -106,6 +108,7 @@
     public final static List<IAlgebraicRewriteRule> buildNormalizationRuleCollection() {
         List<IAlgebraicRewriteRule> normalization = new LinkedList<IAlgebraicRewriteRule>();
         normalization.add(new EliminateSubplanRule());
+        normalization.add(new EnforceOrderByAfterSubplan());
         normalization.add(new PushAggFuncIntoStandaloneAggregateRule());
         normalization.add(new BreakSelectIntoConjunctsRule());
         normalization.add(new ExtractGbyExpressionsRule());
@@ -229,6 +232,7 @@
         physicalRewritesAllLevels.add(new ReplaceSinkOpWithCommitOpRule());
         physicalRewritesAllLevels.add(new SetAlgebricksPhysicalOperatorsRule());
         physicalRewritesAllLevels.add(new SetAsterixPhysicalOperatorsRule());
+        physicalRewritesAllLevels.add(new IntroduceInstantLockSearchCallbackRule());
         physicalRewritesAllLevels.add(new EnforceStructuralPropertiesRule());
         physicalRewritesAllLevels.add(new IntroHashPartitionMergeExchange());
         physicalRewritesAllLevels.add(new SetClosedRecordConstructorsRule());
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceInstantLockSearchCallbackRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceInstantLockSearchCallbackRule.java
new file mode 100644
index 0000000..62cca6c
--- /dev/null
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceInstantLockSearchCallbackRule.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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.
+ */
+package edu.uci.ics.asterix.optimizer.rules;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.lang3.mutable.Mutable;
+
+import edu.uci.ics.asterix.algebra.operators.CommitOperator;
+import edu.uci.ics.asterix.algebra.operators.physical.BTreeSearchPOperator;
+import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
+import edu.uci.ics.asterix.metadata.declared.AqlMetadataImplConfig;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.optimizer.rules.am.AccessMethodJobGenParams;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.IPhysicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.DataSourceScanPOperator;
+import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+
+public class IntroduceInstantLockSearchCallbackRule implements IAlgebraicRewriteRule {
+
+    @Override
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
+        return false;
+    }
+
+    private void extractDataSourcesInfo(AbstractLogicalOperator op,
+            Map<String, Triple<Integer, LogicalOperatorTag, IPhysicalOperator>> dataSourcesMap) {
+
+        for (int i = 0; i < op.getInputs().size(); ++i) {
+            AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
+
+            if (descendantOp.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
+                UnnestMapOperator unnestMapOp = (UnnestMapOperator) descendantOp;
+                ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
+                if (unnestExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+                    AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) unnestExpr;
+                    FunctionIdentifier fid = f.getFunctionIdentifier();
+                    if (!fid.equals(AsterixBuiltinFunctions.INDEX_SEARCH)) {
+                        throw new IllegalStateException();
+                    }
+                    AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
+                    jobGenParams.readFromFuncArgs(f.getArguments());
+                    boolean isPrimaryIndex = jobGenParams.isPrimaryIndex();
+                    String indexName = jobGenParams.getIndexName();
+                    if (isPrimaryIndex) {
+                        if (dataSourcesMap.containsKey(indexName)) {
+                            ++(dataSourcesMap.get(indexName).first);
+                        } else {
+                            dataSourcesMap.put(indexName, new Triple<Integer, LogicalOperatorTag, IPhysicalOperator>(1,
+                                    LogicalOperatorTag.UNNEST_MAP, unnestMapOp.getPhysicalOperator()));
+                        }
+                    }
+                }
+            } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
+                DataSourceScanOperator dataSourceScanOp = (DataSourceScanOperator) descendantOp;
+                String datasetName = ((AqlDataSource) dataSourceScanOp.getDataSource()).getDataset().getDatasetName();
+                if (dataSourcesMap.containsKey(datasetName)) {
+                    ++(dataSourcesMap.get(datasetName).first);
+                } else {
+                    dataSourcesMap.put(datasetName, new Triple<Integer, LogicalOperatorTag, IPhysicalOperator>(1,
+                            LogicalOperatorTag.DATASOURCESCAN, dataSourceScanOp.getPhysicalOperator()));
+                }
+            }
+            extractDataSourcesInfo(descendantOp, dataSourcesMap);
+        }
+
+    }
+
+    private boolean checkIfRuleIsApplicable(AbstractLogicalOperator op) {
+        if (op.getPhysicalOperator() == null) {
+            return false;
+        }
+        if (op.getOperatorTag() == LogicalOperatorTag.EXTENSION_OPERATOR) {
+            ExtensionOperator extensionOp = (ExtensionOperator) op;
+            if (extensionOp.getDelegate() instanceof CommitOperator) {
+                return true;
+            }
+        }
+        if (op.getOperatorTag() == LogicalOperatorTag.DISTRIBUTE_RESULT
+                || op.getOperatorTag() == LogicalOperatorTag.WRITE_RESULT) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+
+        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
+
+        if (!checkIfRuleIsApplicable(op)) {
+            return false;
+        }
+        Map<String, Triple<Integer, LogicalOperatorTag, IPhysicalOperator>> dataSourcesMap = new HashMap<String, Triple<Integer, LogicalOperatorTag, IPhysicalOperator>>();
+        extractDataSourcesInfo(op, dataSourcesMap);
+
+        boolean introducedInstantLock = false;
+
+        Iterator<Map.Entry<String, Triple<Integer, LogicalOperatorTag, IPhysicalOperator>>> it = dataSourcesMap
+                .entrySet().iterator();
+        while (it.hasNext()) {
+            Entry<String, Triple<Integer, LogicalOperatorTag, IPhysicalOperator>> entry = it.next();
+            Triple<Integer, LogicalOperatorTag, IPhysicalOperator> triple = entry.getValue();
+            if (triple.first == 1) {
+                AqlMetadataImplConfig aqlMetadataImplConfig = new AqlMetadataImplConfig(true);
+                if (triple.second == LogicalOperatorTag.UNNEST_MAP) {
+                    BTreeSearchPOperator pOperator = (BTreeSearchPOperator) triple.third;
+                    pOperator.setImplConfig(aqlMetadataImplConfig);
+                    introducedInstantLock = true;
+                } else {
+                    DataSourceScanPOperator pOperator = (DataSourceScanPOperator) triple.third;
+                    pOperator.setImplConfig(aqlMetadataImplConfig);
+                    introducedInstantLock = true;
+                }
+            }
+
+        }
+        return introducedInstantLock;
+    }
+}
\ No newline at end of file
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
index fed591d..c99e4bc 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
@@ -64,27 +64,34 @@
         }
 
         FunctionIdentifier fid = null;
-        AbstractLogicalOperator op2 = op1;
+        /** op2 is the assign operator which extract primary keys from the record variable */
+        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op1.getInputs().get(0).getValue();
         List<LogicalVariable> recordVar = new ArrayList<LogicalVariable>();
-        // Find assign op that creates record to be inserted/deleted.
-        while (fid != AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR) {
-            if (op2.getInputs().size() == 0) {
-                return false;
+        VariableUtilities.getUsedVariables(op2, recordVar);
+        if (recordVar.size() == 0) {
+            /**
+             * For the case primary key-assignment expressions are constant expressions,
+             * find assign op that creates record to be inserted/deleted.
+             */
+            while (fid != AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR) {
+                if (op2.getInputs().size() == 0) {
+                    return false;
+                }
+                op2 = (AbstractLogicalOperator) op2.getInputs().get(0).getValue();
+                if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
+                    continue;
+                }
+                AssignOperator assignOp = (AssignOperator) op2;
+                ILogicalExpression assignExpr = assignOp.getExpressions().get(0).getValue();
+                if (assignExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+                    ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) assignOp.getExpressions()
+                            .get(0).getValue();
+                    fid = funcExpr.getFunctionIdentifier();
+                }
             }
-            op2 = (AbstractLogicalOperator) op2.getInputs().get(0).getValue();
-            if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-                continue;
-            }
-            AssignOperator assignOp = (AssignOperator) op2;
-            ILogicalExpression assignExpr = assignOp.getExpressions().get(0).getValue();
-            if (assignExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
-                ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) assignOp.getExpressions().get(0)
-                        .getValue();
-                fid = funcExpr.getFunctionIdentifier();
-            }
+            AssignOperator assignOp2 = (AssignOperator) op2;
+            recordVar.addAll(assignOp2.getVariables());
         }
-        AssignOperator assignOp2 = (AssignOperator) op2;
-        recordVar.addAll(assignOp2.getVariables());
         InsertDeleteOperator insertOp = (InsertDeleteOperator) op1;
         AqlDataSource datasetSource = (AqlDataSource) insertOp.getDataSource();
         AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
index e3a9e91..84e152a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodJobGenParams.java
@@ -59,7 +59,6 @@
         retainInput = AccessMethodUtils.getBooleanConstant(funcArgs.get(4));
         requiresBroadcast = AccessMethodUtils.getBooleanConstant(funcArgs.get(5));
         isPrimaryIndex = datasetName.equals(indexName);
-        isPrimaryIndex = datasetName.equals(indexName);
     }
 
     public String getIndexName() {
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index c8b0321..976ec7c 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -1370,7 +1370,6 @@
                 }
                 switch (pdf) {
                     case HTML:
-                        out.println("<h3>Result:</h3>");
                         out.println("<pre>");
                         ResultUtils.prettyPrintHTML(out, response);
                         out.println("</pre>");
diff --git a/asterix-app/src/main/resources/webui/querytemplate.html b/asterix-app/src/main/resources/webui/querytemplate.html
index 23887c40..95323bb 100644
--- a/asterix-app/src/main/resources/webui/querytemplate.html
+++ b/asterix-app/src/main/resources/webui/querytemplate.html
@@ -5,7 +5,6 @@
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link href='http://fonts.googleapis.com/css?family=Bitter|PT+Sans+Caption|Open+Sans' rel='stylesheet' type='text/css'>
 <script src="/webui/static/js/jquery.min.js"></script>
-<script src="/webui/static/js/jquery.autosize-min.js"></script>
 
 <link href="/webui/static/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
 <link href="/webui/static/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css" />
@@ -16,9 +15,8 @@
 
 <script type="text/javascript">
 $(document).ready(function(){
-   $('textarea').autosize();
-
    $("form#queryform").submit(function() {
+     $('#output-message').html("");
      $.post("/", $("form#queryform").serialize(), function(data) {
        $('#output-message').html(data);
      });
@@ -59,28 +57,18 @@
           <form id="queryform" class="form-horizontal" method="post">
             <div>
               <label class="query">Query</label>
-              <textarea rows="20" name="query" class="query" value="%s" placeholder="Type your AQL query ..."></textarea>
+              <textarea rows="10" name="query" class="query" value="%s" placeholder="Type your AQL query ..."></textarea>
             </div>
             <div>
-              <div class="left">
-                <label class="checkbox"><input type="checkbox" name="print-expr-tree" value="true" /> Print parsed expressions</label>
-              </div>
-              <div class="right">
-                <label class="checkbox"><input type="checkbox" name="print-rewritten-expr-tree" value="true" /> Print rewritten expressions</label>
-              </div>
+              <label class="checkbox"><input type="checkbox" checked="checked" name="print-expr-tree" value="true" /> Print parsed expressions</label>
+              <label class="checkbox"><input type="checkbox" checked="checked" name="print-rewritten-expr-tree" value="true" /> Print rewritten expressions</label>
             </div>
             <div>
-              <div class="left">
-                <label class="checkbox"><input type="checkbox" name="print-logical-plan" value="true" /> Print logical plan</label>
-              </div>
-              <div class="right">
-                <label class="checkbox"><input type="checkbox" name="print-optimized-logical-plan" value="true" /> Print optimized logical plan</label>
-              </div>
+              <label class="checkbox"><input type="checkbox" checked="checked" name="print-logical-plan" value="true" /> Print logical plan</label>
+              <label class="checkbox"><input type="checkbox" checked="checked" name="print-optimized-logical-plan" value="true" /> Print optimized logical plan</label>
             </div>
             <div>
-              <div class="left">
-                <label class="checkbox"><input type="checkbox" name="print-job" value="true" /> Print hyracks job</label>
-              </div>
+              <label class="checkbox"><input type="checkbox" checked="checked" name="print-job" value="true" /> Print hyracks job</label>
             </div>
             <button type="submit" class="btn btn-danger">Execute</button>
           </form>
diff --git a/asterix-app/src/main/resources/webui/static/css/style.css b/asterix-app/src/main/resources/webui/static/css/style.css
index 673cd07..10f28dd 100644
--- a/asterix-app/src/main/resources/webui/static/css/style.css
+++ b/asterix-app/src/main/resources/webui/static/css/style.css
@@ -50,16 +50,11 @@
     font-family: bitter, helvetica;
     width: 100%;
     padding: 10px;
-    color: #999;
+    color: #333;
     resize: none;
     border: 10px solid #eee;
 }
 
-textarea.query:focus {
-    outline: none;
-    color: #333;
-}
-
 label {
     padding-top: 10px;
 }
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index 2602707..1555549 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -51,11 +51,15 @@
         int num = 0;
         int chunkCounter = 0;
         int recordCounter = 0;
-        try {
 
+        try {
             while ((lineExpected = readerExpected.readLine()) != null) {
-                if (jArray.length() <= 0) {
-                    throw new Exception("No results returned for query.");
+                // Skip the blank line in the expected file.
+                if (lineExpected.isEmpty()) {
+                    continue;
+                }
+                if (jArray.length() <= chunkCounter) {
+                    throw new Exception("No more results available.");
                 }
                 JSONArray resultArray = jArray.getJSONArray(chunkCounter);
 
@@ -73,19 +77,11 @@
                 if (recordCounter >= resultArray.length()) {
                     chunkCounter++;
                     recordCounter = 0;
-                    if (chunkCounter >= jArray.length()) {
-                        break;
-                    }
                 }
             }
-
-            while ((lineExpected = readerExpected.readLine()) != null) {
-                // TODO(khurram): Print out the remaining expected file contents
-            }
         } finally {
             readerExpected.close();
         }
-
     }
 
     private static boolean equalStrings(String s1, String s2) {
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.1.ddl.aql
new file mode 100644
index 0000000..0f548a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.1.ddl.aql
@@ -0,0 +1,23 @@
+/*
+ * Description  : This test case is to verify the fix for issue288
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=288
+ * Expected Res : Success
+ * Date         : 3th April 2013
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type LineIDType as closed {
+  l_orderkey: int32, 
+  l_linenumber: int32, 
+  l_suppkey: int32
+}
+
+create dataset LineID(LineIDType)
+  primary key l_orderkey, l_linenumber;
+
+create dataset LineID2(LineIDType)
+  primary key l_orderkey, l_linenumber;
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.2.update.aql
new file mode 100644
index 0000000..181085f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.2.update.aql
@@ -0,0 +1,25 @@
+/*
+ * Description  : This test case is to verify the fix for issue288
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=288
+ * Expected Res : Success
+ * Date         : 3th April 2013
+ */
+
+use dataverse test;
+
+load dataset LineID 
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/tpch0.001/lineitem_0.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+
+insert into dataset LineID (
+let $x:=1
+let $y:=2
+let $z:=3
+return {
+	"l_orderkey": $x,
+	"l_linenumber": $y,
+	"l_suppkey": $z
+}
+);
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.3.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.3.ddl.aql
new file mode 100644
index 0000000..c3a2bef
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.3.ddl.aql
@@ -0,0 +1,11 @@
+/*
+ * Description  : This test case is to verify the fix for issue288
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=288
+ * Expected Res : Success
+ * Date         : 3th April 2013
+ */
+use dataverse test;
+
+create index idx_LineID_1 on LineID(l_linenumber);
+create index idx_LineID_2 on LineID2(l_linenumber);
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.4.update.aql b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.4.update.aql
new file mode 100644
index 0000000..2ae4ba0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.4.update.aql
@@ -0,0 +1,25 @@
+/*
+ * Description  : This test case is to verify the fix for issue288
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=288
+ * Expected Res : Success
+ * Date         : 3th April 2013
+ */
+ 
+use dataverse test;
+
+insert into dataset LineID2
+(
+	for $r in dataset('LineID')
+	return $r
+);
+
+// If we replace the insert statement with this, it will work
+/* insert into dataset LineID2
+(
+	for $r in dataset('LineID')
+	return {
+"l_orderkey": $r.l_orderkey, 
+"l_linenumber": $r.l_linenumber, 
+"l_suppkey": $r.l_suppkey}
+);
+*/ 
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.5.query.aql b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.5.query.aql
new file mode 100644
index 0000000..a1196bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/query-issue288/query-issue288.5.query.aql
@@ -0,0 +1,12 @@
+/*
+ * Description  : This test case is to verify the fix for issue288
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=288
+ * Expected Res : Success
+ * Date         : 3th April 2013
+ */
+ 
+use dataverse test;
+   
+for $c in dataset('LineID2')
+where $c.l_linenumber=2
+return $c 
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.1.ddl.aql
new file mode 100644
index 0000000..230315e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.1.ddl.aql
@@ -0,0 +1,31 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title, and given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type DBLPType as closed {
+  id: int32, 
+  dblpid: string,
+  title: string,
+  authors: string,
+  misc: string
+}
+
+create type CSXType as closed {
+  id: int32, 
+  csxid: string,
+  title: string,
+  authors: string,
+  misc: string
+}
+
+create dataset DBLP(DBLPType) primary key id;
+create dataset CSX(CSXType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.2.update.aql
new file mode 100644
index 0000000..923f6e4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.2.update.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title, and given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+load dataset DBLP 
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/pub-small/dblp-small-id.txt"),("format"="delimited-text"),("delimiter"=":"));
+
+load dataset CSX
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/pub-small/csx-small-id.txt"),("format"="delimited-text"),("delimiter"=":"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.3.query.aql
new file mode 100644
index 0000000..edcb9b2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285-2/query_issue285-2.3.query.aql
@@ -0,0 +1,25 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title, and given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ *
+ *					TODO(@Sattam): given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ *					
+ *					regression test 2 for issue 285--having an order by and limit for the outer loop relation
+ *
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+for $a in dataset('DBLP')
+order by $a.id
+limit 10
+return {
+"aid": $a.id,
+"bids": for $b in dataset('CSX')
+where $a.authors = $b.authors
+order by $b.id
+return $b.id
+}
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.1.ddl.aql
new file mode 100644
index 0000000..a04adc8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.1.ddl.aql
@@ -0,0 +1,35 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title.
+ *					
+ *					TODO(@Sattam): given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ *					
+ *					regression test for issue 285
+ * Success        : Yes
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+
+use dataverse test;
+
+create type DBLPType as closed {
+  id: int32, 
+  dblpid: string,
+  title: string,
+  authors: string,
+  misc: string
+}
+
+create type CSXType as closed {
+  id: int32, 
+  csxid: string,
+  title: string,
+  authors: string,
+  misc: string
+}
+
+create dataset DBLP(DBLPType) primary key id;
+create dataset CSX(CSXType) primary key id;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.2.update.aql
new file mode 100644
index 0000000..923f6e4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.2.update.aql
@@ -0,0 +1,17 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title, and given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+load dataset DBLP 
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/pub-small/dblp-small-id.txt"),("format"="delimited-text"),("delimiter"=":"));
+
+load dataset CSX
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/pub-small/csx-small-id.txt"),("format"="delimited-text"),("delimiter"=":"));
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.3.query.aql
new file mode 100644
index 0000000..f5ff114
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/leftouterjoin/query_issue285/query_issue285.3.query.aql
@@ -0,0 +1,23 @@
+/*
+ * Description    : Left-outer joins two datasets, DBLP and CSX, based on their title.
+ *                  DBLP has a secondary btree index on title, and given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ *
+ *					TODO(@Sattam): given the 'indexnl' hint 
+ *                  we expect the join to be transformed into an indexed nested-loop join.
+ *					
+ *					regression test for issue 285--having an order by for the outer loop relation
+ * Success        : Yes
+ */
+
+use dataverse test;
+
+for $a in dataset('DBLP')
+order by $a.id
+return {
+"aid": $a.id,
+"bids": for $b in dataset('CSX')
+where $a.authors = $b.authors
+order by $b.id
+return $b.id
+}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20/round-half-to-even20.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20/round-half-to-even20.3.query.aql
index 462de75..d14fb40 100644
--- a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20/round-half-to-even20.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20/round-half-to-even20.3.query.aql
@@ -8,5 +8,5 @@
 let $c5 := int16("0")
 let $c6 := int32("0")
 let $c7 := int64("0")
-return {"f0": numeric-round-half-to-even2($c0,2), "f1": numeric-round-half-to-even2($c1,2),"f2": numeric-round-half-to-even2($c2,2), "f3": numeric-round-half-to-even2($c3,2),
-	"f4": numeric-round-half-to-even2($c4,2),"f5": numeric-round-half-to-even2($c5,2) ,"f6": numeric-round-half-to-even2($c6,2), "f7": numeric-round-half-to-even2($c7,2)}
+return {"f0": numeric-round-half-to-even($c0,2), "f1": numeric-round-half-to-even($c1,2),"f2": numeric-round-half-to-even($c2,2), "f3": numeric-round-half-to-even($c3,2),
+	"f4": numeric-round-half-to-even($c4,2),"f5": numeric-round-half-to-even($c5,2) ,"f6": numeric-round-half-to-even($c6,2), "f7": numeric-round-half-to-even($c7,2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21/round-half-to-even21.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21/round-half-to-even21.3.query.aql
index 6847ed7..958a63d 100644
--- a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21/round-half-to-even21.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21/round-half-to-even21.3.query.aql
@@ -8,5 +8,5 @@
 let $c5 := int16("22")
 let $c6 := int32("23")
 let $c7 := int64("27")
-return {"f0": numeric-round-half-to-even2($c0,2), "f1": numeric-round-half-to-even2($c1,2),"f2": numeric-round-half-to-even2($c2,2), "f3": numeric-round-half-to-even2($c3,2),
-	"f4": numeric-round-half-to-even2($c4,2),"f5": numeric-round-half-to-even2($c5,2) ,"f6": numeric-round-half-to-even2($c6,2), "f7": numeric-round-half-to-even2($c7,2)}
+return {"f0": numeric-round-half-to-even($c0,2), "f1": numeric-round-half-to-even($c1,2),"f2": numeric-round-half-to-even($c2,2), "f3": numeric-round-half-to-even($c3,2),
+	"f4": numeric-round-half-to-even($c4,2),"f5": numeric-round-half-to-even($c5,2) ,"f6": numeric-round-half-to-even($c6,2), "f7": numeric-round-half-to-even($c7,2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22/round-half-to-even22.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22/round-half-to-even22.3.query.aql
index 9338f10..e9aa46c 100644
--- a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22/round-half-to-even22.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22/round-half-to-even22.3.query.aql
@@ -7,5 +7,5 @@
 let $c4 := float("-INF")
 let $c5 := float("-0.0")
 let $c6 := float("0.0")
-return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,3),
-        "d3": numeric-round-half-to-even2($c3,4),"d4": numeric-round-half-to-even2($c4,5),"d5": numeric-round-half-to-even2($c5,6), "d6": numeric-round-half-to-even2($c6,0)}
+return {"d0": numeric-round-half-to-even($c0,2), "d1": numeric-round-half-to-even($c1,2),"d2": numeric-round-half-to-even($c2,3),
+        "d3": numeric-round-half-to-even($c3,4),"d4": numeric-round-half-to-even($c4,5),"d5": numeric-round-half-to-even($c5,6), "d6": numeric-round-half-to-even($c6,0)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23/round-half-to-even23.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23/round-half-to-even23.3.query.aql
index c7260ab..8fe4615 100644
--- a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23/round-half-to-even23.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23/round-half-to-even23.3.query.aql
@@ -7,5 +7,5 @@
 let $c4 := double("-INF")
 let $c5 := double("-0.0")
 let $c6 := double("0.0")
-return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,3),
-        "d3": numeric-round-half-to-even2($c3,4),"d4": numeric-round-half-to-even2($c4,5),"d5": numeric-round-half-to-even2($c5,6), "d6": numeric-round-half-to-even2($c6,0)}
+return {"d0": numeric-round-half-to-even($c0,2), "d1": numeric-round-half-to-even($c1,2),"d2": numeric-round-half-to-even($c2,3),
+        "d3": numeric-round-half-to-even($c3,4),"d4": numeric-round-half-to-even($c4,5),"d5": numeric-round-half-to-even($c5,6), "d6": numeric-round-half-to-even($c6,0)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24/round-half-to-even24.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24/round-half-to-even24.3.query.aql
index 8a2d135..9b3095f 100644
--- a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24/round-half-to-even24.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24/round-half-to-even24.3.query.aql
@@ -5,5 +5,5 @@
 let $c2 := double("3.567812E+3")
 let $c3 := double("4.7564E-3")
 let $c4 := double("35612.25")
-return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,2),
-        "d3": numeric-round-half-to-even2($c3,2),"d4": numeric-round-half-to-even2($c4,-2)}
+return {"d0": numeric-round-half-to-even($c0,2), "d1": numeric-round-half-to-even($c1,2),"d2": numeric-round-half-to-even($c2,2),
+        "d3": numeric-round-half-to-even($c3,2),"d4": numeric-round-half-to-even($c4,-2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches21/matches21.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches21/matches21.3.query.aql
index dff183b..e874fcb 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/matches21/matches21.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches21/matches21.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := matches2("abracadabra","Bra","")
+let $c1 := matches("abracadabra","Bra","")
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches22/matches22.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches22/matches22.3.query.aql
index ac16ae8..7b5c9c0 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/matches22/matches22.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches22/matches22.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := matches2("abracadabra","Bra","i")
+let $c1 := matches("abracadabra","Bra","i")
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches23/matches23.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches23/matches23.3.query.aql
index 8289897..9d81aae 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/matches23/matches23.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches23/matches23.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := matches2("helloworld","hello world","x")
+let $c1 := matches("helloworld","hello world","x")
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matchesnull/matchesnull.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/matchesnull/matchesnull.3.query.aql
index 5f01b89..6ce6a77 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/matchesnull/matchesnull.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matchesnull/matchesnull.3.query.aql
@@ -3,7 +3,7 @@
 let $c1 := matches("helloworld",null)
 let $c2 := matches("",null)
 let $c3 := matches(null,null)
-let $c4 := matches2("helloworld",null, "")
-let $c5 := matches2("",null, "i")
-let $c6 := matches2(null,null, null)
+let $c4 := matches("helloworld",null, "")
+let $c5 := matches("",null, "i")
+let $c6 := matches(null,null, null)
 return {"result1": $c1, "result2": $c2, "result3": $c3, "result4": $c4, "result5": $c5, "result6": $c6}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql
index a814373..3552126 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace21/replace21.3.query.aql
@@ -1,6 +1,6 @@
 use dataverse test;
 
-let $c1 := replace2("abracadabra","Bra", "kkk" , "")
-let $c2 := replace2("abracadabra","Bra", "kkk" ,"i")
-let $c3 := replace2("helloworld","hello world", "kkk" , "x")
+let $c1 := replace("abracadabra","Bra", "kkk" , "")
+let $c2 := replace("abracadabra","Bra", "kkk" ,"i")
+let $c3 := replace("helloworld","hello world", "kkk" , "x")
 return {"result1": $c1,"result2": $c2,"result3": $c3}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql
index 1dcbe08..df67481 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace22/replace22.3.query.aql
@@ -1,11 +1,11 @@
 use dataverse test;
 
-let $c1 := replace2("abracadabra","", null , null)
-let $c2 := replace2("abracadabra","bra", "XXX" ,"")
-let $c3 := replace2(null,"hello world", "XxXx" , "x")
-let $c4 := replace2("abracadabra","bra", "XXX" ,null)
-let $c5 := replace2("abracadabra",null, "XXX" ,null)
-let $c6 := replace2("abracadabra","Bra", null ,"i")
-let $c7 := replace2("abracadabra","Bra", "" ,"i")
-let $c8 := replace2("abracadabra","", "XXX" ,"")
+let $c1 := replace("abracadabra","", null , null)
+let $c2 := replace("abracadabra","bra", "XXX" ,"")
+let $c3 := replace(null,"hello world", "XxXx" , "x")
+let $c4 := replace("abracadabra","bra", "XXX" ,null)
+let $c5 := replace("abracadabra",null, "XXX" ,null)
+let $c6 := replace("abracadabra","Bra", null ,"i")
+let $c7 := replace("abracadabra","Bra", "" ,"i")
+let $c8 := replace("abracadabra","", "XXX" ,"")
 return {"result1": $c1,"result2": $c2,"result3": $c3,"result4": $c4,"result5": $c5,"result6": $c6,"result7": $c7,"result8": $c8}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr01/substr01.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr01/substr01.3.query.aql
index 422f87c..e7b638c 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr01/substr01.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr01/substr01.3.query.aql
@@ -6,23 +6,23 @@
  */
 
 let $str1:="Hello World"
-let $str2:=substring2($str1,10)
+let $str2:=substring($str1,10)
 
 let $str3:="This is a test string"
-let $str4:=substring2($str3,21)
+let $str4:=substring($str3,21)
 
 let $str5:="This is a test string"
-let $str6:=substring2($str5,22)
+let $str6:=substring($str5,22)
 
 let $str7:="This is a test string"
-let $str8:=substring2($str7,0)
+let $str8:=substring($str7,0)
 
 let $str9:="This is a test string"
-let $str10:=substring2($str9,-1)
+let $str10:=substring($str9,-1)
 
 let $str11:="This is a test string"
 let $str12:="This is a another test string"
-let $str13:=substring2(string-concat([$str11,$str12]),21)
+let $str13:=substring(string-concat([$str11,$str12]),21)
 
-let $str14:=substring2("UC Irvine",string-length("UC Irvine")/2)
+let $str14:=substring("UC Irvine",string-length("UC Irvine")/2)
 return { "str2":$str2,"str4":$str4,"str6":$str6,"str8":$str8,"str10":$str10,"str13":$str13,"str14":$str14}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
index b00bea5..0f5b1ff 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
@@ -6,14 +6,14 @@
  */
 
 for $a in [ substring2("hello world",7,11),
-substring2("hello world",1,11),
-substring2("hello world",3,7),
-substring2("ABCD",3,6),
-substring2("ABCD",0,4),
-substring2("UC Irvine",4,string-length("UC Irvine")),
-substring2("UC Irvine",0,string-length("UC Irvine")),
-substring2("UC Irvine",1,string-length("UC Irvine")),
-substring2(substring2("UC Irvine",4),0,string-length("Irvine")),
-substring2(substring2("UC Irvine",4),0,(string-length("Irvine")/2))
+substring("hello world",1,11),
+substring("hello world",3,7),
+substring("ABCD",3,6),
+substring("ABCD",0,4),
+substring("UC Irvine",4,string-length("UC Irvine")),
+substring("UC Irvine",0,string-length("UC Irvine")),
+substring("UC Irvine",1,string-length("UC Irvine")),
+substring(substring("UC Irvine",4),0,string-length("Irvine")),
+substring(substring("UC Irvine",4),0,(string-length("Irvine")/2))
 ]
 return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
index df111b3..1b2cfe5 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
@@ -11,4 +11,4 @@
 
 for $a in dataset('testdst')
 order by $a.name
-return substring2($a.name,4,string-length($a.name));
+return substring($a.name,4,string-length($a.name));
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr06/substr06.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr06/substr06.3.query.aql
index a2cb9d3..b6be396 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr06/substr06.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr06/substr06.3.query.aql
@@ -10,4 +10,4 @@
 
 for $a in dataset('testdst')
 order by $a.name
-return substring2($a.name,4);
+return substring($a.name,4);
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-1/substring2-1.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-1/substring2-1.3.query.aql
index 2ef7ba8..6e32225 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substring2-1/substring2-1.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-1/substring2-1.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := substring2("HEllow",2)
+let $c1 := substring("HEllow",2)
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-2/substring2-2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-2/substring2-2.3.query.aql
index db40e40..854eac6 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substring2-2/substring2-2.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-2/substring2-2.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := substring2("HEllow",0)
+let $c1 := substring("HEllow",0)
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-3/substring2-3.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-3/substring2-3.3.query.aql
index 77b847c..f8a53f4 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substring2-3/substring2-3.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-3/substring2-3.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := substring2("HEllow",10)
+let $c1 := substring("HEllow",10)
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-4/substring2-4.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-4/substring2-4.3.query.aql
index 27c5ce2..192698c 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substring2-4/substring2-4.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-4/substring2-4.3.query.aql
@@ -1,4 +1,4 @@
 use dataverse test;
 
-let $c1 := substring2("HEllow",-1)
+let $c1 := substring("HEllow",-1)
 return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/toLowerCase02/toLowerCase02.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/toLowerCase02/toLowerCase02.3.query.aql
index 31cb9e3..24ccdcc 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/toLowerCase02/toLowerCase02.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/toLowerCase02/toLowerCase02.3.query.aql
@@ -17,6 +17,6 @@
     lowercase("AbCdEfGhIjKlMnOpQrStUvWxYz"),
     lowercase("abcdefghijkABCDEFGHIJK"),
     lowercase("HIJKLMNOPQRhijklmnopqr"),
-    lowercase(substring2("ABCDEFghIJKLMnopQRSTuvwxYZ01234",0)),
+    lowercase(substring("ABCDEFghIJKLMnopQRSTuvwxYZ01234",0)),
     lowercase("A33B2CD1EF78GHijk123LMNopqrstUVW3x2y01035Z")]
 return $a
diff --git a/asterix-app/src/test/resources/runtimets/results/dml/query-issue288/query-issue288.1.adm b/asterix-app/src/test/resources/runtimets/results/dml/query-issue288/query-issue288.1.adm
new file mode 100644
index 0000000..e6716e8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/dml/query-issue288/query-issue288.1.adm
@@ -0,0 +1 @@
+{ "l_orderkey": 1, "l_linenumber": 2, "l_suppkey": 3 }
diff --git a/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285-2/query_issue285-2.1.adm b/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285-2/query_issue285-2.1.adm
new file mode 100644
index 0000000..3005398
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285-2/query_issue285-2.1.adm
@@ -0,0 +1,10 @@
+{ "aid": 1, "bids": [  ] }
+{ "aid": 2, "bids": [  ] }
+{ "aid": 3, "bids": [  ] }
+{ "aid": 4, "bids": [  ] }
+{ "aid": 5, "bids": [ 98 ] }
+{ "aid": 6, "bids": [  ] }
+{ "aid": 7, "bids": [  ] }
+{ "aid": 8, "bids": [  ] }
+{ "aid": 9, "bids": [  ] }
+{ "aid": 10, "bids": [  ] }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285/query_issue285.1.adm b/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285/query_issue285.1.adm
new file mode 100644
index 0000000..62c427a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/leftouterjoin/query_issue285/query_issue285.1.adm
@@ -0,0 +1,100 @@
+{ "aid": 1, "bids": [  ] }
+{ "aid": 2, "bids": [  ] }
+{ "aid": 3, "bids": [  ] }
+{ "aid": 4, "bids": [  ] }
+{ "aid": 5, "bids": [ 98 ] }
+{ "aid": 6, "bids": [  ] }
+{ "aid": 7, "bids": [  ] }
+{ "aid": 8, "bids": [  ] }
+{ "aid": 9, "bids": [  ] }
+{ "aid": 10, "bids": [  ] }
+{ "aid": 11, "bids": [  ] }
+{ "aid": 12, "bids": [  ] }
+{ "aid": 13, "bids": [  ] }
+{ "aid": 14, "bids": [  ] }
+{ "aid": 15, "bids": [  ] }
+{ "aid": 16, "bids": [  ] }
+{ "aid": 17, "bids": [  ] }
+{ "aid": 18, "bids": [  ] }
+{ "aid": 19, "bids": [  ] }
+{ "aid": 20, "bids": [  ] }
+{ "aid": 21, "bids": [  ] }
+{ "aid": 22, "bids": [  ] }
+{ "aid": 23, "bids": [  ] }
+{ "aid": 24, "bids": [  ] }
+{ "aid": 25, "bids": [  ] }
+{ "aid": 26, "bids": [  ] }
+{ "aid": 27, "bids": [  ] }
+{ "aid": 28, "bids": [  ] }
+{ "aid": 29, "bids": [  ] }
+{ "aid": 30, "bids": [  ] }
+{ "aid": 31, "bids": [  ] }
+{ "aid": 32, "bids": [  ] }
+{ "aid": 33, "bids": [  ] }
+{ "aid": 34, "bids": [ 57 ] }
+{ "aid": 35, "bids": [  ] }
+{ "aid": 36, "bids": [  ] }
+{ "aid": 37, "bids": [  ] }
+{ "aid": 38, "bids": [  ] }
+{ "aid": 39, "bids": [  ] }
+{ "aid": 40, "bids": [  ] }
+{ "aid": 41, "bids": [  ] }
+{ "aid": 42, "bids": [  ] }
+{ "aid": 43, "bids": [  ] }
+{ "aid": 44, "bids": [  ] }
+{ "aid": 45, "bids": [  ] }
+{ "aid": 46, "bids": [  ] }
+{ "aid": 47, "bids": [  ] }
+{ "aid": 48, "bids": [  ] }
+{ "aid": 49, "bids": [  ] }
+{ "aid": 50, "bids": [  ] }
+{ "aid": 51, "bids": [  ] }
+{ "aid": 52, "bids": [  ] }
+{ "aid": 53, "bids": [  ] }
+{ "aid": 54, "bids": [ 91 ] }
+{ "aid": 55, "bids": [  ] }
+{ "aid": 56, "bids": [  ] }
+{ "aid": 57, "bids": [  ] }
+{ "aid": 58, "bids": [  ] }
+{ "aid": 59, "bids": [  ] }
+{ "aid": 60, "bids": [  ] }
+{ "aid": 61, "bids": [  ] }
+{ "aid": 62, "bids": [  ] }
+{ "aid": 63, "bids": [  ] }
+{ "aid": 64, "bids": [  ] }
+{ "aid": 65, "bids": [  ] }
+{ "aid": 66, "bids": [  ] }
+{ "aid": 67, "bids": [  ] }
+{ "aid": 68, "bids": [ 57 ] }
+{ "aid": 69, "bids": [ 57 ] }
+{ "aid": 70, "bids": [  ] }
+{ "aid": 71, "bids": [  ] }
+{ "aid": 72, "bids": [  ] }
+{ "aid": 73, "bids": [  ] }
+{ "aid": 74, "bids": [  ] }
+{ "aid": 75, "bids": [  ] }
+{ "aid": 76, "bids": [  ] }
+{ "aid": 77, "bids": [  ] }
+{ "aid": 78, "bids": [  ] }
+{ "aid": 79, "bids": [  ] }
+{ "aid": 80, "bids": [  ] }
+{ "aid": 81, "bids": [  ] }
+{ "aid": 82, "bids": [  ] }
+{ "aid": 83, "bids": [  ] }
+{ "aid": 84, "bids": [  ] }
+{ "aid": 85, "bids": [  ] }
+{ "aid": 86, "bids": [  ] }
+{ "aid": 87, "bids": [  ] }
+{ "aid": 88, "bids": [  ] }
+{ "aid": 89, "bids": [  ] }
+{ "aid": 90, "bids": [  ] }
+{ "aid": 91, "bids": [  ] }
+{ "aid": 92, "bids": [  ] }
+{ "aid": 93, "bids": [  ] }
+{ "aid": 94, "bids": [  ] }
+{ "aid": 95, "bids": [  ] }
+{ "aid": 96, "bids": [  ] }
+{ "aid": 97, "bids": [  ] }
+{ "aid": 98, "bids": [  ] }
+{ "aid": 99, "bids": [  ] }
+{ "aid": 100, "bids": [  ] }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 4eb7b0f..f6b3192 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -743,6 +743,11 @@
     -->
   </test-group>
   <test-group name="dml">
+     <test-case FilePath="dml">
+      <compilation-unit name="query-issue288">
+        <output-dir compare="Text">query-issue288</output-dir>
+      </compilation-unit>
+    </test-case>
     <test-case FilePath="dml">
       <compilation-unit name="query-issue205">
         <output-dir compare="Text">query-issue205</output-dir>
@@ -4165,5 +4170,17 @@
       </compilation-unit>
   	</test-case>
   </test-group>
+  <test-group name="leftouterjoin">
+    <test-case FilePath="leftouterjoin">
+      <compilation-unit name="query_issue285">
+        <output-dir compare="Text">query_issue285</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="leftouterjoin">
+      <compilation-unit name="query_issue285-2">
+        <output-dir compare="Text">query_issue285-2</output-dir>
+      </compilation-unit>
+    </test-case>
+  </test-group>
 </test-suite>
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataImplConfig.java
new file mode 100644
index 0000000..4ea752b
--- /dev/null
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataImplConfig.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * 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 from
+ * 
+ *     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.
+ */
+
+package edu.uci.ics.asterix.metadata.declared;
+
+public class AqlMetadataImplConfig {
+    private final boolean useInstantLock;
+
+    public AqlMetadataImplConfig(boolean useInstantLock) {
+        this.useInstantLock = useInstantLock;
+    }
+
+    public boolean isInstantLock() {
+        return useInstantLock;
+    }
+}
\ No newline at end of file
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
index 938dfc4..e1f707c 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
@@ -68,6 +68,7 @@
 import edu.uci.ics.asterix.runtime.formats.FormatUtils;
 import edu.uci.ics.asterix.runtime.formats.NonTaggedDataFormat;
 import edu.uci.ics.asterix.runtime.job.listener.JobEventListenerFactory;
+import edu.uci.ics.asterix.transaction.management.opcallbacks.PrimaryIndexInstantSearchOperationCallbackFactory;
 import edu.uci.ics.asterix.transaction.management.opcallbacks.PrimaryIndexModificationOperationCallbackFactory;
 import edu.uci.ics.asterix.transaction.management.opcallbacks.PrimaryIndexSearchOperationCallbackFactory;
 import edu.uci.ics.asterix.transaction.management.opcallbacks.SecondaryIndexModificationOperationCallbackFactory;
@@ -247,7 +248,7 @@
     public Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> getScannerRuntime(
             IDataSource<AqlSourceId> dataSource, List<LogicalVariable> scanVariables,
             List<LogicalVariable> projectVariables, boolean projectPushed, IOperatorSchema opSchema,
-            IVariableTypeEnvironment typeEnv, JobGenContext context, JobSpecification jobSpec)
+            IVariableTypeEnvironment typeEnv, JobGenContext context, JobSpecification jobSpec, Object implConfig)
             throws AlgebricksException {
         Dataset dataset;
         try {
@@ -264,12 +265,12 @@
                         return buildExternalDatasetScan(jobSpec, dataset, dataSource);
                     } else {
                         return buildInternalDatasetScan(jobSpec, scanVariables, opSchema, typeEnv, dataset, dataSource,
-                                context);
+                                context, implConfig);
 
                     }
                 case INTERNAL: {
                     return buildInternalDatasetScan(jobSpec, scanVariables, opSchema, typeEnv, dataset, dataSource,
-                            context);
+                            context, implConfig);
                 }
                 case EXTERNAL: {
                     return buildExternalDatasetScan(jobSpec, dataset, dataSource);
@@ -285,14 +286,14 @@
 
     private Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildInternalDatasetScan(JobSpecification jobSpec,
             List<LogicalVariable> outputVars, IOperatorSchema opSchema, IVariableTypeEnvironment typeEnv,
-            Dataset dataset, IDataSource<AqlSourceId> dataSource, JobGenContext context) throws AlgebricksException,
-            MetadataException {
+            Dataset dataset, IDataSource<AqlSourceId> dataSource, JobGenContext context, Object implConfig)
+            throws AlgebricksException, MetadataException {
         AqlSourceId asid = dataSource.getId();
         String dataverseName = asid.getDataverseName();
         String datasetName = asid.getDatasetName();
         Index primaryIndex = MetadataManager.INSTANCE.getIndex(mdTxnCtx, dataverseName, datasetName, datasetName);
         return buildBtreeRuntime(jobSpec, outputVars, opSchema, typeEnv, context, false, dataset,
-                primaryIndex.getIndexName(), null, null, true, true);
+                primaryIndex.getIndexName(), null, null, true, true, implConfig);
     }
 
     private Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildExternalDatasetScan(JobSpecification jobSpec,
@@ -467,7 +468,8 @@
     public Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildBtreeRuntime(JobSpecification jobSpec,
             List<LogicalVariable> outputVars, IOperatorSchema opSchema, IVariableTypeEnvironment typeEnv,
             JobGenContext context, boolean retainInput, Dataset dataset, String indexName, int[] lowKeyFields,
-            int[] highKeyFields, boolean lowKeyInclusive, boolean highKeyInclusive) throws AlgebricksException {
+            int[] highKeyFields, boolean lowKeyInclusive, boolean highKeyInclusive, Object implConfig)
+            throws AlgebricksException {
         boolean isSecondary = true;
         try {
             Index primaryIndex = MetadataManager.INSTANCE.getIndex(mdTxnCtx, dataset.getDataverseName(),
@@ -523,11 +525,16 @@
                     primaryKeyFields[i] = i;
                 }
 
+                AqlMetadataImplConfig aqlMetadataImplConfig = (AqlMetadataImplConfig) implConfig;
                 TransactionSubsystemProvider txnSubsystemProvider = new TransactionSubsystemProvider();
-                searchCallbackFactory = new PrimaryIndexSearchOperationCallbackFactory(jobId, datasetId,
-                        primaryKeyFields, txnSubsystemProvider, ResourceType.LSM_BTREE);
+                if (aqlMetadataImplConfig != null && aqlMetadataImplConfig.isInstantLock()) {
+                    searchCallbackFactory = new PrimaryIndexInstantSearchOperationCallbackFactory(jobId, datasetId,
+                            primaryKeyFields, txnSubsystemProvider, ResourceType.LSM_BTREE);
+                } else {
+                    searchCallbackFactory = new PrimaryIndexSearchOperationCallbackFactory(jobId, datasetId,
+                            primaryKeyFields, txnSubsystemProvider, ResourceType.LSM_BTREE);
+                }
             }
-
             BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(jobSpec, outputRecDesc,
                     appContext.getStorageManagerInterface(), appContext.getIndexLifecycleManagerProvider(), spPc.first,
                     typeTraits, comparatorFactories, bloomFilterKeyFields, lowKeyFields, highKeyFields,
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
index e8a9719..24649d9 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -181,7 +181,7 @@
     public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "numeric-round-half-to-even", 1);
     public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN2 = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "numeric-round-half-to-even2", 2);
+            FunctionConstants.ASTERIX_NS, "numeric-round-half-to-even", 2);
     // String funcitons
     public final static FunctionIdentifier STRING_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-equal", 2);
@@ -192,17 +192,17 @@
     public final static FunctionIdentifier STRING_MATCHES = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "matches", 2);
     public final static FunctionIdentifier STRING_MATCHES_WITH_FLAG = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "matches2", 3);
+            FunctionConstants.ASTERIX_NS, "matches", 3);
     public final static FunctionIdentifier STRING_LOWERCASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "lowercase", 1);
     public final static FunctionIdentifier STRING_REPLACE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "replace", 3);
     public final static FunctionIdentifier STRING_REPLACE_WITH_FLAG = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "replace2", 4);
+            FunctionConstants.ASTERIX_NS, "replace", 4);
     public final static FunctionIdentifier STRING_LENGTH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "string-length", 1);
     public final static FunctionIdentifier SUBSTRING2 = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "substring2", 2);
+            "substring", 2);
     public final static FunctionIdentifier SUBSTRING_BEFORE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "substring-before", 2);
     public final static FunctionIdentifier SUBSTRING_AFTER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
@@ -494,12 +494,17 @@
     public final static FunctionIdentifier ADJUST_DATETIME_FOR_TIMEZONE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "adjust-datetime-for-timezone", 2);
 
-    public final static FunctionIdentifier GET_POINT_X_COORDINATE_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-x", 1);
-    public final static FunctionIdentifier GET_POINT_Y_COORDINATE_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-y", 1);
-    public final static FunctionIdentifier GET_CIRCLE_RADIUS_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-radius", 1);
-    public final static FunctionIdentifier GET_CIRCLE_CENTER_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-center", 1);
-    public final static FunctionIdentifier GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-points", 1);
-    
+    public final static FunctionIdentifier GET_POINT_X_COORDINATE_ACCESSOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "get-x", 1);
+    public final static FunctionIdentifier GET_POINT_Y_COORDINATE_ACCESSOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "get-y", 1);
+    public final static FunctionIdentifier GET_CIRCLE_RADIUS_ACCESSOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "get-radius", 1);
+    public final static FunctionIdentifier GET_CIRCLE_CENTER_ACCESSOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "get-center", 1);
+    public final static FunctionIdentifier GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "get-points", 1);
+
     public static final FunctionIdentifier EQ = AlgebricksBuiltinFunctions.EQ;
     public static final FunctionIdentifier LE = AlgebricksBuiltinFunctions.LE;
     public static final FunctionIdentifier GE = AlgebricksBuiltinFunctions.GE;
@@ -995,7 +1000,7 @@
         funTypeComputer.put(functionInfo, typeComputer);
         finfoRepo.put(fi);
     }
-    
+
     private static IFunctionInfo addPrivateFunction(FunctionIdentifier fi, IResultTypeComputer typeComputer) {
         IFunctionInfo functionInfo = getAsterixFunctionInfo(fi);
         builtinFunctionsSet.put(functionInfo, functionInfo);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
index b8b1c61..4655c37 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
@@ -56,12 +56,14 @@
             return false;
         }
         AsterixFunctionInfo info = (AsterixFunctionInfo) o;
-        return functionIdentifier.equals(info.getFunctionIdentifier());
+        return functionIdentifier.equals(info.getFunctionIdentifier())
+                && functionIdentifier.getArity() == info.getFunctionIdentifier().getArity();
     }
 
     @Override
     public String toString() {
-        return this.functionIdentifier.getNamespace() + ":" + this.functionIdentifier.getName();
+        return this.functionIdentifier.getNamespace() + ":" + this.functionIdentifier.getName() + "@"
+                + this.functionIdentifier.getArity();
     }
 
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FunctionManagerImpl.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FunctionManagerImpl.java
index b5b6f29..6f834a7 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FunctionManagerImpl.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/FunctionManagerImpl.java
@@ -24,31 +24,34 @@
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.functions.IFunctionManager;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 
 public class FunctionManagerImpl implements IFunctionManager {
-    private final Map<FunctionIdentifier, IFunctionDescriptorFactory> functions;
+    private final Map<Pair<FunctionIdentifier, Integer>, IFunctionDescriptorFactory> functions;
 
     public FunctionManagerImpl() {
-        functions = new HashMap<FunctionIdentifier, IFunctionDescriptorFactory>();
+        functions = new HashMap<Pair<FunctionIdentifier, Integer>, IFunctionDescriptorFactory>();
     }
 
     @Override
     public synchronized IFunctionDescriptor lookupFunction(FunctionIdentifier fid) throws AlgebricksException {
-        return functions.get(fid).createFunctionDescriptor();
+        Pair<FunctionIdentifier, Integer> key = new Pair<FunctionIdentifier, Integer>(fid, fid.getArity());
+        return functions.get(key).createFunctionDescriptor();
     }
 
     @Override
     public synchronized void registerFunction(IFunctionDescriptorFactory descriptorFactory) throws AlgebricksException {
         FunctionIdentifier fid = descriptorFactory.createFunctionDescriptor().getIdentifier();
-        functions.put(fid, descriptorFactory);
+        functions.put(new Pair<FunctionIdentifier, Integer>(fid, fid.getArity()), descriptorFactory);
     }
 
     @Override
     public synchronized void unregisterFunction(IFunctionDescriptorFactory descriptorFactory)
             throws AlgebricksException {
         FunctionIdentifier fid = descriptorFactory.createFunctionDescriptor().getIdentifier();
-        functions.remove(fid);
+        Pair<FunctionIdentifier, Integer> key = new Pair<FunctionIdentifier, Integer>(fid, fid.getArity());
+        functions.remove(key);
     }
 
     @Override
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
index 9b8d1a4..9c344ad 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
@@ -19,7 +19,6 @@
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
@@ -78,9 +77,16 @@
                         eval3.evaluate(tuple);
 
                         try {
-                            ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER
+                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER
                                     .deserialize(outInput0.getByteArray()[0]);
-                            if (tag == ATypeTag.POINT) {
+                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput1.getByteArray()[0]);
+                            ATypeTag tag2 = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput2.getByteArray()[0]);
+                            ATypeTag tag3 = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput3.getByteArray()[0]);
+                            if (tag0 == ATypeTag.POINT && tag1 == ATypeTag.POINT && tag2 == ATypeTag.DOUBLE
+                                    && tag3 == ATypeTag.DOUBLE) {
                                 double xLoc = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                         APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                 double yLoc = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
@@ -100,11 +106,24 @@
                                 aPoint[1].setValue(x + xInc, y + yInc);
                                 aRectangle.setValue(aPoint[0], aPoint[1]);
                                 rectangleSerde.serialize(aRectangle, out);
-                            } else if (tag == ATypeTag.NULL) {
+                            } else if (tag0 == ATypeTag.NULL || tag1 == ATypeTag.NULL || tag2 == ATypeTag.NULL
+                                    || tag3 == ATypeTag.NULL) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_CELL.getName()
-                                        + ": does not support the type: " + tag + "; it is only implemented for POINT.");
+                                throw new AlgebricksException(
+                                        AsterixBuiltinFunctions.SPATIAL_CELL.getName()
+                                                + ": expects input type: (POINT, POINT, DOUBLE, DOUBLE) but got ("
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput0
+                                                        .getByteArray()[0])
+                                                + ", "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput1
+                                                        .getByteArray()[0])
+                                                + ", "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput2
+                                                        .getByteArray()[0])
+                                                + ", "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput3
+                                                        .getByteArray()[0]) + ").");
                             }
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);