MCPcopy Create free account
hub / github.com/MariaDB/server / MakeIndex

Method MakeIndex

storage/connect/tabdos.cpp:1668–1822  ·  view source on GitHub ↗

/ Check whether we have to create/update permanent indexes. */ /

Source from the content-addressed store, hash-verified

1666/* Check whether we have to create/update permanent indexes. */
1667/***********************************************************************/
1668int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
1669 {
1670 int k, n, rc = RC_OK;
1671 bool fixed, doit, sep;
1672 PCOL *keycols, colp;
1673 PIXDEF xdp, sxp = NULL;
1674 PKPDEF kdp;
1675 PDOSDEF dfp;
1676//PCOLDEF cdp;
1677 PXINDEX x;
1678 PXLOAD pxp;
1679
1680 Mode = MODE_READ;
1681 Use = USE_READY;
1682 dfp = (PDOSDEF)To_Def;
1683
1684 if (!Cardinality(g)) {
1685 // Void table erase eventual index file(s)
1686 (void)dfp->DeleteIndexFile(g, NULL);
1687 return RC_OK;
1688 } else
1689 fixed = Ftype != RECFM_VAR;
1690
1691 // Are we are called from CreateTable or CreateIndex?
1692 if (pxdf) {
1693 if (!add && dfp->GetIndx()) {
1694 safe_strcpy(g->Message, sizeof(g->Message), MSG(INDX_EXIST_YET));
1695 return RC_FX;
1696 } // endif To_Indx
1697
1698 if (add && dfp->GetIndx()) {
1699 for (sxp = dfp->GetIndx(); sxp; sxp = sxp->GetNext())
1700 if (!stricmp(sxp->GetName(), pxdf->GetName())) {
1701 snprintf(g->Message, sizeof(g->Message), MSG(INDEX_YET_ON), pxdf->GetName(), Name);
1702 return RC_FX;
1703 } else if (!sxp->GetNext())
1704 break;
1705
1706 sxp->SetNext(pxdf);
1707// first = false;
1708 } else
1709 dfp->SetIndx(pxdf);
1710
1711// pxdf->SetDef(dfp);
1712 } else if (!(pxdf = dfp->GetIndx()))
1713 return RC_INFO; // No index to make
1714
1715 try {
1716 // Allocate all columns that will be used by indexes.
1717 // This must be done before opening the table so specific
1718 // column initialization can be done (in particular by TDBVCT)
1719 for (n = 0, xdp = pxdf; xdp; xdp = xdp->GetNext())
1720 for (kdp = xdp->GetToKeyParts(); kdp; kdp = kdp->GetNext()) {
1721 if (!(colp = ColDB(g, kdp->GetName(), 0))) {
1722 snprintf(g->Message, sizeof(g->Message), MSG(INDX_COL_NOTIN), kdp->GetName(), Name);
1723 goto err;
1724 } else if (colp->GetResultType() == TYPE_DECIM) {
1725 snprintf(g->Message, sizeof(g->Message), "Decimal columns are not indexable yet");

Callers 2

PlgMakeIndexFunction · 0.45
external_lockMethod · 0.45

Calls 12

safe_strcpyFunction · 0.85
PlugSubAllocFunction · 0.85
DeleteIndexFileMethod · 0.80
InitValueMethod · 0.80
GetBoolCatInfoMethod · 0.80
MakeMethod · 0.80
SetMxsameMethod · 0.80
CardinalityFunction · 0.70
htrcFunction · 0.70
CloseDBFunction · 0.70
GetNextMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected