[GitHub] incubator-trafodion pull request #750: TRAFODION-2265

2016-10-18 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/incubator-trafodion/pull/750


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-trafodion pull request #750: TRAFODION-2265

2016-10-10 Thread narendragoyal
Github user narendragoyal commented on a diff in the pull request:

https://github.com/apache/incubator-trafodion/pull/750#discussion_r82648928
  
--- Diff: core/sql/exp/exp_fixup.cpp ---
@@ -1740,6 +1741,103 @@ Lng32 
ex_conv_clause::findIndexIntoInstrArray(ConvInstruction ci)
   return -1; // not found
 }
 
+bool   ex_conv_clause::sv_instrOffsetIndexPopulated = false;
+short  ex_conv_clause::sv_MaxOpTypeValue = -1;
+int   *ex_conv_clause::sv_convIndexSparse = 0;
+
+/* 
+ * Scans convInstrInfo[] and populates a 
+ * sparsely populated index: sv_convIndexSparse. 
+ * 
+ * For a given op type: op_type, 
+ * if (sv_convIndexSparse[op_type>] != -1) then 
+ * it contains the offset into the first row of 
+ * convInstrInfo[]
+ */
+void ex_conv_clause::populateInstrOffsetIndex()
+{
+  if (sv_instrOffsetIndexPopulated) {
+return;
+  }
+
+  typedef struct convInstrIndexStruct {
+short type_op1;
+short offset;
+  } convInstrIndexDef;
+  
+  short lv_MaxIndex = -1;
+
+  // Currently, the number of distinct 'type_op1' values in the 
convInstrInf[] is 32
+  const int lv_MaxIndexCapacity = 100;
+  convInstrIndexDef lv_convIndex[lv_MaxIndexCapacity];
+
+  Int32 i = 0;
+  Int32 lv_source_type = -1;
+  Int32 lv_max_array_size = sizeof(ex_conv_clause::convInstrInfo) / 
sizeof(ex_conv_clause::ConvInstrStruct);
+  
+  // collect distinct type_op1 values and their 1st offset in 
convInstrInfo[]
+  while (i < lv_max_array_size) {
+if (ex_conv_clause::convInstrInfo[i].type_op1 != lv_source_type) {
+  lv_source_type = ex_conv_clause::convInstrInfo[i].type_op1;
+  if ((lv_source_type > -1) && 
+ (lv_MaxIndex < (lv_MaxIndexCapacity - 1))) {
+   lv_convIndex[++lv_MaxIndex].type_op1 = lv_source_type;
+   lv_convIndex[lv_MaxIndex].offset = i;
+  }
+}
+i++;
+  }
+
+  // Find the max op type value in lv_convIndex
+  int j = 0;
+  while (j <= lv_MaxIndex) {
+if (sv_MaxOpTypeValue < lv_convIndex[j].type_op1) {
+  sv_MaxOpTypeValue = lv_convIndex[j].type_op1;
+}
+j++;
+  }
+
+  // just in case some op type has been assigned a pretty large value
+  // we dont want to allocate a very large sparse value
+  if (sv_MaxOpTypeValue > 8000) {
+sv_MaxOpTypeValue = 8000;
+  }
+  
+  // Allocate a sparsely populated array
+  sv_convIndexSparse = (int *) calloc(sizeof(int), 
--- End diff --

Thanks Dave! Agreed - will take care of it as you suggested.

I will also remove the call to ex_conv_clause::populateInstrOffsetIndex() 
from ex_conv_clause::getInstrOffset. This way 
ex_conv_clause::populateInstrOffsetIndex() will only be called from sqInit().


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-trafodion pull request #750: TRAFODION-2265

2016-10-10 Thread DaveBirdsall
Github user DaveBirdsall commented on a diff in the pull request:

https://github.com/apache/incubator-trafodion/pull/750#discussion_r82643315
  
--- Diff: core/sql/exp/exp_fixup.cpp ---
@@ -1740,6 +1741,103 @@ Lng32 
ex_conv_clause::findIndexIntoInstrArray(ConvInstruction ci)
   return -1; // not found
 }
 
+bool   ex_conv_clause::sv_instrOffsetIndexPopulated = false;
+short  ex_conv_clause::sv_MaxOpTypeValue = -1;
+int   *ex_conv_clause::sv_convIndexSparse = 0;
+
+/* 
+ * Scans convInstrInfo[] and populates a 
+ * sparsely populated index: sv_convIndexSparse. 
+ * 
+ * For a given op type: op_type, 
+ * if (sv_convIndexSparse[op_type>] != -1) then 
+ * it contains the offset into the first row of 
+ * convInstrInfo[]
+ */
+void ex_conv_clause::populateInstrOffsetIndex()
+{
+  if (sv_instrOffsetIndexPopulated) {
+return;
+  }
+
+  typedef struct convInstrIndexStruct {
+short type_op1;
+short offset;
+  } convInstrIndexDef;
+  
+  short lv_MaxIndex = -1;
+
+  // Currently, the number of distinct 'type_op1' values in the 
convInstrInf[] is 32
+  const int lv_MaxIndexCapacity = 100;
+  convInstrIndexDef lv_convIndex[lv_MaxIndexCapacity];
+
+  Int32 i = 0;
+  Int32 lv_source_type = -1;
+  Int32 lv_max_array_size = sizeof(ex_conv_clause::convInstrInfo) / 
sizeof(ex_conv_clause::ConvInstrStruct);
+  
+  // collect distinct type_op1 values and their 1st offset in 
convInstrInfo[]
+  while (i < lv_max_array_size) {
+if (ex_conv_clause::convInstrInfo[i].type_op1 != lv_source_type) {
+  lv_source_type = ex_conv_clause::convInstrInfo[i].type_op1;
+  if ((lv_source_type > -1) && 
+ (lv_MaxIndex < (lv_MaxIndexCapacity - 1))) {
+   lv_convIndex[++lv_MaxIndex].type_op1 = lv_source_type;
+   lv_convIndex[lv_MaxIndex].offset = i;
+  }
+}
+i++;
+  }
+
+  // Find the max op type value in lv_convIndex
+  int j = 0;
+  while (j <= lv_MaxIndex) {
+if (sv_MaxOpTypeValue < lv_convIndex[j].type_op1) {
+  sv_MaxOpTypeValue = lv_convIndex[j].type_op1;
+}
+j++;
+  }
+
+  // just in case some op type has been assigned a pretty large value
+  // we dont want to allocate a very large sparse value
+  if (sv_MaxOpTypeValue > 8000) {
+sv_MaxOpTypeValue = 8000;
+  }
+  
+  // Allocate a sparsely populated array
+  sv_convIndexSparse = (int *) calloc(sizeof(int), 
--- End diff --

I think this logic is idempotent to it probably doesn't matter but it looks 
like two threads could do the calloc, one of them will win in setting 
sv_convIndexSparse, then both of them could interleave in the initialization 
logic below. Could be the fast one sets the sv_instrOffsetIndexPopulated flag 
to true while the slow one is in the Initialize to -1 loop so theoretically we 
could get wrong answers. Might be safer to use a local variable here and only 
set sv_convIndexSparse at the very end just before setting the boolean. Then 
the worst thing that happens is we allocated the array twice but it will never 
be inconsistent.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-trafodion pull request #750: TRAFODION-2265

2016-10-08 Thread narendragoyal
GitHub user narendragoyal opened a pull request:

https://github.com/apache/incubator-trafodion/pull/750

TRAFODION-2265

[TRAFODION-2265]

Parse ex_conv_clause::convInstrStrInfo at sql process startup
(in sqInit) into a sparsely populated index for quick reference by
ex_conv_clause::findInstruction.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/narendragoyal/incubator-trafodion master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-trafodion/pull/750.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #750


commit 9278776aba5db83cbfb8ecdeb14ede68cbce7e73
Author: Narendra Goyal 
Date:   2016-10-08T17:58:39Z

TRAFODION-2265

Parse ex_conv_clause::convInstrStrInfo at sql process startup
(in sqInit) into a sparsely populated index for quick reference by
ex_conv_clause::findInstruction.

commit fe5ca994159bd59fd9f15603a5e37df959c7f0ca
Author: Narendra Goyal 
Date:   2016-10-08T18:11:26Z

TRAFODION-2265

Parse ex_conv_clause::convInstrStrInfo at sql process startup
(in sqInit) into a sparsely populated index for quick reference by
ex_conv_clause::findInstruction.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---