Commit e7c7256d authored by Olivier Bertrand's avatar Olivier Bertrand

- 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
parent 883c37a8
......@@ -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;
......
......@@ -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
......@@ -1150,6 +1159,31 @@ PXOS ha_connect::GetIndexOptionStruct(KEY *kp)
return kp->option_struct;
} // 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. */
/****************************************************************************/
......@@ -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. */
......
......@@ -140,7 +140,7 @@ struct ha_field_option_struct
*/
struct ha_index_option_struct
{
bool kindx;
bool dynamic;
bool mapped;
};
......@@ -187,6 +187,7 @@ class ha_connect: public handler
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
......
......@@ -1695,21 +1695,23 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
/***********************************************************************/
/* 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. */
......
......@@ -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);
......
......@@ -32,7 +32,7 @@
/***********************************************************************/
/***********************************************************************/
/* Include relevant MariaDB header file. */
/* Include relevant MariaDB header file. */
/***********************************************************************/
#include "my_global.h"
#if defined(WIN32)
......
......@@ -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);
......
This diff is collapsed.
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment