Commit cb1847df authored by Olivier Bertrand's avatar Olivier Bertrand

- 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
parent 7a30ec72
...@@ -55,11 +55,8 @@ SELECT SUM(brut) FROM t1; ...@@ -55,11 +55,8 @@ SELECT SUM(brut) FROM t1;
SUM(brut) SUM(brut)
64319029 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'; SELECT * FROM t1 WHERE matricule = '0091';
matricule nom prenom sexe aanais mmnais ddentree ddnom brut net service sitmat formation 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 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 ...@@ -95,15 +92,12 @@ create table t2
( (
sexe INT(1) KEY, sexe INT(1) KEY,
genre CHAR(8) NOT NULL 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; SELECT * FROM t2;
sexe genre sexe genre
0 Inconnu 0 Inconnu
1 Masculin 1 Masculin
2 Feminin 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; SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
nom prenom genre nom prenom genre
ESCOURCHE BENEDICTE Feminin ESCOURCHE BENEDICTE Feminin
...@@ -122,7 +116,7 @@ LONES GERARD Masculin ...@@ -122,7 +116,7 @@ LONES GERARD Masculin
CREATE TABLE t3 ( CREATE TABLE t3 (
sitmat CHAR(1) KEY, sitmat CHAR(1) KEY,
situation CHAR(12) NOT NULL 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; SELECT * FROM t3;
sitmat situation sitmat situation
. Inconnu . Inconnu
...@@ -132,9 +126,6 @@ L Union libre ...@@ -132,9 +126,6 @@ L Union libre
M Marie M Marie
S Separe S Separe
V Veuf 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'; SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH';
nom prenom genre situation nom prenom genre situation
FOCH BERNADETTE Feminin Inconnu FOCH BERNADETTE Feminin Inconnu
......
...@@ -34,9 +34,8 @@ SELECT * FROM t1 LIMIT 10; ...@@ -34,9 +34,8 @@ SELECT * FROM t1 LIMIT 10;
SELECT SUM(brut) FROM t1; SELECT SUM(brut) FROM t1;
--echo # --echo #
--echo # Make the indexes --echo # Test the indexes (made when creating the table)
--echo # --echo #
OPTIMIZE TABLE t1;
SELECT * FROM t1 WHERE matricule = '0091'; SELECT * FROM t1 WHERE matricule = '0091';
SELECT * FROM t1 WHERE nom = 'FOCH'; SELECT * FROM t1 WHERE nom = 'FOCH';
SELECT * FROM t1 WHERE nom = 'FOCH' and prenom = 'DENIS'; SELECT * FROM t1 WHERE nom = 'FOCH' and prenom = 'DENIS';
...@@ -56,9 +55,8 @@ create table t2 ...@@ -56,9 +55,8 @@ create table t2
( (
sexe INT(1) KEY, sexe INT(1) KEY,
genre CHAR(8) NOT NULL 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; SELECT * FROM t2;
OPTIMIZE TABLE t2;
SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10; SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
--echo # --echo #
...@@ -67,9 +65,8 @@ SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10; ...@@ -67,9 +65,8 @@ SELECT nom, prenom, genre FROM t1 NATURAL JOIN t2 LIMIT 10;
CREATE TABLE t3 ( CREATE TABLE t3 (
sitmat CHAR(1) KEY, sitmat CHAR(1) KEY,
situation CHAR(12) NOT NULL 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; SELECT * FROM t3;
OPTIMIZE TABLE t3;
SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH'; SELECT nom, prenom, genre, situation FROM t1 NATURAL JOIN t2 NATURAL JOIN t3 WHERE nom = 'FOCH';
--echo # --echo #
......
...@@ -2100,9 +2100,10 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -2100,9 +2100,10 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt)
if (tdbp || (tdbp= GetTDB(g))) { if (tdbp || (tdbp= GetTDB(g))) {
if (!((PTDBASE)tdbp)->GetDef()->Indexable()) { if (!((PTDBASE)tdbp)->GetDef()->Indexable()) {
sprintf(g->Message, "Table %s is not indexable", tdbp->GetName()); sprintf(g->Message, "Table %s is not indexable", tdbp->GetName());
rc= RC_INFO; rc= HA_ERR_INTERNAL_ERROR;
} else } else
rc= ((PTDBASE)tdbp)->ResetTableOpt(g, true); if (((PTDBASE)tdbp)->ResetTableOpt(g, true))
rc = HA_ERR_INTERNAL_ERROR;
} else } else
rc= HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
...@@ -2299,7 +2300,7 @@ int ha_connect::index_init(uint idx, bool sorted) ...@@ -2299,7 +2300,7 @@ int ha_connect::index_init(uint idx, bool sorted)
DBUG_PRINT("index_init", (g->Message)); DBUG_PRINT("index_init", (g->Message));
printf("index_init CONNECT: %s\n", g->Message); printf("index_init CONNECT: %s\n", g->Message);
active_index= MAX_KEY; active_index= MAX_KEY;
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
} else { } else {
if (((PTDBDOX)tdbp)->To_Kindex->GetNum_K()) { if (((PTDBDOX)tdbp)->To_Kindex->GetNum_K()) {
if (((PTDBASE)tdbp)->GetFtype() != RECFM_NAF) if (((PTDBASE)tdbp)->GetFtype() != RECFM_NAF)
...@@ -2402,7 +2403,7 @@ int ha_connect::index_read(uchar * buf, const uchar * key, uint key_len, ...@@ -2402,7 +2403,7 @@ int ha_connect::index_read(uchar * buf, const uchar * key, uint key_len,
if (indexing > 0) if (indexing > 0)
rc= ReadIndexed(buf, op, key, key_len); rc= ReadIndexed(buf, op, key, key_len);
else else
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
DBUG_RETURN(rc); DBUG_RETURN(rc);
} // end of index_read } // end of index_read
...@@ -2423,7 +2424,7 @@ int ha_connect::index_next(uchar *buf) ...@@ -2423,7 +2424,7 @@ int ha_connect::index_next(uchar *buf)
else if (!indexing) else if (!indexing)
rc= rnd_next(buf); rc= rnd_next(buf);
else else
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
DBUG_RETURN(rc); DBUG_RETURN(rc);
} // end of index_next } // end of index_next
...@@ -2460,10 +2461,10 @@ int ha_connect::index_first(uchar *buf) ...@@ -2460,10 +2461,10 @@ int ha_connect::index_first(uchar *buf)
if (indexing > 0) if (indexing > 0)
rc= ReadIndexed(buf, OP_FIRST); rc= ReadIndexed(buf, OP_FIRST);
else if (indexing < 0) else if (indexing < 0)
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
else if (CntRewindTable(xp->g, tdbp)) { else if (CntRewindTable(xp->g, tdbp)) {
table->status= STATUS_NOT_FOUND; table->status= STATUS_NOT_FOUND;
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
} else } else
rc= rnd_next(buf); rc= rnd_next(buf);
...@@ -2504,7 +2505,7 @@ int ha_connect::index_next_same(uchar *buf, const uchar *key, uint keylen) ...@@ -2504,7 +2505,7 @@ int ha_connect::index_next_same(uchar *buf, const uchar *key, uint keylen)
else if (indexing > 0) else if (indexing > 0)
rc= ReadIndexed(buf, OP_SAME); rc= ReadIndexed(buf, OP_SAME);
else else
rc= -1; rc= HA_ERR_INTERNAL_ERROR;
DBUG_RETURN(rc); DBUG_RETURN(rc);
} // end of index_next_same } // end of index_next_same
...@@ -2911,7 +2912,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -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); printf("%p external_lock: lock_type=%d\n", this, lock_type);
if (!g) if (!g)
DBUG_RETURN(-99); DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
// Action will depend on lock_type // Action will depend on lock_type
switch (lock_type) { switch (lock_type) {
......
...@@ -426,6 +426,9 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox) ...@@ -426,6 +426,9 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox)
if (dox) { if (dox) {
// Remake eventual indexes // Remake eventual indexes
if (Mode != MODE_UPDATE)
To_SetCols = NULL; // Only used on Update
Columns = NULL; // Not used anymore Columns = NULL; // Not used anymore
Txfp->Reset(); // New start Txfp->Reset(); // New start
Use = USE_READY; // So the table can be reopened Use = USE_READY; // So the table can be reopened
...@@ -450,7 +453,7 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox) ...@@ -450,7 +453,7 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dox)
int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
{ {
int k, n; int k, n;
bool fixed, b = (pxdf != NULL); bool fixed, doit, b = (pxdf != NULL);
PCOL *keycols, colp; PCOL *keycols, colp;
PIXDEF xdp, sxp = NULL; PIXDEF xdp, sxp = NULL;
PKPDEF kdp; PKPDEF kdp;
...@@ -514,13 +517,25 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add) ...@@ -514,13 +517,25 @@ int TDBDOS::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)
// Auto increment key and fixed file: use an XXROW index // Auto increment key and fixed file: use an XXROW index
continue; // XXROW index doesn't need to be made continue; // XXROW index doesn't need to be made
// On Update, redo only indexes that are modified
doit = !To_SetCols;
n = 0; n = 0;
if (sxp) if (sxp)
xdp->SetID(sxp->GetID() + 1); 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); 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(); k = xdp->GetNparts();
......
...@@ -588,6 +588,10 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) ...@@ -588,6 +588,10 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
err: err:
// We don't need the index anymore // We don't need the index anymore
Close(); Close();
if (brc)
printf("%s\n", g->Message);
return brc; return brc;
} // end of Make } // end of Make
......
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