summaryrefslogtreecommitdiff
path: root/storage/connect
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2014-04-30 10:48:29 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2014-04-30 10:48:29 +0200
commite7c7256d1d67125921d9f688a382aef873f5b9ce (patch)
tree06a78782e6deea301516dc6df03a3a686b191130 /storage/connect
parent883c37a827ede4379d25896e482e0fe5292330a3 (diff)
downloadmariadb-git-e7c7256d1d67125921d9f688a382aef873f5b9ce.tar.gz
- Implementation of adding selected columns to dynamic indexes.
modified: storage/connect/connect.cc storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabvct.cpp storage/connect/tabvct.h storage/connect/xindex.cpp storage/connect/xindex.h
Diffstat (limited to 'storage/connect')
-rw-r--r--storage/connect/connect.cc71
-rw-r--r--storage/connect/ha_connect.cc60
-rw-r--r--storage/connect/ha_connect.h5
-rw-r--r--storage/connect/tabdos.cpp38
-rw-r--r--storage/connect/tabdos.h2
-rw-r--r--storage/connect/tabvct.cpp2
-rw-r--r--storage/connect/tabvct.h2
-rwxr-xr-xstorage/connect/xindex.cpp149
-rw-r--r--storage/connect/xindex.h4
9 files changed, 207 insertions, 126 deletions
diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc
index f7bba541dfa..daff6ffdc68 100644
--- a/storage/connect/connect.cc
+++ b/storage/connect/connect.cc
@@ -604,15 +604,8 @@ int CntCloseTable(PGLOBAL g, PTDB tdbp)
/***********************************************************************/
int CntIndexInit(PGLOBAL g, PTDB ptdb, int id)
{
- int k;
- PCOL colp;
- PVAL valp;
- PKXBASE xp;
- PXLOAD pxp;
PIXDEF xdp;
- XKPDEF *kdp;
PTDBDOX tdbp;
- PCOLDEF cdp;
DOXDEF *dfp;
if (!ptdb)
@@ -651,64 +644,20 @@ int CntIndexInit(PGLOBAL g, PTDB ptdb, int id)
return 0;
} // endif xdp
+#if 0
if (xdp->IsDynamic()) {
// This is a dynamically created index (KINDEX)
- // It cannot be created now, before cond_push is executed
+ // It should not be created now, if called by index range
tdbp->SetXdp(xdp);
return (xdp->IsUnique()) ? 1 : 2;
} // endif dynamic
+#endif // 0
// Static indexes must be initialized now for records_in_range
- // Allocate the key columns definition block
- tdbp->Knum= xdp->GetNparts();
- tdbp->To_Key_Col= (PCOL*)PlugSubAlloc(g, NULL, tdbp->Knum * sizeof(PCOL));
-
- // Get the key column description list
- for (k= 0, kdp= (XKPDEF*)xdp->GetToKeyParts(); kdp; kdp= (XKPDEF*)kdp->Next)
- if (!(colp= tdbp->ColDB(g, kdp->Name, 0)) || colp->InitValue(g)) {
- sprintf(g->Message, "Wrong column %s", kdp->Name);
- return 0;
- } else
- tdbp->To_Key_Col[k++]= colp;
-
-#if defined(_DEBUG)
- if (k != tdbp->Knum) {
- sprintf(g->Message, "Key part number mismatch for %s",
- xdp->GetName());
- return 0;
- } // endif k
-#endif // _DEBUG
-
- // Allocate the pseudo constants that will contain the key values
- tdbp->To_Link= (PXOB*)PlugSubAlloc(g, NULL, tdbp->Knum * sizeof(PXOB));
-
- for (k= 0, kdp= (XKPDEF*)xdp->GetToKeyParts();
- kdp; k++, kdp= (XKPDEF*)kdp->Next) {
- cdp= tdbp->Key(k)->GetCdp();
- valp= AllocateValue(g, cdp->GetType(), cdp->GetLength());
- tdbp->To_Link[k]= new(g) CONSTANT(valp);
- } // endfor k
-
- // Make the index on xdp
- if (!xdp->IsAuto()) {
- if (dfp->Huge)
- pxp= new(g) XHUGE;
- else
- pxp= new(g) XFILE;
-
- if (tdbp->Knum == 1) // Single index
- xp= new(g) XINDXS(tdbp, xdp, pxp, tdbp->To_Key_Col, tdbp->To_Link);
- else // Multi-Column index
- xp= new(g) XINDEX(tdbp, xdp, pxp, tdbp->To_Key_Col, tdbp->To_Link);
-
- } else // Column contains same values as ROWID
- xp= new(g) XXROW(tdbp);
-
- if (xp->Init(g))
+ if (tdbp->InitialyzeIndex(g, xdp))
return 0;
- tdbp->To_Kindex= xp;
- return (xp->IsMul()) ? 2 : 1;
+ return (tdbp->To_Kindex->IsMul()) ? 2 : 1;
} // end of CntIndexInit
/***********************************************************************/
@@ -746,20 +695,18 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
// Set reference values and index operator
if (!tdbp->To_Link || !tdbp->To_Kindex) {
- if (!tdbp->To_Xdp) {
+// if (!tdbp->To_Xdp) {
sprintf(g->Message, "Index not initialized for table %s", tdbp->Name);
return RC_FX;
+#if 0
} // endif !To_Xdp
-
// Now it's time to make the dynamic index
- tdbp->SetFilter(tdbp->To_Def->GetHandler()->CheckFilter(g));
-
- if (tdbp->MakeDynamicIndex(g)) {
+ if (tdbp->InitialyzeIndex(g, NULL)) {
sprintf(g->Message, "Fail to make dynamic index %s",
tdbp->To_Xdp->GetName());
return RC_FX;
} // endif MakeDynamicIndex
-
+#endif // 0
} // endif !To_Kindex
xbp= (XXBASE*)tdbp->To_Kindex;
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc
index d56f3ca08e4..ae9de333054 100644
--- a/storage/connect/ha_connect.cc
+++ b/storage/connect/ha_connect.cc
@@ -324,8 +324,10 @@ ha_create_table_option connect_field_option_list[]=
*/
ha_create_table_option connect_index_option_list[]=
{
- HA_IOPTION_BOOL("DYNAMIC", kindx, 0),
+ HA_IOPTION_BOOL("DYNAMIC", dynamic, 0),
+ HA_IOPTION_BOOL("DYNAM", dynamic, 0),
HA_IOPTION_BOOL("MAPPED", mapped, 0),
+ HA_IOPTION_END
};
/***********************************************************************/
@@ -435,6 +437,7 @@ static int connect_init_func(void *p)
connect_hton->flags= HTON_TEMPORARY_NOT_SUPPORTED | HTON_NO_PARTITION;
connect_hton->table_options= connect_table_option_list;
connect_hton->field_options= connect_field_option_list;
+ connect_hton->index_options= connect_index_option_list;
connect_hton->tablefile_extensions= ha_connect_exts;
connect_hton->discover_table_structure= connect_assisted_discovery;
@@ -658,7 +661,13 @@ TABTYPE ha_connect::GetRealType(PTOS pos)
const char *ha_connect::index_type(uint inx)
{
switch (GetIndexType(GetRealType())) {
- case 1: return "XINDEX";
+ case 1:
+ if (table_share)
+ return (GetIndexOption(&table_share->key_info[inx], "Dynamic"))
+ ? "KINDEX" : "XINDEX";
+ else
+ return "XINDEX";
+
case 2: return "REMOTE";
} // endswitch
@@ -1151,6 +1160,31 @@ PXOS ha_connect::GetIndexOptionStruct(KEY *kp)
} // end of GetIndexOptionStruct
/****************************************************************************/
+/* Return a Boolean index option or false if not specified. */
+/****************************************************************************/
+bool ha_connect::GetIndexOption(KEY *kp, char *opname)
+{
+ bool opval= false;
+ PXOS options= GetIndexOptionStruct(kp);
+
+ if (options) {
+ if (!stricmp(opname, "Dynamic"))
+ opval= options->dynamic;
+ else if (!stricmp(opname, "Mapped"))
+ opval= options->mapped;
+
+ } else if (kp->comment.str != NULL) {
+ char *pv, *oplist= kp->comment.str;
+
+ if ((pv= GetListOption(xp->g, opname, oplist)))
+ opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
+
+ } // endif comment
+
+ return opval;
+} // end of GetIndexOption
+
+/****************************************************************************/
/* Returns the index description structure used to make the index. */
/****************************************************************************/
PIXDEF ha_connect::GetIndexInfo(TABLE_SHARE *s)
@@ -1159,7 +1193,6 @@ PIXDEF ha_connect::GetIndexInfo(TABLE_SHARE *s)
bool unique;
PIXDEF xdp, pxd=NULL, toidx= NULL;
PKPDEF kpp, pkp;
- PXOS xosp;
KEY kp;
PGLOBAL& g= xp->g;
@@ -1172,7 +1205,6 @@ PIXDEF ha_connect::GetIndexInfo(TABLE_SHARE *s)
// Find the index to describe
kp= s->key_info[n];
- xosp= kp.option_struct;
// Now get index information
pn= (char*)s->keynames.type_names[n];
@@ -1214,20 +1246,8 @@ PIXDEF ha_connect::GetIndexInfo(TABLE_SHARE *s)
} // endfor k
xdp->SetNParts(kp.user_defined_key_parts);
-
- if (xosp) {
- xdp->Dynamic= xosp->kindx;
- xdp->Mapped= xosp->mapped;
- } else if (kp.comment.str != NULL) {
- char *pv, *oplist= kp.comment.str;
-
- if ((pv= GetListOption(g, "Dynamic", oplist)))
- xdp->Dynamic= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
-
- if ((pv= GetListOption(g, "Mapped", oplist)))
- xdp->Mapped= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
-
- } // endif comment
+ xdp->Dynamic= GetIndexOption(&kp, "Dynamic");
+ xdp->Mapped= GetIndexOption(&kp, "Mapped");
if (pxd)
pxd->SetNext(xdp);
@@ -1867,7 +1887,7 @@ const char *ha_connect::GetValStr(OPVAL vop, bool neg)
return val;
} // end of GetValStr
-
+#if 0
/***********************************************************************/
/* Check the WHERE condition and return a CONNECT filter. */
/***********************************************************************/
@@ -1875,7 +1895,7 @@ PFIL ha_connect::CheckFilter(PGLOBAL g)
{
return CondFilter(g, (Item *)pushed_cond);
} // end of CheckFilter
-
+#endif // 0
/***********************************************************************/
/* Check the WHERE condition and return a CONNECT filter. */
diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h
index 40815a1a9ea..ebdeeae8623 100644
--- a/storage/connect/ha_connect.h
+++ b/storage/connect/ha_connect.h
@@ -140,7 +140,7 @@ struct ha_field_option_struct
*/
struct ha_index_option_struct
{
- bool kindx;
+ bool dynamic;
bool mapped;
};
@@ -187,6 +187,7 @@ public:
bool GetBooleanOption(char *opname, bool bdef);
bool SetBooleanOption(char *opname, bool b);
int GetIntegerOption(char *opname);
+ bool GetIndexOption(KEY *kp, char *opname);
bool CheckString(const char *str1, const char *str2);
bool SameString(TABLE *tab, char *opn);
bool SetIntegerOption(char *opname, int n);
@@ -347,7 +348,7 @@ virtual const COND *cond_push(const COND *cond);
PCFIL CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond);
const char *GetValStr(OPVAL vop, bool neg);
PFIL CondFilter(PGLOBAL g, Item *cond);
-PFIL CheckFilter(PGLOBAL g);
+//PFIL CheckFilter(PGLOBAL g);
/**
Number of rows in table. It will only be called if
diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp
index a23ce388184..e596b438d5f 100644
--- a/storage/connect/tabdos.cpp
+++ b/storage/connect/tabdos.cpp
@@ -1695,21 +1695,23 @@ err:
/***********************************************************************/
/* Make a dynamic index. */
/***********************************************************************/
-bool TDBDOS::MakeDynamicIndex(PGLOBAL g)
+bool TDBDOS::InitialyzeIndex(PGLOBAL g, PIXDEF xdp)
{
int k, rc;
- bool brc;
+ bool brc, dynamic;
PCOL colp;
PCOLDEF cdp;
PVAL valp;
- PIXDEF xdp;
+ PXLOAD pxp;
PKXBASE kxp;
PKPDEF kdp;
- if (!(xdp = To_Xdp)) {
+ if (!xdp && !(xdp = To_Xdp)) {
strcpy(g->Message, "NULL dynamic index");
return true;
- } // endif To_Xdp
+ } else
+ dynamic = To_Filter && xdp->IsUnique() && xdp->IsDynamic();
+// dynamic = To_Filter && xdp->IsDynamic(); NIY
// Allocate the key columns definition block
Knum = xdp->GetNparts();
@@ -1742,13 +1744,22 @@ bool TDBDOS::MakeDynamicIndex(PGLOBAL g)
// Make the index on xdp
if (!xdp->IsAuto()) {
+ if (!dynamic) {
+ if (((PDOSDEF)To_Def)->Huge)
+ pxp = new(g) XHUGE;
+ else
+ pxp = new(g) XFILE;
+
+ } else
+ pxp = NULL;
+
if (Knum == 1) // Single index
- kxp= new(g) XINDXS(this, xdp, NULL, To_Key_Col, To_Link);
- else // Multi-Column index
- kxp= new(g) XINDEX(this, xdp, NULL, To_Key_Col, To_Link);
+ kxp = new(g) XINDXS(this, xdp, pxp, To_Key_Col, To_Link);
+ else // Multi-Column index
+ kxp = new(g) XINDEX(this, xdp, pxp, To_Key_Col, To_Link);
} else // Column contains same values as ROWID
- kxp= new(g) XXROW(this);
+ kxp = new(g) XXROW(this);
// Prepare error return
if (g->jump_level == MAX_JUMP) {
@@ -1758,12 +1769,15 @@ bool TDBDOS::MakeDynamicIndex(PGLOBAL g)
if ((rc = setjmp(g->jumper[++g->jump_level])) != 0) {
brc = true;
- } else if (!(brc = kxp->Make(g, xdp)))
- To_Kindex= kxp;
+ } else
+ if (!(brc = (dynamic) ? kxp->Make(g, xdp) : kxp->Init(g))) {
+ kxp->SetDynamic(dynamic);
+ To_Kindex= kxp;
+ } // endif brc
g->jump_level--;
return brc;
- } // end of MakeDynamicIndex
+ } // end of InitialyzeIndex
/***********************************************************************/
/* DOS GetProgMax: get the max value for progress information. */
diff --git a/storage/connect/tabdos.h b/storage/connect/tabdos.h
index d7a6af5a5ec..c6652c4d2d7 100644
--- a/storage/connect/tabdos.h
+++ b/storage/connect/tabdos.h
@@ -170,7 +170,7 @@ class DllExport TDBDOS : public TDBASE {
// Optimization routines
virtual int MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add);
- bool MakeDynamicIndex(PGLOBAL g);
+ bool InitialyzeIndex(PGLOBAL g, PIXDEF xdp);
void ResetBlockFilter(PGLOBAL g);
bool GetDistinctColumnValues(PGLOBAL g, int nrec);
diff --git a/storage/connect/tabvct.cpp b/storage/connect/tabvct.cpp
index ed258f3a80f..ba5cf36a640 100644
--- a/storage/connect/tabvct.cpp
+++ b/storage/connect/tabvct.cpp
@@ -32,7 +32,7 @@
/***********************************************************************/
/***********************************************************************/
-/* Include relevant MariaDB header file. */
+/* Include relevant MariaDB header file. */
/***********************************************************************/
#include "my_global.h"
#if defined(WIN32)
diff --git a/storage/connect/tabvct.h b/storage/connect/tabvct.h
index e15150ab356..b744dbb2529 100644
--- a/storage/connect/tabvct.h
+++ b/storage/connect/tabvct.h
@@ -20,6 +20,7 @@ typedef class VCTCOL *PVCTCOL;
/* VCT table. */
/***********************************************************************/
class DllExport VCTDEF : public DOSDEF { /* Logical table description */
+ friend class TDBVCT;
friend class VCTFAM;
friend class VECFAM;
friend class VMPFAM;
@@ -64,6 +65,7 @@ class DllExport TDBVCT : public TDBFIX {
virtual AMT GetAmType(void) {return TYPE_AM_VCT;}
virtual PTDB Duplicate(PGLOBAL g)
{return (PTDB)new(g) TDBVCT(g, this);}
+ bool IsSplit(void) {return ((VCTDEF*)To_Def)->Split;}
// Methods
virtual PTDB CopyOne(PTABS t);
diff --git a/storage/connect/xindex.cpp b/storage/connect/xindex.cpp
index 5039f2d7aee..2a7a10528fb 100755
--- a/storage/connect/xindex.cpp
+++ b/storage/connect/xindex.cpp
@@ -45,6 +45,7 @@
//nclude "array.h"
#include "filamtxt.h"
#include "tabdos.h"
+#include "tabvct.h"
/***********************************************************************/
/* Macro or external routine definition */
@@ -167,6 +168,8 @@ XXBASE::XXBASE(PTDBDOS tbxp, bool b) : CSORT(b),
Op = OP_EQ;
To_KeyCol = NULL;
Mul = false;
+ Srtd = false;
+ Dynamic = false;
Val_K = -1;
Nblk = Sblk = 0;
Thresh = 7;
@@ -252,13 +255,14 @@ void XINDEX::Close(void)
PlgDBfree(Index);
PlgDBfree(Offset);
- // De-allocate Key data
- for (PXCOL kcp = To_KeyCol; kcp; kcp = kcp->Next)
- kcp->FreeData();
+ for (PXCOL kcp = To_KeyCol; kcp; kcp = kcp->Next) {
+ // Column values cannot be retrieved from key anymore
+ if (kcp->Colp)
+ kcp->Colp->SetKcol(NULL);
- // Column values cannot be retrieved from key anymore
- for (int k = 0; k < Nk; k++)
- To_Cols[k]->SetKcol(NULL);
+ // De-allocate Key data
+ kcp->FreeData();
+ } // endfor kcp
} // end of Close
@@ -278,6 +282,25 @@ int XINDEX::Qcompare(int *i1, int *i2)
return k;
} // end of Qcompare
+/***********************************************************************/
+/* AddColumns: here we try to determine whether it is worthwhile to */
+/* add to the keys the values of the columns selected for this table. */
+/* Sure enough, it is done while records are read and permit to avoid */
+/* reading the table while doing the join (Dynamic index only) */
+/***********************************************************************/
+bool XINDEX::AddColumns(void)
+ {
+ if (!Dynamic)
+ return false; // Not applying to static index
+ else if (IsMul())
+ return false; // Not done yet for multiple index
+ else if (Tbxp->GetAmType() == TYPE_AM_VCT && ((PTDBVCT)Tbxp)->IsSplit())
+ return false; // This would require to read additional files
+ else
+ return true;
+
+ } // end of AddColumns
+
/***********************************************************************/
/* Make: Make and index on key column(s). */
/***********************************************************************/
@@ -291,8 +314,13 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
PKPDEF kdfp = Xdp->GetToKeyParts();
bool brc = false;
PCOL colp;
- PXCOL kp, prev = NULL, kcp = NULL;
- PDBUSER dup = (PDBUSER)g->Activityp->Aptr;
+ PFIL filp = Tdbp->GetFilter();
+ PXCOL kp, addcolp, prev = NULL, kcp = NULL;
+//PDBUSER dup = (PDBUSER)g->Activityp->Aptr;
+
+#if defined(_DEBUG)
+ assert(X || Nk == 1);
+#endif // _DEBUG
/*********************************************************************/
/* Allocate the storage that will contain the keys and the file */
@@ -350,6 +378,50 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
To_LastCol = prev;
+ if (AddColumns()) {
+ PCOL kolp = To_Cols[0]; // Temporary while imposing Nk = 1
+
+ i = 0;
+
+ // Allocate the accompanying
+ for (colp = Tbxp->GetColumns(); colp; colp = colp->GetNext()) {
+ // Count how many columns to add
+// for (k = 0; k < Nk; k++)
+// if (colp == To_Cols[k])
+// break;
+
+// if (k == nk)
+ if (colp != kolp)
+ i++;
+
+ } // endfor colp
+
+ if (i && i < 10) // Should be a parameter
+ for (colp = Tbxp->GetColumns(); colp; colp = colp->GetNext()) {
+// for (k = 0; k < Nk; k++)
+// if (colp == To_Cols[k])
+// break;
+
+// if (k < nk)
+ if (colp == kolp)
+ continue; // This is a key column
+
+ kcp = new(g) KXYCOL(this);
+
+ if (kcp->Init(g, colp, n, true, NULL))
+ return true;
+
+ if (trace)
+ htrc("Adding colp=%p Buf_Type=%d size=%d\n",
+ colp, colp->GetResultType(), n);
+
+ prev->Next = kcp;
+ prev = kcp;
+ } // endfor colp
+
+ } // endif AddColumns
+
+#if 0
/*********************************************************************/
/* Get the starting information for progress. */
/*********************************************************************/
@@ -357,18 +429,19 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
sprintf((char*)dup->Step, MSG(BUILD_INDEX), Xdp->GetName(), Tdbp->Name);
dup->ProgMax = Tdbp->GetProgMax(g);
dup->ProgCur = 0;
+#endif // 0
/*********************************************************************/
/* Standard init: read the file and construct the index table. */
/* Note: reading will be sequential as To_Kindex is not set. */
/*********************************************************************/
for (i = nkey = 0; i < n && rc != RC_EF; i++) {
-#if defined(THREAD)
+#if 0
if (!dup->Step) {
strcpy(g->Message, MSG(QUERY_CANCELLED));
longjmp(g->jumper[g->jump_level], 99);
} // endif Step
-#endif // THREAD
+#endif // 0
/*******************************************************************/
/* Read a valid record from table file. */
@@ -376,12 +449,12 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
rc = Tdbp->ReadDB(g);
// Update progress information
- dup->ProgCur = Tdbp->GetProgCur();
+// dup->ProgCur = Tdbp->GetProgCur();
// Check return code and do whatever must be done according to it
switch (rc) {
case RC_OK:
- if (ApplyFilter(g, Tdbp->GetFilter()))
+ if (ApplyFilter(g, filp))
break;
// passthru
@@ -398,7 +471,11 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
/* Get and Store the file position of the last read record for */
/* future direct access. */
/*******************************************************************/
- To_Rec[nkey] = Tdbp->GetRecpos();
+ if (nkey == n) {
+ sprintf(g->Message, MSG(TOO_MANY_KEYS), nkey);
+ return true;
+ } else
+ To_Rec[nkey] = Tdbp->GetRecpos();
/*******************************************************************/
/* Get the keys and place them in the key blocks. */
@@ -407,11 +484,11 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
k < Nk && kcp;
k++, kcp = kcp->Next) {
colp = To_Cols[k];
- colp->Reset();
- colp->ReadColumn(g);
-// if (colp->ReadColumn(g))
-// goto err;
+ if (!colp->GetStatus(BUF_READ))
+ colp->ReadColumn(g);
+ else
+ colp->Reset();
kcp->SetValue(colp, nkey);
} // endfor k
@@ -422,7 +499,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
end_of_file:
// Update progress information
- dup->ProgCur = Tdbp->GetProgMax(g);
+//dup->ProgCur = Tdbp->GetProgMax(g);
/*********************************************************************/
/* Record the Index size and eventually resize memory allocation. */
@@ -457,6 +534,10 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
goto err; // Error
} // endif alloc
+ // We must separate keys and added columns before sorting
+ addcolp = To_LastCol->Next;
+ To_LastCol->Next = NULL;
+
// Call the sort program, it returns the number of distinct values
if ((Ndif = Qsort(g, Num_K)) < 0)
goto err; // Error during sort
@@ -469,6 +550,9 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
} else
PlgDBfree(Offset); // Not used anymore
+ // Restore kcp list
+ To_LastCol->Next = addcolp;
+
// Use the index to physically reorder the xindex
Srtd = Reorder(g);
@@ -493,7 +577,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
} else {
Mul = false; // Current index is unique
PlgDBfree(Offset); // Not used anymore
- MaxSame = 1; // Reset it when remaking an index
+ MaxSame = 1; // Reset it when remaking an index
} // endif Ndif
/*********************************************************************/
@@ -508,7 +592,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
/* except if the subset originally contains unique values. */
/*********************************************************************/
// Update progress information
- dup->Step = STEP(REDUCE_INDEX);
+//dup->Step = STEP(REDUCE_INDEX);
ndf = Ndif;
To_LastCol->Mxs = MaxSame;
@@ -558,7 +642,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
/* calculated, so the Record array can be discarted. */
/* Note: for Num_K = 1 any non null value is Ok. */
/*********************************************************************/
- if (Srtd && Tdbp->Ftype != RECFM_VAR) {
+ if (Srtd && !filp && Tdbp->Ftype != RECFM_VAR) {
Incr = (Num_K > 1) ? To_Rec[1] : Num_K;
PlgDBfree(Record);
} // endif Srtd
@@ -587,8 +671,14 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
/*********************************************************************/
/* Save the xindex so it has not to be recalculated. */
/*********************************************************************/
- if (X && SaveIndex(g, sxp))
- brc = true;
+ if (X) {
+ if (SaveIndex(g, sxp))
+ brc = true;
+
+ } else // Dynamic index
+ // Indicate that key column values can be found from KEYCOL's
+ for (kcp = To_KeyCol; kcp; kcp = kcp->Next)
+ kcp->Colp->SetKcol(kcp);
err:
// We don't need the index anymore
@@ -637,6 +727,7 @@ bool XINDEX::Reorder(PGLOBAL g)
register int i, j, k, n;
bool sorted = true;
PXCOL kcp;
+#if 0
PDBUSER dup = (PDBUSER)g->Activityp->Aptr;
if (Num_K > 500000) {
@@ -646,6 +737,7 @@ bool XINDEX::Reorder(PGLOBAL g)
dup->ProgCur = 0;
} else
dup = NULL;
+#endif // 0
if (!Pex)
return Srtd;
@@ -654,8 +746,8 @@ bool XINDEX::Reorder(PGLOBAL g)
if (Pex[i] == Num_K) { // Already moved
continue;
} else if (Pex[i] == i) { // Already placed
- if (dup)
- dup->ProgCur++;
+// if (dup)
+// dup->ProgCur++;
continue;
} // endif's Pex
@@ -684,8 +776,8 @@ bool XINDEX::Reorder(PGLOBAL g)
To_Rec[j] = To_Rec[k];
} // endif k
- if (dup)
- dup->ProgCur++;
+// if (dup)
+// dup->ProgCur++;
} // endfor j
@@ -2834,7 +2926,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln)
int len = colp->GetLength(), prec = colp->GetScale();
// Currently no indexing on NULL columns
- if (colp->IsNullable()) {
+ if (colp->IsNullable() && kln) {
sprintf(g->Message, "Cannot index nullable column %s", colp->GetName());
return true;
} // endif nullable
@@ -2877,6 +2969,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln)
IsSorted = colp->GetOpt() == 2;
//SetNulls(colp->IsNullable()); for when null columns will be indexable
+ Colp = colp;
return false;
} // end of Init
diff --git a/storage/connect/xindex.h b/storage/connect/xindex.h
index f447051a517..50f8282e5c3 100644
--- a/storage/connect/xindex.h
+++ b/storage/connect/xindex.h
@@ -177,6 +177,8 @@ class DllExport XXBASE : public CSORT, public BLOCK {
virtual void Reset(void) = 0;
virtual bool IsMul(void) {return false;}
virtual bool IsRandom(void) {return true;}
+ virtual bool IsDynamic(void) {return Dynamic;}
+ virtual void SetDynamic(bool dyn) {Dynamic = dyn;}
virtual bool HaveSame(void) {return false;}
virtual int GetCurPos(void) {return Cur_K;}
virtual void SetNval(int n) {assert(n == 1);}
@@ -227,6 +229,7 @@ class DllExport XXBASE : public CSORT, public BLOCK {
OPVAL Op; // Search operator
bool Mul; // true if multiple
bool Srtd; // true for sorted column
+ bool Dynamic; // true when dynamically made
int Val_K; // Index of current value
int Nblk; // Number of blocks
int Sblk; // Block size
@@ -275,6 +278,7 @@ class DllExport XINDEX : public XXBASE {
bool GetAllSizes(PGLOBAL g, int &ndif, int &numk);
protected:
+ bool AddColumns(void);
bool NextValDif(void);
// Members