mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Make indexes to be rebuilt on Update only when an indexed column was updated.
modified: mysql-test/suite/connect/r/index.result mysql-test/suite/connect/t/index.test storage/connect/ha_connect.cc storage/connect/tabdos.cpp storage/connect/xindex.cpp
This commit is contained in:
@@ -55,11 +55,8 @@ SELECT SUM(brut) FROM t1;
|
||||
SUM(brut)
|
||||
64319029
|
||||
#
|
||||
# Make the indexes
|
||||
# Test the indexes (made when creating the table)
|
||||
#
|
||||
OPTIMIZE TABLE t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
SELECT * FROM t1 WHERE matricule = '0091';
|
||||
matricule nom prenom sexe aanais mmnais ddentree ddnom brut net service sitmat formation
|
||||
91 THIVERNAL DIDIER JEAN 1 1951 10 1980-05-01 1991-10-01 14715 12024.71 1 M SANS
|
||||
@@ -95,15 +92,12 @@ create table t2
|
||||
(
|
||||
sexe INT(1) KEY,
|
||||
genre CHAR(8) NOT NULL
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sexe.csv' SEP_CHAR=';' MAPPED=yes ENDING=2;
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sexe.csv' SEP_CHAR=';' ENDING=2;
|
||||
SELECT * FROM t2;
|
||||
sexe genre
|
||||
0 Inconnu
|
||||
1 Masculin
|
||||
2 Feminin
|
||||
OPTIMIZE TABLE t2;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t2 optimize status OK
|
||||
SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
|
||||
nom prenom genre
|
||||
ESCOURCHE BENEDICTE Feminin
|
||||
@@ -122,7 +116,7 @@ LONES GERARD Masculin
|
||||
CREATE TABLE t3 (
|
||||
sitmat CHAR(1) KEY,
|
||||
situation CHAR(12) NOT NULL
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sitmat.csv' SEP_CHAR=';' MAPPED=yes ENDING=2;
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sitmat.csv' SEP_CHAR=';' ENDING=2;
|
||||
SELECT * FROM t3;
|
||||
sitmat situation
|
||||
. Inconnu
|
||||
@@ -132,9 +126,6 @@ L Union libre
|
||||
M Marie
|
||||
S Separe
|
||||
V Veuf
|
||||
OPTIMIZE TABLE t3;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t3 optimize status OK
|
||||
SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH';
|
||||
nom prenom genre situation
|
||||
FOCH BERNADETTE Feminin Inconnu
|
||||
|
@@ -34,9 +34,8 @@ SELECT * FROM t1 LIMIT 10;
|
||||
SELECT SUM(brut) FROM t1;
|
||||
|
||||
--echo #
|
||||
--echo # Make the indexes
|
||||
--echo # Test the indexes (made when creating the table)
|
||||
--echo #
|
||||
OPTIMIZE TABLE t1;
|
||||
SELECT * FROM t1 WHERE matricule = '0091';
|
||||
SELECT * FROM t1 WHERE nom = 'FOCH';
|
||||
SELECT * FROM t1 WHERE nom = 'FOCH' and prenom = 'DENIS';
|
||||
@@ -56,9 +55,8 @@ create table t2
|
||||
(
|
||||
sexe INT(1) KEY,
|
||||
genre CHAR(8) NOT NULL
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sexe.csv' SEP_CHAR=';' MAPPED=yes ENDING=2;
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sexe.csv' SEP_CHAR=';' ENDING=2;
|
||||
SELECT * FROM t2;
|
||||
OPTIMIZE TABLE t2;
|
||||
SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
|
||||
|
||||
--echo #
|
||||
@@ -67,9 +65,8 @@ SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
|
||||
CREATE TABLE t3 (
|
||||
sitmat CHAR(1) KEY,
|
||||
situation CHAR(12) NOT NULL
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sitmat.csv' SEP_CHAR=';' MAPPED=yes ENDING=2;
|
||||
) ENGINE=CONNECT TABLE_TYPE=CSV FILE_NAME='sitmat.csv' SEP_CHAR=';' ENDING=2;
|
||||
SELECT * FROM t3;
|
||||
OPTIMIZE TABLE t3;
|
||||
SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH';
|
||||
|
||||
--echo #
|
||||
|
@@ -2100,9 +2100,10 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
||||
if (tdbp || (tdbp= GetTDB(g))) {
|
||||
if (!((PTDBASE)tdbp)->GetDef()->Indexable()) {
|
||||
sprintf(g->Message, "Table %s is not indexable", tdbp->GetName());
|
||||
rc= RC_INFO;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
} else
|
||||
rc= ((PTDBASE)tdbp)->ResetTableOpt(g, true);
|
||||
if (((PTDBASE)tdbp)->ResetTableOpt(g, true))
|
||||
rc = HA_ERR_INTERNAL_ERROR;
|
||||
|
||||
} else
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
@@ -2299,7 +2300,7 @@ int ha_connect::index_init(uint idx, bool sorted)
|
||||
DBUG_PRINT("index_init", (g->Message));
|
||||
printf("index_init CONNECT: %s\n", g->Message);
|
||||
active_index= MAX_KEY;
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
} else {
|
||||
if (((PTDBDOX)tdbp)->To_Kindex->GetNum_K()) {
|
||||
if (((PTDBASE)tdbp)->GetFtype() != RECFM_NAF)
|
||||
@@ -2402,7 +2403,7 @@ int ha_connect::index_read(uchar * buf, const uchar * key, uint key_len,
|
||||
if (indexing > 0)
|
||||
rc= ReadIndexed(buf, op, key, key_len);
|
||||
else
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
|
||||
DBUG_RETURN(rc);
|
||||
} // end of index_read
|
||||
@@ -2423,7 +2424,7 @@ int ha_connect::index_next(uchar *buf)
|
||||
else if (!indexing)
|
||||
rc= rnd_next(buf);
|
||||
else
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
|
||||
DBUG_RETURN(rc);
|
||||
} // end of index_next
|
||||
@@ -2460,10 +2461,10 @@ int ha_connect::index_first(uchar *buf)
|
||||
if (indexing > 0)
|
||||
rc= ReadIndexed(buf, OP_FIRST);
|
||||
else if (indexing < 0)
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
else if (CntRewindTable(xp->g, tdbp)) {
|
||||
table->status= STATUS_NOT_FOUND;
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
} else
|
||||
rc= rnd_next(buf);
|
||||
|
||||
@@ -2504,7 +2505,7 @@ int ha_connect::index_next_same(uchar *buf, const uchar *key, uint keylen)
|
||||
else if (indexing > 0)
|
||||
rc= ReadIndexed(buf, OP_SAME);
|
||||
else
|
||||
rc= -1;
|
||||
rc= HA_ERR_INTERNAL_ERROR;
|
||||
|
||||
DBUG_RETURN(rc);
|
||||
} // end of index_next_same
|
||||
@@ -2911,7 +2912,7 @@ int ha_connect::external_lock(THD *thd, int lock_type)
|
||||
printf("%p external_lock: lock_type=%d\n", this, lock_type);
|
||||
|
||||
if (!g)
|
||||
DBUG_RETURN(-99);
|
||||
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
|
||||
|
||||
// Action will depend on lock_type
|
||||
switch (lock_type) {
|
||||
|
@@ -426,6 +426,9 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox)
|
||||
|
||||
if (dox) {
|
||||
// Remake eventual indexes
|
||||
if (Mode != MODE_UPDATE)
|
||||
To_SetCols = NULL; // Only used on Update
|
||||
|
||||
Columns = NULL; // Not used anymore
|
||||
Txfp->Reset(); // New start
|
||||
Use = USE_READY; // So the table can be reopened
|
||||
@@ -450,7 +453,7 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox)
|
||||
int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
|
||||
{
|
||||
int k, n;
|
||||
bool fixed, b = (pxdf != NULL);
|
||||
bool fixed, doit, b = (pxdf != NULL);
|
||||
PCOL *keycols, colp;
|
||||
PIXDEF xdp, sxp = NULL;
|
||||
PKPDEF kdp;
|
||||
@@ -514,13 +517,25 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
|
||||
// Auto increment key and fixed file: use an XXROW index
|
||||
continue; // XXROW index doesn't need to be made
|
||||
|
||||
// On Update, redo only indexes that are modified
|
||||
doit = !To_SetCols;
|
||||
n = 0;
|
||||
|
||||
if (sxp)
|
||||
xdp->SetID(sxp->GetID() + 1);
|
||||
|
||||
for (kdp = xdp->GetToKeyParts(); kdp; kdp = kdp->GetNext())
|
||||
for (kdp = xdp->GetToKeyParts(); kdp; kdp = kdp->GetNext()) {
|
||||
// Check whether this column was updated
|
||||
for (colp = To_SetCols; !doit && colp; colp = colp->GetNext())
|
||||
if (!stricmp(kdp->GetName(), colp->GetName()))
|
||||
doit = true;
|
||||
|
||||
keycols[n++] = ColDB(g, kdp->GetName(), 0);
|
||||
} // endfor kdp
|
||||
|
||||
// If no indexed columns were updated, don't remake the index
|
||||
if (!doit)
|
||||
continue;
|
||||
|
||||
k = xdp->GetNparts();
|
||||
|
||||
|
@@ -588,6 +588,10 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
|
||||
err:
|
||||
// We don't need the index anymore
|
||||
Close();
|
||||
|
||||
if (brc)
|
||||
printf("%s\n", g->Message);
|
||||
|
||||
return brc;
|
||||
} // end of Make
|
||||
|
||||
|
Reference in New Issue
Block a user