You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by in...@apache.org on 2018/04/27 05:24:07 UTC

incubator-hawq git commit: HAWQ-1611. refactor the vtype in order to advance the performance (by Wang Weinan)

Repository: incubator-hawq
Updated Branches:
  refs/heads/master 80eaf448f -> cebbda9da


HAWQ-1611. refactor the vtype in order to advance the performance (by Wang Weinan)


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/cebbda9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/cebbda9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/cebbda9d

Branch: refs/heads/master
Commit: cebbda9da81b30e47c0a68138f20f5b7d97a5f39
Parents: 80eaf44
Author: Shujie Zhang <sh...@Shujie-Zhangs-MacBook-Pro.local>
Authored: Thu Apr 26 14:52:03 2018 +0800
Committer: interma <in...@outlook.com>
Committed: Fri Apr 27 13:22:49 2018 +0800

----------------------------------------------------------------------
 contrib/vexecutor/Makefile         |   2 +-
 contrib/vexecutor/README           |   2 +-
 contrib/vexecutor/ao_reader.c      |   8 +-
 contrib/vexecutor/execVQual.c      |  46 ++--
 contrib/vexecutor/execVQual.h      |   1 -
 contrib/vexecutor/execVScan.c      |  20 +-
 contrib/vexecutor/parquet_reader.c |  23 +-
 contrib/vexecutor/tuplebatch.c     |  93 +++++---
 contrib/vexecutor/tuplebatch.h     |   7 +-
 contrib/vexecutor/vadt.c           | 410 --------------------------------
 contrib/vexecutor/vadt.h           | 218 -----------------
 contrib/vexecutor/vcheck.c         |  50 +---
 contrib/vexecutor/vcheck.h         |  15 +-
 contrib/vexecutor/vexecutor.c      |   9 +-
 contrib/vexecutor/vexecutor.h      |   3 +-
 contrib/vexecutor/vtype.c          | 323 +++++++++++++++++++++++++
 contrib/vexecutor/vtype.h          | 171 +++++++++++++
 17 files changed, 628 insertions(+), 773 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/Makefile
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/Makefile b/contrib/vexecutor/Makefile
index cb6cdd4..ed655b5 100644
--- a/contrib/vexecutor/Makefile
+++ b/contrib/vexecutor/Makefile
@@ -17,7 +17,7 @@
 
 
 MODULE_big = vexecutor
-OBJS    = vexecutor.o vadt.o vcheck.o tuplebatch.o execVScan.o execVQual.o parquet_reader.o ao_reader.o
+OBJS    = vexecutor.o vtype.o vcheck.o tuplebatch.o execVScan.o execVQual.o parquet_reader.o ao_reader.o
 
 PG_CXXFLAGS = -Wall -O0 -g -std=c++11
 PG_LIBS = $(libpq_pgport) 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/README
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/README b/contrib/vexecutor/README
index ec5fc6f..68f9e92 100644
--- a/contrib/vexecutor/README
+++ b/contrib/vexecutor/README
@@ -70,7 +70,7 @@ data type, you can follow these steps:
 For example, If the base type is 'XXX', we want to create the 
 vectorized data types for it:
     1) You can add the vectorized data types struct
-       (e.g. Add to vadt.h)
+       (e.g. Add to vtype.h)
             typedef struct vXXX
             {
                 vheader header;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/ao_reader.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/ao_reader.c b/contrib/vexecutor/ao_reader.c
index bdba565..44ad709 100644
--- a/contrib/vexecutor/ao_reader.c
+++ b/contrib/vexecutor/ao_reader.c
@@ -93,12 +93,14 @@ AppendOnlyVScanNext(ScanState *scanState)
                 if(!tb->datagroup[i])
                     tbCreateColumn(tb,i,hawqVTypeID);
 
-                Datum *ptr = GetVFunc(hawqVTypeID)->gettypeptr(tb->datagroup[i],tb->nrows);
-                *ptr = slot_getattr(slot,i + 1, &(tb->datagroup[i]->isnull[tb->nrows]));
+                tb->datagroup[i]->values[tb->nrows] = slot_getattr(slot,i + 1, &(tb->datagroup[i]->isnull[tb->nrows]));
 
                 /* if attribute is a reference, deep copy the data out to prevent ao table buffer free before vectorized scan batch done */
                 if(!slot->tts_mt_bind->tupdesc->attrs[i]->attbyval)
-                    *ptr = datumCopy(*ptr,slot->tts_mt_bind->tupdesc->attrs[i]->attbyval,slot->tts_mt_bind->tupdesc->attrs[i]->attlen);
+                    tb->datagroup[i]->values[tb->nrows]= datumCopy(tb->datagroup[i]->values[tb->nrows],
+                                                                   slot->tts_mt_bind->tupdesc->attrs[i]->attbyval,
+                                                                   slot->tts_mt_bind->tupdesc->attrs[i]->attlen);
+
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/execVQual.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/execVQual.c b/contrib/vexecutor/execVQual.c
index 83e298a..0974e1e 100644
--- a/contrib/vexecutor/execVQual.c
+++ b/contrib/vexecutor/execVQual.c
@@ -120,9 +120,9 @@ VirtualNodeProc(ScanState* state,TupleTableSlot *slot){
 
     for(int i = 0;i < tb->ncols;i ++)
     {
-        vheader *header = tb->datagroup[i];
-        GetVFunc(GetVtype(header->elemtype))->gettypevalue(header,tb->iter,slot->PRIVATE_tts_values + i);
-        slot->PRIVATE_tts_isnull[i] = header->isnull[tb->iter];
+        vtype *vt = tb->datagroup[i];
+        slot->PRIVATE_tts_values[i] = vt->values[tb->iter];
+        slot->PRIVATE_tts_isnull[i] = vt->isnull[tb->iter];
     }
     tb->iter ++;
     ExecStoreVirtualTuple(slot);
@@ -271,7 +271,7 @@ VExecEvalVar(ExprState *exprstate, ExprContext *econtext,
 			if (!attr->attisdropped)
 			{
 				if (variable->vartype != attr->atttypid &&
-					GetNType(variable->vartype) != attr->atttypid)
+					GetNtype(variable->vartype) != attr->atttypid)
 					ereport(ERROR,
 							(errmsg("attribute %d has wrong type", attnum),
 							 errdetail("Table has type %s, but query expects %s.",
@@ -334,9 +334,9 @@ VExecEvalNot(BoolExprState *notclause, ExprContext *econtext,
 	expr_value = ExecEvalExpr(clause, econtext, isNull, NULL);
 
 	ret = (vbool*)DatumGetPointer(expr_value);
-	for(i = 0; i < ret->header.dim; i++)
+	for(i = 0; i < ret->dim; i++)
 	{
-		if(!ret->header.isnull[i])
+		if(!ret->isnull[i])
 			ret->values[i] = !ret->values[i];
 	}
 
@@ -394,10 +394,10 @@ VExecEvalOr(BoolExprState *orExpr, ExprContext *econtext,
 		if(NULL == res)
 		{
 			res = DatumGetPointer(clause_value);
-			Assert(NULL != res->header.isnull);
-			for(i = 0; i < res->header.dim; i++)
+			Assert(NULL != res->isnull);
+			for(i = 0; i < res->dim; i++)
 			{
-				if(res->header.isnull[i] ||
+				if(res->isnull[i] ||
 					!res->values[i])
 				{
 					skip = false;
@@ -408,13 +408,13 @@ VExecEvalOr(BoolExprState *orExpr, ExprContext *econtext,
 		else
 		{
 			next = DatumGetPointer(clause_value);
-			Assert(NULL != res->header.isnull && NULL != next->header.isnull);
-			for(i = 0; i < res->header.dim; i++)
+			Assert(NULL != res->isnull && NULL != next->isnull);
+			for(i = 0; i < res->dim; i++)
 			{
-				res->header.isnull[i] =
-						(res->header.isnull[i] || next->header.isnull[i]);
+				res->isnull[i] =
+						(res->isnull[i] || next->isnull[i]);
 				res->values[i] = (res->values[i] || next->values[i]);
-				if(skip && (res->header.isnull[i] || !res->values[i]))
+				if(skip && (res->isnull[i] || !res->values[i]))
 					skip = false;
 			}
 		}
@@ -468,10 +468,10 @@ VExecEvalAndInternal(List* clauses, ExprContext *econtext,
 		if(NULL == res)
 		{
 			res = DatumGetPointer(clause_value);
-			Assert(NULL != res->header.isnull);
-			for(i = 0; i < res->header.dim; i++)
+			Assert(NULL != res->isnull);
+			for(i = 0; i < res->dim; i++)
 			{
-				if(res->header.isnull[i] || res->values[i])
+				if(res->isnull[i] || res->values[i])
 				{
 					skip = false;
 					break;
@@ -481,13 +481,13 @@ VExecEvalAndInternal(List* clauses, ExprContext *econtext,
 		else
 		{
 			next = DatumGetPointer(clause_value);
-			Assert(NULL != res->header.isnull && NULL != next->header.isnull);
-			for(i = 0; i < res->header.dim; i++)
+			Assert(NULL != res->isnull && NULL != next->isnull);
+			for(i = 0; i < res->dim; i++)
 			{
-				res->header.isnull[i] =
-						(res->header.isnull[i] || next->header.isnull[i]);
+				res->isnull[i] =
+						(res->isnull[i] || next->isnull[i]);
 				res->values[i] = (res->values[i] && next->values[i]);
-				if(skip && (res->header.isnull[i] || res->values[i]))
+				if(skip && (res->isnull[i] || res->values[i]))
 					skip = false;
 			}
 		}
@@ -656,7 +656,7 @@ ExecVTargetList(List *targetlist,
 		TargetEntry *tle = (TargetEntry *) gstate->xprstate.expr;
 		AttrNumber	resind = tle->resno - 1;
 
-		tb->datagroup[resind] = ExecEvalExpr(gstate->arg,
+		tb->datagroup[resind] = (vtype*)ExecEvalExpr(gstate->arg,
 									  econtext,
 									  &isnull,
 									  &itemIsDone[resind]);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/execVQual.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/execVQual.h b/contrib/vexecutor/execVQual.h
index 01113dc..4ff4fac 100644
--- a/contrib/vexecutor/execVQual.h
+++ b/contrib/vexecutor/execVQual.h
@@ -26,7 +26,6 @@
 #include "executor/execdebug.h"
 #include "executor/nodeAgg.h"
 #include "tuplebatch.h"
-#include "vadt.h"
 
 extern TupleTableSlot *
 ExecVProject(ProjectionInfo *projInfo, ExprDoneCond *isDone);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/execVScan.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/execVScan.c b/contrib/vexecutor/execVScan.c
index deb2724..f6267ce 100644
--- a/contrib/vexecutor/execVScan.c
+++ b/contrib/vexecutor/execVScan.c
@@ -193,23 +193,29 @@ ExecVScan(ScanState *node, ExecScanAccessMtd accessMtd)
                 /* first construct the skip array */
                 if(NULL != skip)
                 {
-                    for(i = 0; i < skip->header.dim; i++)
+                    for(i = 0; i < skip->dim; i++)
                     {
-                        skip->values[i] = ((!(skip->values[i])) ||
-                                          (skip->header.isnull[i]) ||
+                        ((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->skip[i] =
+                                          ((!DatumGetBool(skip->values[i])) ||
+                                          (skip->isnull[i]) ||
                                           ((TupleBatch)slot->PRIVATE_tb)->skip[i]);
                     }
                 }
+                else
+                {
+                    Assert(((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->batchsize ==
+                           ((TupleBatch)slot->PRIVATE_tb)->batchsize);
+
+                    memcpy(((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->skip,
+                            ((TupleBatch)slot->PRIVATE_tb)->skip,
+                            ((TupleBatch)slot->PRIVATE_tb)->batchsize * sizeof(bool));
+                }
 
                 /*
                  * Form a projection tuple, store it in the result tuple slot
                  * and return it.
                  */
                 ((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->nrows = ((TupleBatch)slot->PRIVATE_tb)->nrows;
-                if(NULL != skip)
-                    ((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->skip = skip->values;
-                else
-                    ((TupleBatch)projInfo->pi_slot->PRIVATE_tb)->skip = ((TupleBatch)slot->PRIVATE_tb)->skip;
                 return ExecVProject(projInfo, NULL);
             }
             else

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/parquet_reader.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/parquet_reader.c b/contrib/vexecutor/parquet_reader.c
index ca58a09..4298022 100644
--- a/contrib/vexecutor/parquet_reader.c
+++ b/contrib/vexecutor/parquet_reader.c
@@ -131,12 +131,13 @@ ParquetRowGroupReader_ScanNextTupleBatch(
 			continue;
 
 		Oid hawqTypeID = tupDesc->attrs[i]->atttypid;
-		Oid hawqVTypeID = GetVtype(hawqTypeID);
 		if(!tb->datagroup[i])
-			tbCreateColumn(tb,i,hawqVTypeID);
+			tbCreateColumn(tb,i,hawqTypeID);
+
+
+		vtype* vt = tb->datagroup[i];
+		vt->dim = tb->nrows;
 
-		vheader* header = tb->datagroup[i];
-		header->dim = tb->nrows;
 
 		ParquetColumnReader *nextReader =
 			&rowGroupReader->columnReaders[colReaderIndex];
@@ -146,7 +147,7 @@ ParquetRowGroupReader_ScanNextTupleBatch(
 
 			if(hawqAttrToParquetColNum[i] == 1)
 			{
-				ParquetColumnReader_readValue(nextReader, GetVFunc(hawqVTypeID)->gettypeptr(header,j), header->isnull + j, hawqTypeID);
+				ParquetColumnReader_readValue(nextReader, vt->values + j , vt->isnull + j, hawqTypeID);
 			}
 			else
 			{
@@ -159,22 +160,22 @@ ParquetRowGroupReader_ScanNextTupleBatch(
 				switch(hawqTypeID)
 				{
 					case HAWQ_TYPE_POINT:
-						ParquetColumnReader_readPoint(nextReader, GetVFunc(hawqVTypeID)->gettypeptr(header,j), header->isnull + j);
+						ParquetColumnReader_readPoint(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					case HAWQ_TYPE_PATH:
-						ParquetColumnReader_readPATH(nextReader, GetVFunc(hawqVTypeID)->gettypeptr(header,j), header->isnull + j);
+						ParquetColumnReader_readPATH(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					case HAWQ_TYPE_LSEG:
-						ParquetColumnReader_readLSEG(nextReader, GetVFunc(hawqVTypeID)->gettypeptr(header,j), header->isnull + j);
+						ParquetColumnReader_readLSEG(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					case HAWQ_TYPE_BOX:
-						ParquetColumnReader_readBOX(nextReader, GetVFunc(hawqVTypeID)->gettypeptr(header,j), header->isnull + j);
+						ParquetColumnReader_readBOX(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					case HAWQ_TYPE_CIRCLE:
-						ParquetColumnReader_readCIRCLE(nextReader,GetVFunc(hawqVTypeID)->gettypeptr(header,j),header->isnull + j);
+						ParquetColumnReader_readCIRCLE(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					case HAWQ_TYPE_POLYGON:
-						ParquetColumnReader_readPOLYGON(nextReader,GetVFunc(hawqVTypeID)->gettypeptr(header,j),header->isnull + j);
+						ParquetColumnReader_readPOLYGON(nextReader, vt->values + j, vt->isnull + j);
 						break;
 					default:
 						Insist(false);

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/tuplebatch.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/tuplebatch.c b/contrib/vexecutor/tuplebatch.c
index cd8859b..d8f2f3f 100644
--- a/contrib/vexecutor/tuplebatch.c
+++ b/contrib/vexecutor/tuplebatch.c
@@ -19,9 +19,6 @@
 #include "postgres.h"
 #include "tuplebatch.h"
 
-static size_t vtypeSize(vheader *vh);
-static size_t tbSerializationSize(TupleBatch tb);
-
 TupleBatch tbGenerate(int colnum,int batchsize)
 {
     Assert(colnum > 0 && batchsize > 0);
@@ -42,16 +39,16 @@ TupleBatch tbGenerate(int colnum,int batchsize)
 }
 
 void tbDestroy(TupleBatch* tb){
-    free((*tb)->skip);
+    pfree((*tb)->skip);
     for(int i = 0 ;i < (*tb)->ncols; ++i)
     {
         if((*tb)->datagroup[i])
             tbfreeColumn((*tb)->datagroup,i);
     }
 
-    free((*tb)->datagroup);
+    pfree((*tb)->datagroup);
 
-    free((*tb));
+    pfree((*tb));
     *tb = NULL;
 }
 
@@ -68,17 +65,12 @@ void tbCreateColumn(TupleBatch tb,int colid,Oid type)
         return;
     int bs = tb->batchsize;
 
-    tb->datagroup[colid] = GetVFunc(type)->vtbuild((bs));
+    tb->datagroup[colid] = buildvtype(type,bs,tb->skip);
 }
 
-void tbfreeColumn(vheader** vh,int colid)
+void tbfreeColumn(vtype** vh,int colid)
 {
-    GetVFunc(GetVtype(vh[colid]->elemtype))->vtfree(&vh[colid]);
-}
-
-static size_t vtypeSize(vheader *vh)
-{
-    return GetVFunc(GetVtype(vh->elemtype))->vtsize(vh);
+    destroyvtype(&vh[colid]);
 }
 
 static size_t
@@ -93,76 +85,95 @@ tbSerializationSize(TupleBatch tb)
     //get skip tag size
     len += sizeof( bool ) * tb->nrows;
 
+    int vtypeSz = VTYPESIZE(tb->nrows);
     //get all un-null columns data size
     for(int i = 0;i < tb->ncols; i++ )
     {
         if(tb->datagroup[i])
         {
             len += sizeof(int);
-            len += vtypeSize(tb->datagroup[i]);
+            len += vtypeSz;
         }
     }
     return len;
 }
 
-unsigned char *
+MemTuple
 tbSerialization(TupleBatch tb )
 {
+    MemTuple ret;
     size_t len = 0;
     size_t tmplen = 0;
     //calculate total size for TupleBatch
     size_t size = tbSerializationSize(tb);
+    //makes buffer length about 8-bytes alignment for motion
+    size = (size + 0x8) & (~0x7);
 
-    unsigned char *buffer = palloc(size);
+    ret = palloc0(size);
+    unsigned char *buffer = ret->PRIVATE_mt_bits;
 
     //copy TupleBatch header
     memcpy(buffer,&size,sizeof(size_t));
+    buffer += sizeof(size_t);
 
     tmplen = offsetof(TupleBatchData ,skip);
-    memcpy(buffer+len,tb,tmplen);
-    len += tmplen;
+    memcpy(buffer,tb,tmplen);
+    buffer +=tmplen;
 
     tmplen = sizeof(bool) * tb->nrows;
-    memcpy(buffer+len,tb->skip,tmplen);
-    len += tmplen;
+    memcpy(buffer,tb->skip,tmplen);
+    buffer += tmplen;
 
 
     for(int i = 0;i < tb->ncols; i++ )
     {
         if(tb->datagroup[i])
         {
-            memcpy(buffer+len,&i,sizeof(int));
-            len += sizeof(int);
+            memcpy(buffer,&i,sizeof(int));
+            buffer += sizeof(int);
+
+            unsigned char* ptr = buffer;
+            memcpy(ptr,tb->datagroup[i],offsetof(vtype,isnull));
+            ptr+= offsetof(vtype,isnull);
+
+            tmplen = VDATUMSZ(tb->nrows);
+            memcpy(ptr,tb->datagroup[i]->values, tmplen);
+            ptr += tmplen;
 
-            tmplen = GetVFunc(tb->datagroup[i]->elemtype)->serialization(tb->datagroup[i],buffer + len);
-            len += tmplen;
+            tmplen = ISNULLSZ(tb->nrows);
+            memcpy(ptr,tb->datagroup[i]->isnull,tmplen);
+            buffer += VTYPESIZE(tb->nrows);
         }
     }
 
-    return buffer;
+    memtuple_set_size(ret,NULL,size);
+    return ret;
 }
 
 TupleBatch tbDeserialization(unsigned char *buffer)
 {
     size_t buflen;
-    memcpy(&buflen,buffer,sizeof(size_t));
+    size_t len = 0;
+    size_t tmplen = 0;
+    tmplen = sizeof(size_t);
+    memcpy(&buflen,buffer,tmplen);
+    len += tmplen;
 
     if(buflen < sizeof(TupleBatchData))
         return NULL;
 
-    size_t len = 0;
-    size_t tmplen = 0;
     TupleBatch tb = palloc0(sizeof(TupleBatchData));
 
     //deserial tb main data
     tmplen = offsetof(TupleBatchData,skip);
-    memcpy(tb,buffer+len,tmplen);
+    memcpy(tb,buffer + len,tmplen);
     len += tmplen;
 
     //deserial member value -- skip
     if(tb->nrows != 0)
     {
-        tb->skip = palloc(sizeof(bool) * tb->nrows);
+        tmplen = sizeof(bool) * tb->nrows;
+        tb->skip = palloc(tmplen);
         memcpy(tb->skip,buffer+len,tmplen);
         len += tmplen;
     }
@@ -170,14 +181,26 @@ TupleBatch tbDeserialization(unsigned char *buffer)
     //deserial member value -- datagroup
     if(tb->ncols != 0)
     {
-        tb->datagroup = palloc0(sizeof(vheader*) * tb->ncols);
         int colid;
-        while (len < buflen)
+        tmplen = sizeof(vtype*) * tb->ncols;
+        tb->datagroup = palloc0(tmplen);
+        //the buffer length is 8-bytes alignment, 
+        //so we need align the current length before comparing.
+        while (((len + 0x8) & (~0x7)) < buflen)
         {
             memcpy(&colid,buffer + len,sizeof(int));
             len += sizeof(int);
-            tb->datagroup[colid] = (vheader* ) GetVFunc(((vheader *) (buffer + len))->elemtype)->deserialization(buffer + len,&tmplen);
-            len += tmplen;
+
+            vtype* src = (vtype*)(buffer + len);
+            tb->datagroup[colid] = buildvtype(src->elemtype,tb->batchsize,tb->skip);
+
+            tmplen = VDATUMSZ(tb->batchsize);
+            //in vtype pointer isnull and skipref are't serialized
+            memcpy(tb->datagroup[colid]->values,src->values - 2,tmplen);
+
+            memcpy(tb->datagroup[colid]->isnull,ISNULLOFFSET(src) - 2,tb->nrows * sizeof(bool));
+
+            len += VTYPESIZE(tb->nrows);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/tuplebatch.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/tuplebatch.h b/contrib/vexecutor/tuplebatch.h
index 8954f6e..d87f0f4 100644
--- a/contrib/vexecutor/tuplebatch.h
+++ b/contrib/vexecutor/tuplebatch.h
@@ -56,13 +56,12 @@
 
 typedef struct TupleBatchData
 {
-    int     _tb_len;
     int     batchsize;  //indicate maximum number of batch
     int     ncols;      //the number of target table column
     int     nrows;      //the number of tuples scaned out
     int     iter;       //used for data
     bool*   skip;       //used for qualification
-    vheader** datagroup;
+    vtype** datagroup;
 }TupleBatchData,*TupleBatch;
 
 /* TupleBatch ctor */
@@ -74,9 +73,9 @@ void tbReset(TupleBatch tb);
 /* TupleBatch dtor */
 void tbDestroy(TupleBatch* tb);
 /* free one column */
-void tbfreeColumn(vheader** vh,int colid);
+void tbfreeColumn(vtype** vh,int colid);
 /* TupleBatch serialization function */
-unsigned char * tbSerialization(TupleBatch tb);
+MemTuple tbSerialization(TupleBatch tb);
 /* TupleBatch deserialization function */
 TupleBatch tbDeserialization(unsigned char *buffer);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vadt.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vadt.c b/contrib/vexecutor/vadt.c
deleted file mode 100644
index 1aa486e..0000000
--- a/contrib/vexecutor/vadt.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "postgres.h"
-#include "catalog/pg_type.h"
-#include "utils/builtins.h"
-#include "vadt.h"
-
-
-/* the maximum length of numeric */
-#define MAX_NUM_LEN 32
-
-/* Get the size of vectorized data */
-#define FUNCTION_VTYPESIZE(type) \
-size_t v##type##Size(vheader *vh) \
-{\
-	size_t len = offsetof(vheader,isnull);\
-	return  len + vh->dim * sizeof(bool) + vh->dim * sizeof(type) + sizeof(Datum);\
-}
-
-/* Build the vectorized data */
-#define FUNCTION_BUILD(type, typeoid) \
-vheader* buildv##type(int n) \
-{ \
-	vheader* result; \
-	result = (vheader*) palloc0(offsetof(v##type,values) + n * sizeof(type) + sizeof(Datum)) ; \
-	result->dim = n; \
-	result->elemtype = typeoid; \
-	result->isnull = palloc0(sizeof(bool) * n); \
-	SET_VARSIZE(result,v##type##Size(result)); \
-	return result; \
-}
-
-/* Destroy the vectorized data */
-#define FUNCTION_DESTORY(type, typeoid) \
-void destroyv##type(vheader **header) \
-{ \
-	v##type** ptr = (v##type**) header; \
-	pfree((*header)->isnull); \
-	pfree(*ptr); \
-	*ptr = NULL; \
-}
-
-/*
- * Serialize functions and deserialize functions for the abstract data types
- */
-#define FUNCTION_SERIALIZATION(type,typeoid) \
-size_t v##type##serialization(vheader* vh,unsigned char *buf) \
-{ \
-	size_t len = 0; \
-	v##type *vt = (v##type *)vh; \
- \
-	memcpy(buf + len,vt,offsetof(vheader,isnull)); \
-	len += offsetof(vheader,isnull); \
- \
-	memcpy(buf + len,vh->isnull,sizeof(bool) * vh->dim); \
-	len += sizeof(bool) * vh->dim; \
- \
-	memcpy(buf + len,vt->values,sizeof(type) * vh->dim); \
-	len += sizeof(type) * vh->dim; \
- \
-	return len; \
-} \
-\
-\
-Datum v##type##deserialization(unsigned char* buf,size_t* len) \
-{\
-	vheader* vh = (vheader *) buf;\
-	*len = 0;\
-	\
-	v##type* vt = palloc(sizeof(v##type) + sizeof(type) * vh->dim);\
-	memcpy(vt,buf,offsetof(vheader,isnull));\
-	*len += offsetof(vheader,isnull);\
-	\
-	vt->header.isnull = palloc(vh->dim * sizeof(bool));\
-	memcpy(vt->header.isnull, buf + *len,vh->dim * sizeof(bool));\
-	*len += vh->dim * sizeof(bool);\
-	\
-	memcpy(vt->values,buf + *len,vh->dim * sizeof(type)); \
-	*len += vh->dim * sizeof(type); \
-	\
-	return PointerGetDatum(vt); \
-}
-
-/*
- * IN function for the abstract data types
- * e.g. Datum vint2in(PG_FUNCTION_ARGS)
- */
-#define FUNCTION_IN(type, typeoid, MACRO_DATUM) \
-PG_FUNCTION_INFO_V1(v##type##in); \
-Datum \
-v##type##in(PG_FUNCTION_ARGS) \
-{ \
-    char *intString = PG_GETARG_CSTRING(0); \
-    v##type *res = NULL; \
-    char tempstr[MAX_NUM_LEN] = {0}; \
-    int n = 0; \
-    res = palloc0(offsetof(v##type, values) + (MAX_VECTOR_SIZE) * sizeof(type)); \
-    for (n = 0; *intString && n < MAX_VECTOR_SIZE; n++) \
-    { \
-    	    char *start = NULL;\
-        while (*intString && isspace((unsigned char) *intString)) \
-            intString++; \
-        if (*intString == '\0') \
-            break; \
-        start = intString; \
-        while ((*intString && !isspace((unsigned char) *intString)) && *intString != '\0') \
-            intString++; \
-        Assert(intString - start < MAX_NUM_LEN); \
-        strncpy(tempstr, start, intString - start); \
-        tempstr[intString - start] = 0; \
-        res->values[n] =  MACRO_DATUM(DirectFunctionCall1(type##in, CStringGetDatum(tempstr))); \
-        while (*intString && !isspace((unsigned char) *intString)) \
-            intString++; \
-    } \
-    while (*intString && isspace((unsigned char) *intString)) \
-        intString++; \
-    if (*intString) \
-        ereport(ERROR, \
-        (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
-                errmsg("int2vector has too many elements"))); \
-    SET_VARSIZE(res, (offsetof(v##type, values) + n * sizeof(type))); \
-    res->header.elemtype = typeoid; \
-    res->header.dim = n; \
-    res->header.isnull = palloc0(sizeof(bool) * n); \
-    PG_RETURN_POINTER(res); \
-}
-
-/*
- * OUT function for the abstract data types
- * e.g. Datum vint2out(PG_FUNCTION_ARGS)
- */
-#define FUNCTION_OUT(type, typeoid, MACRO_DATUM) \
-PG_FUNCTION_INFO_V1(v##type##out); \
-Datum \
-v##type##out(PG_FUNCTION_ARGS) \
-{ \
-	v##type * arg1 = (v##type *) PG_GETARG_POINTER(0); \
-	int len = arg1->header.dim; \
-    int i = 0; \
-	char *rp; \
-	char *result; \
-	rp = result = (char *) palloc0(len * MAX_NUM_LEN + 1); \
-	for (i = 0; i < len; i++) \
-	{ \
-		if (i != 0) \
-			*rp++ = ' '; \
-		strcat(rp, DatumGetCString(DirectFunctionCall1(type##out, MACRO_DATUM(arg1->values[i]))));\
-		while (*++rp != '\0'); \
-	} \
-	*rp = '\0'; \
-	PG_RETURN_CSTRING(result); \
-}
-
-/*
- * Operator function for the abstract data types, this MACRO is used for the 
- * V-types OP V-types.
- * e.g. extern Datum vint2vint2pl(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_OP(type1, type2, opsym, opstr) \
-PG_FUNCTION_INFO_V1(v##type1##v##type2##opstr); \
-Datum \
-v##type1##v##type2##opstr(PG_FUNCTION_ARGS) \
-{ \
-    int size = 0; \
-    int i = 0; \
-    v##type1 *arg1 = PG_GETARG_POINTER(0); \
-    v##type2 *arg2 = PG_GETARG_POINTER(1); \
-    Assert((arg1)->header.dim == (arg2)->header.dim); \
-    size = (arg1)->header.dim; \
-    if(sizeof(type1) > sizeof(type2)) \
-    { \
-        v##type1 *res = NULL; \
-        res = (v##type1 *)buildv##type1(size); \
-        while(i < size) \
-        { \
-            res->header.isnull[i] = \
-                arg1->header.isnull[i] || arg2->header.isnull[i]; \
-            if(!res->header.isnull[i]) \
-                res->values[i] = arg1->values[i] opsym arg2->values[i]; \
-            i++; \
-        } \
-        PG_RETURN_POINTER(res); \
-    } \
-    else \
-    { \
-        v##type2 *res = NULL; \
-        res = (v##type2 *)buildv##type2(size); \
-        while(i < size) \
-        { \
-            res->header.isnull[i] = \
-                arg1->header.isnull[i] || arg2->header.isnull[i]; \
-            if(!res->header.isnull[i]) \
-                res->values[i] = arg1->values[i] opsym arg2->values[i]; \
-            i++; \
-        } \
-        PG_RETURN_POINTER(res); \
-    } \
-}
-
-/*
- * Operator function for the abstract data types, this MACRO is used for the 
- * V-types OP Consts.
- * e.g. extern Datum vint2int2pl(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO, opsym, opstr) \
-PG_FUNCTION_INFO_V1(v##type##const_type##opstr); \
-Datum \
-v##type##const_type##opstr(PG_FUNCTION_ARGS) \
-{ \
-    int size = 0; \
-    int i = 0; \
-    v##type *arg1 = PG_GETARG_POINTER(0); \
-    const_type arg2 = CONST_ARG_MACRO(1); \
-    v##type *res = NULL; \
-    size = (arg1)->header.dim; \
-    res = (v##type *)buildv##type(size); \
-    while(i < size) \
-    { \
-        res->header.isnull[i] = (arg1)->header.isnull[i]; \
-        if(!res->header.isnull[i]) \
-            res->values[i] = arg1->values[i] opsym arg2; \
-        i ++ ;\
-    } \
-    PG_RETURN_POINTER(res); \
-}
-
-/*
- * Comparision function for the abstract data types, this MACRO is used for the 
- * V-types OP V-types.
- * e.g. extern Datum vint2vint2eq(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_CMP(type1, type2, cmpsym, cmpstr) \
-PG_FUNCTION_INFO_V1(v##type1##v##type2##cmpstr); \
-Datum \
-v##type1##v##type2##cmpstr(PG_FUNCTION_ARGS) \
-{ \
-    int size = 0; \
-    int i = 0; \
-    v##type1 *arg1 = PG_GETARG_POINTER(0); \
-    v##type2 *arg2 = PG_GETARG_POINTER(1); \
-    vbool *res = NULL; \
-    size = (arg1)->header.dim; \
-    res = (vbool*)buildvbool(size); \
-    while(i < size) \
-    { \
-         res->header.isnull[i] =  \
-            arg1->header.isnull[i] || arg2->header.isnull[i]; \
-        if(!res->header.isnull[i]) \
-            res->values[i] = arg1->values[i] cmpsym arg2->values[i]; \
-        i++; \
-    } \
-    PG_RETURN_POINTER(res); \
-}
-
-/*
- * Comparision function for the abstract data types, this MACRO is used for the 
- * V-types OP Consts.
- * e.g. extern Datum vint2int2eq(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO, cmpsym, cmpstr) \
-PG_FUNCTION_INFO_V1(v##type##const_type##cmpstr); \
-Datum \
-v##type##const_type##cmpstr(PG_FUNCTION_ARGS) \
-{ \
-    int size = 0; \
-    int i = 0; \
-    v##type *arg1 = PG_GETARG_POINTER(0); \
-    const_type arg2 = CONST_ARG_MACRO(1); \
-    vbool *res = NULL; \
-    size = (arg1)->header.dim; \
-    res = (vbool*)buildvbool(size); \
-    while(i < size) \
-    { \
-        res->header.isnull[i] = (arg1)->header.isnull[i]; \
-        if(!res->header.isnull[i]) \
-            res->values[i] = arg1->values[i] cmpsym arg2; \
-        i++; \
-    } \
-    PG_RETURN_POINTER(res); \
-}
-
-/* Implement the functions for the all data types by the upper BASE MARCO.*/
-#define _FUNCTION_OP(type1, type2) \
-    __FUNCTION_OP(type1, type2, +, pl)  \
-    __FUNCTION_OP(type1, type2, -, mi)  \
-    __FUNCTION_OP(type1, type2, *, mul) \
-    __FUNCTION_OP(type1, type2, /, div)
-
-#define FUNCTION_OP(type) \
-    _FUNCTION_OP(type, int2) \
-    _FUNCTION_OP(type, int4) \
-    _FUNCTION_OP(type, int8) \
-    _FUNCTION_OP(type, float4) \
-    _FUNCTION_OP(type, float8)
-
-
-#define _FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO) \
-    __FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO, +, pl)  \
-    __FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO, -, mi)  \
-    __FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO, *, mul) \
-    __FUNCTION_OP_RCONST(type, const_type, CONST_ARG_MACRO, /, div)
-
-
-#define FUNCTION_OP_RCONST(type) \
-    _FUNCTION_OP_RCONST(type, int2, PG_GETARG_INT16) \
-    _FUNCTION_OP_RCONST(type, int4, PG_GETARG_INT32) \
-    _FUNCTION_OP_RCONST(type, int8, PG_GETARG_INT64) \
-    _FUNCTION_OP_RCONST(type, float4, PG_GETARG_FLOAT4) \
-    _FUNCTION_OP_RCONST(type, float8, PG_GETARG_FLOAT8)
-
-
-#define _FUNCTION_CMP(type1, type2) \
-    __FUNCTION_CMP(type1, type2, ==, eq) \
-    __FUNCTION_CMP(type1, type2, !=, ne) \
-    __FUNCTION_CMP(type1, type2, >, gt) \
-    __FUNCTION_CMP(type1, type2, >=, ge) \
-    __FUNCTION_CMP(type1, type2, <, lt) \
-    __FUNCTION_CMP(type1, type2, <=, le)
-
-#define FUNCTION_CMP(type1) \
-    _FUNCTION_CMP(type1, int2) \
-    _FUNCTION_CMP(type1, int4) \
-    _FUNCTION_CMP(type1, int8) \
-    _FUNCTION_CMP(type1, float4) \
-    _FUNCTION_CMP(type1, float8)
-
-
-#define _FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO) \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO, ==, eq)  \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO, !=, ne)  \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO,  >, gt) \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO, >=, ge) \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO,  <, lt) \
-    __FUNCTION_CMP_RCONST(type, const_type, CONST_ARG_MACRO, <=, le) \
-
-#define FUNCTION_CMP_RCONST(type) \
-    _FUNCTION_CMP_RCONST(type, int2, PG_GETARG_INT16) \
-    _FUNCTION_CMP_RCONST(type, int4, PG_GETARG_INT32) \
-    _FUNCTION_CMP_RCONST(type, int8, PG_GETARG_INT64) \
-    _FUNCTION_CMP_RCONST(type, float4, PG_GETARG_FLOAT4) \
-    _FUNCTION_CMP_RCONST(type, float8, PG_GETARG_FLOAT8)
-
-#define FUNCTION_OP_ALL(type) \
-    FUNCTION_OP(type) \
-    FUNCTION_OP_RCONST(type) \
-    FUNCTION_CMP(type) \
-    FUNCTION_CMP_RCONST(type) 
-
-#define FUNCTION_GETPTR(type) \
-type* getptrv##type(vheader *header,int n) \
-{\
-	if(n < 0 || n > header->dim) return NULL; \
-	v##type* ptr = (v##type *) header; \
-	return ptr->values + n; \
-}
-
-#define FUNCTION_GETVALUE(type) \
-void getvaluev##type(vheader *header,int n,Datum *ptr) \
-{ \
-	if(n < 0 || n > header->dim) return;\
-	*ptr = ((v##type*)header)->values[n];\
-}
-
-#define TYPE_DEFINE(type, typeoid) \
-    FUNCTION_VTYPESIZE(type) \
-    FUNCTION_OP_ALL(type) \
-    FUNCTION_BUILD(type, typeoid) \
-    FUNCTION_DESTORY(type, typeoid) \
-    FUNCTION_GETPTR(type) \
-    FUNCTION_GETVALUE(type) \
-    FUNCTION_SERIALIZATION(type,typeoid) \
-
-/* These MACRO will be expanded when the code is compiled. */
-TYPE_DEFINE(int2, INT2OID)
-TYPE_DEFINE(int4, INT4OID)
-TYPE_DEFINE(int8, INT8OID)
-TYPE_DEFINE(float4, FLOAT4OID)
-TYPE_DEFINE(float8, FLOAT8OID)
-TYPE_DEFINE(bool, BOOLOID)
-
-FUNCTION_IN(int2, INT2OID, DatumGetInt16)
-FUNCTION_IN(int4, INT4OID, DatumGetInt32)
-FUNCTION_IN(int8, INT8OID, DatumGetInt64)
-FUNCTION_IN(float4, FLOAT4OID, DatumGetFloat4)
-FUNCTION_IN(float8, FLOAT8OID, DatumGetFloat8)
-FUNCTION_IN(bool, BOOLOID, DatumGetBool)
-
-FUNCTION_OUT(int2, INT2OID, Int16GetDatum)
-FUNCTION_OUT(int4, INT4OID, Int32GetDatum)
-FUNCTION_OUT(int8, INT8OID, Int64GetDatum)
-FUNCTION_OUT(float4, FLOAT4OID, Float4GetDatum)
-FUNCTION_OUT(float8, FLOAT8OID, Float8GetDatum)
-FUNCTION_OUT(bool, BOOLOID, BoolGetDatum)

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vadt.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vadt.h b/contrib/vexecutor/vadt.h
deleted file mode 100644
index c8ad3f8..0000000
--- a/contrib/vexecutor/vadt.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#ifndef __VADT_H__
-#define __VADT_H__
-
-#include "postgres.h"
-#include "fmgr.h"
-
-#define MAX_VECTOR_SIZE 1024
-
-/* 
- * Vectorized abstract data types headers
- */
-#define VADT_HEADER() \
-	typedef struct vheader \
-	{ \
-		int _vl_len; \
-		Oid elemtype; \
-		int dim; \
-		bool *isnull; \
-	}vheader;
-
-/* 
- * Vectorized abstract data types,
- */
-#define VADT_STRUCT(type) \
-	typedef struct v##type \
-	{ \
-		vheader header; \
-		type values[0]; \
-	}v##type;
-
-/* MACRO "HEADER" is used to the functions declare */
-
-/* Get the size of vectorized data */
-#define FUNCTION_VTYPESIZE_HEADER(type) \
-extern size_t v##type##Size(vheader *vh); 
-
-/* Build the vectorized data */
-#define FUNCTION_BUILD_HEADER(type, typeoid) \
-extern vheader* buildv##type(int n);
-
-/* Destroy the vectorized data */
-#define FUNCTION_DESTORY_HEADER(type, typeoid) \
-extern void destroyv##type(vheader **header);
-
-/* Get a column data pointer */
-#define FUNCTION_GETPTR_HEADER(type) \
-extern type* getptrv##type(vheader *header,int n);
-
-/* Get a column data */
-#define FUNCTION_GETVALUE_HEADER(type) \
-extern void getvaluev##type(vheader *header,int n,Datum *ptr);
-/*
- * IN function for the abstract data types
- * e.g. Datum vint2in(PG_FUNCTION_ARGS)
- */
-#define FUNCTION_IN_HEADER(type, typeoid) \
-extern Datum v##type##in(PG_FUNCTION_ARGS);
-
-/*
- * OUT function for the abstract data types
- * e.g. Datum vint2out(PG_FUNCTION_ARGS)
- */
-#define FUNCTION_OUT_HEADER(type, typeoid) \
-extern Datum v##type##out(PG_FUNCTION_ARGS);
-
-/*
- * Operator function for the abstract data types, this MACRO is used for the 
- * V-types OP V-types.
- * e.g. extern Datum vint2vint2pl(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_OP_HEADER(type1, type2, opsym, opstr) \
-extern Datum v##type1##v##type2##opstr(PG_FUNCTION_ARGS);
-
-/*
- * Operator function for the abstract data types, this MACRO is used for the 
- * V-types OP Consts.
- * e.g. extern Datum vint2int2pl(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, opsym, opstr) \
-extern Datum v##type##const_type##opstr(PG_FUNCTION_ARGS);
-
-/*
- * Comparision function for the abstract data types, this MACRO is used for the 
- * V-types OP V-types.
- * e.g. extern Datum vint2vint2eq(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_CMP_HEADER(type1, type2, cmpsym, cmpstr) \
-extern Datum v##type1##v##type2##cmpstr(PG_FUNCTION_ARGS);
-
-/*
- * Comparision function for the abstract data types, this MACRO is used for the 
- * V-types OP Consts.
- * e.g. extern Datum vint2int2eq(PG_FUNCTION_ARGS);
- */
-#define __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, cmpsym, cmpstr) \
-extern Datum v##type##const_type##cmpstr(PG_FUNCTION_ARGS);
-
-/*
- * Serialize functions and deserialize functions for the abstract data types
- */
-#define FUNCTION_SERIALIZATION_HEADER(type,typeoid) \
-extern size_t v##type##serialization(vheader* vh,unsigned char *buf); \
-extern Datum v##type##deserialization(unsigned char* buf,size_t* len); \
-
-
-
-/* Implement the functions for the all data types by the upper BASE MARCO.*/
-#define _FUNCTION_OP_HEADER(type1, type2) \
-    __FUNCTION_OP_HEADER(type1, type2, +, pl)  \
-    __FUNCTION_OP_HEADER(type1, type2, -, mi)  \
-    __FUNCTION_OP_HEADER(type1, type2, *, mul) \
-    __FUNCTION_OP_HEADER(type1, type2, /, div)
-
-#define FUNCTION_OP_HEADER(type) \
-    _FUNCTION_OP_HEADER(type, int2) \
-    _FUNCTION_OP_HEADER(type, int4) \
-    _FUNCTION_OP_HEADER(type, int8) \
-    _FUNCTION_OP_HEADER(type, float4) \
-    _FUNCTION_OP_HEADER(type, float8)
-
-
-#define _FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO) \
-    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, +, pl)  \
-    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, -, mi)  \
-    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, *, mul) \
-    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, /, div)
-
-
-#define FUNCTION_OP_RCONST_HEADER(type) \
-    _FUNCTION_OP_RCONST_HEADER(type, int2, PG_GETARG_INT16) \
-    _FUNCTION_OP_RCONST_HEADER(type, int4, PG_GETARG_INT32) \
-    _FUNCTION_OP_RCONST_HEADER(type, int8, PG_GETARG_INT64) \
-    _FUNCTION_OP_RCONST_HEADER(type, float4, PG_GETARG_FLOAT4) \
-    _FUNCTION_OP_RCONST_HEADER(type, float8, PG_GETARG_FLOAT8)
-
-
-#define _FUNCTION_CMP_HEADER(type1, type2) \
-    __FUNCTION_CMP_HEADER(type1, type2, ==, eq) \
-    __FUNCTION_CMP_HEADER(type1, type2, !=, ne) \
-    __FUNCTION_CMP_HEADER(type1, type2, >, gt) \
-    __FUNCTION_CMP_HEADER(type1, type2, >=, ge) \
-    __FUNCTION_CMP_HEADER(type1, type2, <, lt) \
-    __FUNCTION_CMP_HEADER(type1, type2, <=, le)
-
-#define FUNCTION_CMP_HEADER(type1) \
-    _FUNCTION_CMP_HEADER(type1, int2) \
-    _FUNCTION_CMP_HEADER(type1, int4) \
-    _FUNCTION_CMP_HEADER(type1, int8) \
-    _FUNCTION_CMP_HEADER(type1, float4) \
-    _FUNCTION_CMP_HEADER(type1, float8)
-
-
-#define _FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO) \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, ==, eq)  \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, !=, ne)  \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO,  >, gt) \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, >=, ge) \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO,  <, lt) \
-    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, <=, le) 
-
-#define FUNCTION_CMP_RCONST_HEADER(type) \
-    _FUNCTION_CMP_RCONST_HEADER(type, int2, PG_GETARG_INT16) \
-    _FUNCTION_CMP_RCONST_HEADER(type, int4, PG_GETARG_INT32) \
-    _FUNCTION_CMP_RCONST_HEADER(type, int8, PG_GETARG_INT64) \
-    _FUNCTION_CMP_RCONST_HEADER(type, float4, PG_GETARG_FLOAT4) \
-    _FUNCTION_CMP_RCONST_HEADER(type, float8, PG_GETARG_FLOAT8)
-
-#define FUNCTION_OP_ALL_HEADER(type) \
-    FUNCTION_OP_HEADER(type) \
-    FUNCTION_OP_RCONST_HEADER(type) \
-    FUNCTION_CMP_HEADER(type) \
-    FUNCTION_CMP_RCONST_HEADER(type) \
-    FUNCTION_VTYPESIZE_HEADER(type) 
-
-
-#define TYPE_HEADER(type, typeoid) \
-    VADT_BUILD(type) \
-    FUNCTION_GETPTR_HEADER(type)\
-    FUNCTION_GETVALUE_HEADER(type) \
-    FUNCTION_OP_ALL_HEADER(type) \
-    FUNCTION_IN_HEADER(type, typeoid) \
-    FUNCTION_OUT_HEADER(type, typeoid) \
-    FUNCTION_BUILD_HEADER(type, typeoid) \
-    FUNCTION_DESTORY_HEADER(type, typeoid) \
-    FUNCTION_SERIALIZATION_HEADER(type,typeoid) \
-
-#define VADT_BUILD(type) \
-    VADT_STRUCT(type) \
-    FUNCTION_VTYPESIZE_HEADER(type)
-
-/* These MACRO will be expanded when the code is compiled. */
-VADT_HEADER()
-TYPE_HEADER(int2, INT2OID)
-TYPE_HEADER(int4, INT4OID)
-TYPE_HEADER(int8, INT8OID)
-TYPE_HEADER(float4, FLOAT4OID)
-TYPE_HEADER(float8, FLOAT8OID)
-TYPE_HEADER(bool, BOOLOID)
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vcheck.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vcheck.c b/contrib/vexecutor/vcheck.c
index 7e1a591..788cc19 100644
--- a/contrib/vexecutor/vcheck.c
+++ b/contrib/vexecutor/vcheck.c
@@ -30,37 +30,11 @@
 #include "nodes/relation.h"
 #include "optimizer/walkers.h"
 #include "utils/lsyscache.h"
+#include "utils/syscache.h"
 #include "vcheck.h"
-#include "vadt.h"
 #include "vexecutor.h"
 
 
-static const vFuncMap funcMap[] = {
-		{INT2OID, &buildvint2, &destroyvint2, &getptrvint2,&getvaluevint2,&vint2Size,&vint2serialization,&vint2deserialization},
-		{INT4OID, &buildvint4, &destroyvint4, &getptrvint4,&getvaluevint4,&vint4Size,&vint4serialization,&vint4deserialization},
-		{INT8OID, &buildvint8, &destroyvint8, &getptrvint8,&getvaluevint8,&vint8Size,&vint8serialization,&vint8deserialization},
-		{FLOAT4OID, &buildvfloat4, &destroyvfloat4, &getptrvfloat4,&getvaluevfloat4,&vfloat4Size,&vfloat4serialization,&vfloat4deserialization},
-		{FLOAT8OID, &buildvfloat8, &destroyvfloat8, &getptrvfloat8,&getvaluevfloat8,&vfloat8Size,&vfloat8serialization,&vfloat8deserialization},
-		{BOOLOID, &buildvbool, &destroyvbool, &getptrvbool,&getvaluevbool,&vboolSize,&vboolserialization,&vbooldeserialization}
-};
-static const int funcMapLen = sizeof(funcMap) /sizeof(vFuncMap);
-
-static const vFuncMap* vFuncWalker(Oid type)
-{
-	for(int i = 0;i < funcMapLen; i ++)
-		if(funcMap[i].ntype == type) return &funcMap[i];
-
-	return NULL;
-}
-
-static HTAB *hashMapVFunc = NULL;
-
-typedef struct VecFuncHashEntry
-{
-	Oid src;
-	vFuncMap *vFunc;
-} VecFuncHashEntry;
-
 typedef struct VecTypeHashEntry
 {
 	Oid src;
@@ -69,6 +43,8 @@ typedef struct VecTypeHashEntry
 
 /* Map between the vectorized types and non-vectorized types */
 static HTAB *hashMapN2V = NULL;
+/* Map between the vectorized types and non-vectorized types */
+static HTAB *hashMapV2N = NULL;
 
 /*
  * We check the expressions tree recursively becuase the args can be a sub expression,
@@ -345,31 +321,31 @@ Oid GetVtype(Oid ntype)
 /*
  * Get the functions for the vectorized types
  */
-const vFuncMap* GetVFunc(Oid vtype){
+Oid GetNtype(Oid vtype){
 	HeapTuple tuple;
 	bool isNull = true;
 	cqContext *pcqCtx;
-	VecFuncHashEntry *entry = NULL;
+	VecTypeHashEntry *entry = NULL;
 	Oid ntype;
 	bool found = false;
 
 	//construct the hash table
-	if(NULL == hashMapVFunc)
+	if(NULL == hashMapV2N)
 	{
 		HASHCTL	hash_ctl;
 		MemSet(&hash_ctl, 0, sizeof(hash_ctl));
 
 		hash_ctl.keysize = sizeof(Oid);
-		hash_ctl.entrysize = sizeof(VecFuncHashEntry);
+		hash_ctl.entrysize = sizeof(VecTypeHashEntry);
 		hash_ctl.hash = oid_hash;
 
-		hashMapVFunc = hash_create("hashvfunc", 64/*enough?*/, &hash_ctl, HASH_ELEM | HASH_FUNCTION);
+		hashMapV2N = hash_create("hashvfunc", 64/*enough?*/, &hash_ctl, HASH_ELEM | HASH_FUNCTION);
 	}
 
 	//first, find the vectorized type in hash table
-	entry = hash_search(hashMapVFunc, &vtype, HASH_ENTER, &found);
+	entry = hash_search(hashMapV2N, &vtype, HASH_ENTER, &found);
 	if(found)
-		return entry->vFunc;
+		return entry->dest;
 
 	Assert(!found);
 
@@ -383,7 +359,7 @@ const vFuncMap* GetVFunc(Oid vtype){
 	if(!HeapTupleIsValid(tuple))
 	{
 		caql_endscan(pcqCtx);
-		return NULL;
+		return InvalidOid;
 	}
 
 	ntype = caql_getattr(pcqCtx,
@@ -392,10 +368,10 @@ const vFuncMap* GetVFunc(Oid vtype){
 	Assert(!isNull);
 
 	/* storage in hash table*/
-	entry->vFunc = vFuncWalker(ntype);
+	entry->dest = ntype;
 
 	caql_endscan(pcqCtx);
 
-	return entry->vFunc ;
+	return entry->dest;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vcheck.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vcheck.h b/contrib/vexecutor/vcheck.h
index bbeb9bc..1edc2e8 100644
--- a/contrib/vexecutor/vcheck.h
+++ b/contrib/vexecutor/vcheck.h
@@ -20,19 +20,8 @@
 #ifndef VCHECK_H
 #define VCHECK_H
 
-#include "vadt.h"
+#include "vtype.h"
 #include "nodes/execnodes.h"
-typedef struct vFuncMap
-{
-	Oid ntype;
-	vheader* (* vtbuild)(int n);
-	void (* vtfree)(vheader **vh);
-	Datum (* gettypeptr)(vheader *vh,int n);
-	void (* gettypevalue)(vheader *vh,int n,Datum *ptr);
-	size_t (* vtsize)(vheader *vh);
-	size_t (*serialization)(vheader* vh, unsigned char* buf);
-	Datum (*deserialization)(unsigned char* buf,size_t* len);
-}vFuncMap;
 
 typedef struct aoinfo {
 	bool* proj;
@@ -48,8 +37,8 @@ typedef struct VectorizedState
 }VectorizedState;
 
 
-extern const vFuncMap* GetVFunc(Oid vtype);
 extern Plan* CheckAndReplacePlanVectorized(PlannerInfo *root, Plan *plan);
 extern Oid GetVtype(Oid ntype);
+extern Oid GetNtype(Oid vtype);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vexecutor.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vexecutor.c b/contrib/vexecutor/vexecutor.c
index 9f5506f..de82909 100644
--- a/contrib/vexecutor/vexecutor.c
+++ b/contrib/vexecutor/vexecutor.c
@@ -59,7 +59,7 @@ _PG_init(void)
 	vmthd.ExecVecNode_Hook = VExecVecNode;
 	vmthd.ExecProcNode_Hook = VExecProcNode;
 	vmthd.ExecEndNode_Hook = VExecEndNode;
-	vmthd.GetNType = GetNType;
+	vmthd.GetNType = GetNtype;
 	DefineCustomBoolVariable("vectorized_executor_enable",
 	                         gettext_noop("enable vectorized executor"),
 	                         NULL,
@@ -106,7 +106,7 @@ static void backportTupleDescriptor(PlanState* ps,TupleDesc td)
 	Form_pg_type  typeForm;
 	for(int i = 0;i < td->natts; ++i)
 	{
-		oidtypeid = GetVFunc(td->attrs[i]->atttypid)->ntype;
+		oidtypeid = GetNtype(td->attrs[i]->atttypid);
 
 		pcqCtx = caql_beginscan(
 				NULL,
@@ -257,8 +257,3 @@ HasVecExecOprator(NodeTag tag)
 	return result;
 }
 
-Oid GetNType(Oid vtype)
-{
-	const vFuncMap* vf = GetVFunc(vtype);
-	return vf == NULL ? InvalidOid : vf->ntype;
-}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vexecutor.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vexecutor.h b/contrib/vexecutor/vexecutor.h
index fdc3219..06fbd6a 100644
--- a/contrib/vexecutor/vexecutor.h
+++ b/contrib/vexecutor/vexecutor.h
@@ -23,13 +23,12 @@
 #include "postgres.h"
 #include "fmgr.h"
 #include "executor/executor.h"
-#include "vadt.h"
+#include "vtype.h"
 
 /* Function declarations for extension loading and unloading */
 extern void _PG_init(void);
 extern void _PG_fini(void);
 
 extern bool HasVecExecOprator(NodeTag tag);
-Oid GetNType(Oid vtype);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vtype.c
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vtype.c b/contrib/vexecutor/vtype.c
new file mode 100644
index 0000000..89c6556
--- /dev/null
+++ b/contrib/vexecutor/vtype.c
@@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "postgres.h"
+#include "catalog/pg_type.h"
+#include "utils/builtins.h"
+#include "vtype.h"
+
+#define MAX_NUM_LEN 64
+extern int BATCHSIZE;
+const char canary = 0xe7;
+
+vtype* buildvtype(Oid elemtype,int dim,bool *skip)
+{
+    vtype *res;
+    res = palloc0(VTYPESIZE(dim));
+    res->dim = dim;
+    res->elemtype = elemtype;
+
+    *CANARYOFFSET(res) = canary;
+    res->isnull = ISNULLOFFSET(res);
+    res->skipref = skip;
+
+    SET_VARSIZE(res, VTYPESIZE(dim));
+
+    return res;
+}
+
+void destroyvtype(vtype** vt)
+{
+    pfree((*vt));
+    *vt = NULL;
+}
+
+#define _FUNCTION_BUILD(type, typeoid) \
+v##type* buildv##type(int dim, bool *skip) \
+{ \
+    return buildvtype(typeoid, dim, skip); \
+}
+
+/*
+ * IN function for the abstract data types
+ * e.g. Datum vint2in(PG_FUNCTION_ARGS)
+ */
+#define _FUNCTION_IN(type, typeoid) \
+PG_FUNCTION_INFO_V1(v##type##in); \
+Datum \
+v##type##in(PG_FUNCTION_ARGS) \
+{ \
+    char *intString = PG_GETARG_CSTRING(0); \
+    vtype *res = NULL; \
+    char tempstr[MAX_NUM_LEN] = {0}; \
+    int n = 0; \
+    res = buildvtype(typeoid,BATCHSIZE,NULL);\
+    for (n = 0; *intString && n < BATCHSIZE; n++) \
+    { \
+    	    char *start = NULL;\
+        while (*intString && isspace((unsigned char) *intString)) \
+            intString++; \
+        if (*intString == '\0') \
+            break; \
+        start = intString; \
+        while ((*intString && !isspace((unsigned char) *intString)) && *intString != '\0') \
+            intString++; \
+        Assert(intString - start < MAX_NUM_LEN); \
+        strncpy(tempstr, start, intString - start); \
+        tempstr[intString - start] = 0; \
+        res->values[n] = DirectFunctionCall1(type##in, CStringGetDatum(tempstr)); \
+        while (*intString && !isspace((unsigned char) *intString)) \
+            intString++; \
+    } \
+    while (*intString && isspace((unsigned char) *intString)) \
+        intString++; \
+    if (*intString) \
+        ereport(ERROR, \
+        (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
+                errmsg("int2vector has too many elements"))); \
+    res->elemtype = typeoid; \
+    res->dim = n; \
+    SET_VARSIZE(res, VTYPESIZE(n)); \
+    PG_RETURN_POINTER(res); \
+}
+
+/*
+ * OUT function for the abstract data types
+ * e.g. Datum vint2out(PG_FUNCTION_ARGS)
+ */
+#define _FUNCTION_OUT(type, typeoid) \
+PG_FUNCTION_INFO_V1(v##type##out); \
+Datum \
+v##type##out(PG_FUNCTION_ARGS) \
+{ \
+	vtype * arg1 = (v##type *) PG_GETARG_POINTER(0); \
+	int len = arg1->dim; \
+    int i = 0; \
+	char *rp; \
+	char *result; \
+	rp = result = (char *) palloc0(len * MAX_NUM_LEN + 1); \
+	for (i = 0; i < len; i++) \
+	{ \
+		if (i != 0) \
+			*rp++ = ' '; \
+		strcat(rp, DatumGetCString(DirectFunctionCall1(type##out, arg1->values[i])));\
+		while (*++rp != '\0'); \
+	} \
+	*rp = '\0'; \
+	PG_RETURN_CSTRING(result); \
+}
+
+/*
+ * Operator function for the abstract data types, this MACRO is used for the 
+ * V-types OP V-types.
+ * e.g. extern Datum vint2vint2pl(PG_FUNCTION_ARGS);
+ * NOTE:we assum that return type is same with the type of arg1,
+ * we have not processed the overflow so far.
+ */
+#define __FUNCTION_OP(type1, XTYPE1, type2, XTYPE2, opsym, opstr) \
+PG_FUNCTION_INFO_V1(v##type1##v##type2##opstr); \
+Datum \
+v##type1##v##type2##opstr(PG_FUNCTION_ARGS) \
+{ \
+    int size = 0; \
+    int i = 0; \
+    v##type1 *arg1 = PG_GETARG_POINTER(0); \
+    v##type2 *arg2 = PG_GETARG_POINTER(1); \
+    v##type1 *res = buildv##type1(BATCHSIZE, NULL); \
+    Assert(arg1->dim == arg2->dim); \
+    size = arg1->dim; \
+    while(i < size) \
+    { \
+        res->isnull[i] = arg1->isnull[i] || arg2->isnull[i]; \
+        if(!res->isnull[i]) \
+            res->values[i] = XTYPE1##GetDatum((DatumGet##XTYPE1(arg1->values[i])) opsym (DatumGet##XTYPE2(arg2->values[i]))); \
+        i++; \
+    } \
+    res->dim = arg1->dim; \
+    PG_RETURN_POINTER(res); \
+}
+
+/*
+ * Operator function for the abstract data types, this MACRO is used for the 
+ * V-types OP Consts.
+ * e.g. extern Datum vint2int2pl(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, opsym, opstr) \
+PG_FUNCTION_INFO_V1(v##type##const_type##opstr); \
+Datum \
+v##type##const_type##opstr(PG_FUNCTION_ARGS) \
+{ \
+    int size = 0; \
+    int i = 0; \
+    v##type *arg1 = PG_GETARG_POINTER(0); \
+    const_type arg2 = CONST_ARG_MACRO(1); \
+    v##type *res = buildv##type(BATCHSIZE, NULL); \
+    size = arg1->dim;\
+    while(i < size) \
+    { \
+        res->isnull[i] = arg1->isnull[i]; \
+        if(!res->isnull[i]) \
+            res->values[i] = XTYPE##GetDatum((DatumGet##XTYPE(arg1->values[i])) opsym ((type)arg2)); \
+        i ++ ;\
+    } \
+    res->dim = arg1->dim; \
+    PG_RETURN_POINTER(res); \
+}
+
+/*
+ * Comparision function for the abstract data types, this MACRO is used for the 
+ * V-types OP V-types.
+ * e.g. extern Datum vint2vint2eq(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, cmpsym, cmpstr) \
+PG_FUNCTION_INFO_V1(v##type1##v##type2##cmpstr); \
+Datum \
+v##type1##v##type2##cmpstr(PG_FUNCTION_ARGS) \
+{ \
+    int size = 0; \
+    int i = 0; \
+    v##type1 *arg1 = PG_GETARG_POINTER(0); \
+    v##type2 *arg2 = PG_GETARG_POINTER(1); \
+    Assert(arg1->dim == arg2->dim); \
+    vbool *res = buildvtype(BOOLOID, BATCHSIZE, NULL); \
+    size = arg1->dim; \
+    while(i < size) \
+    { \
+        res->isnull[i] = arg1->isnull[i] || arg2->isnull[i]; \
+        if(!res->isnull[i]) \
+            res->values[i] = BoolGetDatum(DatumGet##XTYPE1(arg1->values[i]) cmpsym (DatumGet##XTYPE2(arg2->values[i]))); \
+        i++; \
+    } \
+    res->dim = arg1->dim; \
+    PG_RETURN_POINTER(res); \
+}
+
+/*
+ * Comparision function for the abstract data types, this MACRO is used for the 
+ * V-types OP Consts.
+ * e.g. extern Datum vint2int2eq(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, cmpsym, cmpstr) \
+PG_FUNCTION_INFO_V1(v##type##const_type##cmpstr); \
+Datum \
+v##type##const_type##cmpstr(PG_FUNCTION_ARGS) \
+{ \
+    int size = 0; \
+    int i = 0; \
+    v##type *arg1 = PG_GETARG_POINTER(0); \
+    const_type arg2 = CONST_ARG_MACRO(1); \
+    vbool *res = buildvtype(BOOLOID, BATCHSIZE, NULL); \
+    size = arg1->dim; \
+    while(i < size) \
+    { \
+        res->isnull[i] = arg1->isnull[i]; \
+        if(!res->isnull[i]) \
+            res->values[i] = BoolGetDatum((DatumGet##XTYPE(arg1->values[i])) cmpsym arg2); \
+        i++; \
+    } \
+    res->dim = arg1->dim; \
+    PG_RETURN_POINTER(res); \
+}
+
+//Macro Level 3
+/* These MACRO will be expanded when the code is compiled. */
+#define _FUNCTION_OP(type1, XTYPE1, type2, XTYPE2) \
+    __FUNCTION_OP(type1, XTYPE1, type2, XTYPE2, +, pl)  \
+    __FUNCTION_OP(type1, XTYPE1, type2, XTYPE2, -, mi)  \
+    __FUNCTION_OP(type1, XTYPE1, type2, XTYPE2, *, mul) \
+    __FUNCTION_OP(type1, XTYPE1, type2, XTYPE2, /, div)
+
+#define _FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO) \
+    __FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, +, pl)  \
+    __FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, -, mi)  \
+    __FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, *, mul) \
+    __FUNCTION_OP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, /, div)
+
+#define _FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, ==, eq) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, !=, ne) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, >, gt) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, >=, ge) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, <, lt) \
+    __FUNCTION_CMP(type1, XTYPE1, type2, XTYPE2, <=, le)
+
+#define _FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO) \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, ==, eq)  \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, !=, ne)  \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO,  >, gt) \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, >=, ge) \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO,  <, lt) \
+    __FUNCTION_CMP_RCONST(type, XTYPE, const_type, CONST_ARG_MACRO, <=, le) \
+
+//Macro Level 2
+#define FUNCTION_OP(type, XTYPE1) \
+    _FUNCTION_OP(type, XTYPE1, int2, Int16) \
+    _FUNCTION_OP(type, XTYPE1, int4, Int32) \
+    _FUNCTION_OP(type, XTYPE1, int8, Int64) \
+    _FUNCTION_OP(type, XTYPE1, float4, Float4) \
+    _FUNCTION_OP(type, XTYPE1, float8, Float8)
+
+#define FUNCTION_OP_RCONST(type, XTYPE) \
+    _FUNCTION_OP_RCONST(type, XTYPE, int2, PG_GETARG_INT16) \
+    _FUNCTION_OP_RCONST(type, XTYPE, int4, PG_GETARG_INT32) \
+    _FUNCTION_OP_RCONST(type, XTYPE, int8, PG_GETARG_INT64) \
+    _FUNCTION_OP_RCONST(type, XTYPE, float4, PG_GETARG_FLOAT4) \
+    _FUNCTION_OP_RCONST(type, XTYPE, float8, PG_GETARG_FLOAT8)
+
+#define FUNCTION_CMP(type1, XTYPE1) \
+    _FUNCTION_CMP(type1, XTYPE1, int2, Int16) \
+    _FUNCTION_CMP(type1, XTYPE1, int4, Int32) \
+    _FUNCTION_CMP(type1, XTYPE1, int8, Int64) \
+    _FUNCTION_CMP(type1, XTYPE1, float4, Float4) \
+    _FUNCTION_CMP(type1, XTYPE1, float8, Float8)
+
+#define FUNCTION_CMP_RCONST(type, XTYPE) \
+    _FUNCTION_CMP_RCONST(type, XTYPE, int2, PG_GETARG_INT16) \
+    _FUNCTION_CMP_RCONST(type, XTYPE, int4, PG_GETARG_INT32) \
+    _FUNCTION_CMP_RCONST(type, XTYPE, int8, PG_GETARG_INT64) \
+    _FUNCTION_CMP_RCONST(type, XTYPE, float4, PG_GETARG_FLOAT4) \
+    _FUNCTION_CMP_RCONST(type, XTYPE, float8, PG_GETARG_FLOAT8)
+
+//Macro Level 1
+#define FUNCTION_OP_ALL(type, XTYPE1) \
+    FUNCTION_OP(type, XTYPE1) \
+    FUNCTION_OP_RCONST(type, XTYPE1) \
+    FUNCTION_CMP(type, XTYPE1) \
+    FUNCTION_CMP_RCONST(type, XTYPE1)
+
+#define FUNCTION_BUILD(type, typeoid) \
+    _FUNCTION_BUILD(type, typeoid) \
+    _FUNCTION_IN(type, typeoid) \
+    _FUNCTION_OUT(type, typeoid)
+
+//Macro Level 0
+FUNCTION_BUILD(int2, INT2OID)
+FUNCTION_BUILD(int4, INT4OID)
+FUNCTION_BUILD(int8, INT8OID)
+FUNCTION_BUILD(float4, FLOAT4OID)
+FUNCTION_BUILD(float8, FLOAT8OID)
+FUNCTION_BUILD(bool, BOOLOID)
+
+FUNCTION_OP_ALL(int2, Int16)
+FUNCTION_OP_ALL(int4, Int32)
+FUNCTION_OP_ALL(int8, Int64)
+FUNCTION_OP_ALL(float4, Float4)
+FUNCTION_OP_ALL(float8, Float8)
+FUNCTION_OP_ALL(bool, Bool)
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cebbda9d/contrib/vexecutor/vtype.h
----------------------------------------------------------------------
diff --git a/contrib/vexecutor/vtype.h b/contrib/vexecutor/vtype.h
new file mode 100644
index 0000000..e8315fc
--- /dev/null
+++ b/contrib/vexecutor/vtype.h
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __VTYPE_H___
+#define __VTYPE_H___
+#include "postgres.h"
+#include "fmgr.h"
+typedef struct vtype {
+    int     _vl_len;
+    Oid     elemtype;
+    int     dim;
+    bool    *isnull;
+    bool    *skipref;
+    Datum   values[0];
+}vtype;
+
+
+#define CANARYSIZE  sizeof(char)
+#define VTYPEHEADERSZ (sizeof(vtype))
+#define VDATUMSZ(dim) (sizeof(Datum) * dim)
+#define ISNULLSZ(dim) (sizeof(bool) * dim)
+#define VTYPESIZE(dim) (VTYPEHEADERSZ + VDATUMSZ(dim) + CANARYSIZE + ISNULLSZ(dim))
+#define CANARYOFFSET(vtype) ((char*)((unsigned char*)vtype + VTYPEHEADERSZ + VDATUMSZ(dim)))
+#define ISNULLOFFSET(vtype) ((bool*)((unsigned char*)vtype + VTYPEHEADERSZ + VDATUMSZ(vtype->dim) + CANARYSIZE))
+#define VTYPE_STURCTURE(type) typedef struct vtype v##type;
+
+#define FUNCTION_BUILD_HEADER(type) \
+v##type* buildv##type(int dim, bool *skip);
+
+/*
+ * Operator function for the abstract data types, this MACRO is used for the 
+ * V-types OP V-types.
+ * e.g. extern Datum vint2vint2pl(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_OP_HEADER(type1, type2, opsym, opstr) \
+extern Datum v##type1##v##type2##opstr(PG_FUNCTION_ARGS);
+
+/*
+ * Operator function for the abstract data types, this MACRO is used for the 
+ * V-types OP Consts.
+ * e.g. extern Datum vint2int2pl(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, opsym, opstr) \
+extern Datum v##type##const_type##opstr(PG_FUNCTION_ARGS);
+
+/*
+ * Comparision function for the abstract data types, this MACRO is used for the 
+ * V-types OP V-types.
+ * e.g. extern Datum vint2vint2eq(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_CMP_HEADER(type1, type2, cmpsym, cmpstr) \
+extern Datum v##type1##v##type2##cmpstr(PG_FUNCTION_ARGS);
+
+/*
+ * Comparision function for the abstract data types, this MACRO is used for the 
+ * V-types OP Consts.
+ * e.g. extern Datum vint2int2eq(PG_FUNCTION_ARGS);
+ */
+#define __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, cmpsym, cmpstr) \
+extern Datum v##type##const_type##cmpstr(PG_FUNCTION_ARGS);
+
+#define _FUNCTION_OP_HEADER(type1, type2) \
+    __FUNCTION_OP_HEADER(type1, type2, +, pl)  \
+    __FUNCTION_OP_HEADER(type1, type2, -, mi)  \
+    __FUNCTION_OP_HEADER(type1, type2, *, mul) \
+    __FUNCTION_OP_HEADER(type1, type2, /, div)
+
+#define _FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO) \
+    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, +, pl)  \
+    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, -, mi)  \
+    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, *, mul) \
+    __FUNCTION_OP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, /, div)
+
+
+#define _FUNCTION_CMP_HEADER(type1, type2) \
+    __FUNCTION_CMP_HEADER(type1, type2, ==, eq) \
+    __FUNCTION_CMP_HEADER(type1, type2, !=, ne) \
+    __FUNCTION_CMP_HEADER(type1, type2, >, gt) \
+    __FUNCTION_CMP_HEADER(type1, type2, >=, ge) \
+    __FUNCTION_CMP_HEADER(type1, type2, <, lt) \
+    __FUNCTION_CMP_HEADER(type1, type2, <=, le)
+
+#define _FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO) \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, ==, eq)  \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, !=, ne)  \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO,  >, gt) \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, >=, ge) \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO,  <, lt) \
+    __FUNCTION_CMP_RCONST_HEADER(type, const_type, CONST_ARG_MACRO, <=, le) 
+
+/*
+ * IN function for the abstract data types
+ * e.g. Datum vint2in(PG_FUNCTION_ARGS)
+ */
+#define FUNCTION_IN_HEADER(type, typeoid) \
+extern Datum v##type##in(PG_FUNCTION_ARGS);
+
+/*
+ * OUT function for the abstract data types
+ * e.g. Datum vint2out(PG_FUNCTION_ARGS)
+ */
+#define FUNCTION_OUT_HEADER(type, typeoid) \
+extern Datum v##type##out(PG_FUNCTION_ARGS);
+
+#define FUNCTION_OP_HEADER(type) \
+    _FUNCTION_OP_HEADER(type, int2) \
+    _FUNCTION_OP_HEADER(type, int4) \
+    _FUNCTION_OP_HEADER(type, int8) \
+    _FUNCTION_OP_HEADER(type, float4) \
+    _FUNCTION_OP_HEADER(type, float8)
+
+#define FUNCTION_OP_RCONST_HEADER(type) \
+    _FUNCTION_OP_RCONST_HEADER(type, int2, PG_GETARG_INT16) \
+    _FUNCTION_OP_RCONST_HEADER(type, int4, PG_GETARG_INT32) \
+    _FUNCTION_OP_RCONST_HEADER(type, int8, PG_GETARG_INT64) \
+    _FUNCTION_OP_RCONST_HEADER(type, float4, PG_GETARG_FLOAT4) \
+    _FUNCTION_OP_RCONST_HEADER(type, float8, PG_GETARG_FLOAT8)
+
+#define FUNCTION_CMP_HEADER(type1) \
+    _FUNCTION_CMP_HEADER(type1, int2) \
+    _FUNCTION_CMP_HEADER(type1, int4) \
+    _FUNCTION_CMP_HEADER(type1, int8) \
+    _FUNCTION_CMP_HEADER(type1, float4) \
+    _FUNCTION_CMP_HEADER(type1, float8)
+
+#define FUNCTION_CMP_RCONST_HEADER(type) \
+    _FUNCTION_CMP_RCONST_HEADER(type, int2, PG_GETARG_INT16) \
+    _FUNCTION_CMP_RCONST_HEADER(type, int4, PG_GETARG_INT32) \
+    _FUNCTION_CMP_RCONST_HEADER(type, int8, PG_GETARG_INT64) \
+    _FUNCTION_CMP_RCONST_HEADER(type, float4, PG_GETARG_FLOAT4) \
+    _FUNCTION_CMP_RCONST_HEADER(type, float8, PG_GETARG_FLOAT8)
+
+#define FUNCTION_OP_ALL_HEADER(type) \
+    FUNCTION_OP_HEADER(type) \
+    FUNCTION_OP_RCONST_HEADER(type) \
+    FUNCTION_CMP_HEADER(type) \
+    FUNCTION_CMP_RCONST_HEADER(type) \
+
+#define TYPE_HEADER(type,oid) \
+    VTYPE_STURCTURE(type) \
+	FUNCTION_BUILD_HEADER(type) \
+    FUNCTION_OP_ALL_HEADER(type) \
+    FUNCTION_IN_HEADER(type, typeoid) \
+    FUNCTION_OUT_HEADER(type, typeoid) \
+
+TYPE_HEADER(int2, INT2OID)
+TYPE_HEADER(int4, INT4OID)
+TYPE_HEADER(int8, INT8OID)
+TYPE_HEADER(float4, FLOAT4OID)
+TYPE_HEADER(float8, FLOAT8OID)
+TYPE_HEADER(bool, BOOLOID)
+
+extern vtype* buildvtype(Oid elemtype,int dim,bool *skip);
+extern void destroyvtype(vtype** vt);
+#endif