Commit fd166e03 authored by Olivier Bertrand's avatar Olivier Bertrand

Fix MDEV-12653 Cannot add index for ZIP CONNECT table

  modified:   storage/connect/filamzip.cpp
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/tabdos.cpp
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/xindex.cpp
parent ce3c7cd9
...@@ -740,7 +740,13 @@ int UNZFAM::Cardinality(PGLOBAL g) ...@@ -740,7 +740,13 @@ int UNZFAM::Cardinality(PGLOBAL g)
int card = -1; int card = -1;
int len = GetFileLength(g); int len = GetFileLength(g);
card = (len / (int)Lrecl) * 2; // Estimated ??? if (len) {
// Estimated ???
card = (len / (int)Lrecl) * 2;
card = card ? card : 10; // Lrecl can be too big
} else
card = 0;
return card; return card;
} // end of Cardinality } // end of Cardinality
......
...@@ -4567,9 +4567,11 @@ int ha_connect::external_lock(THD *thd, int lock_type) ...@@ -4567,9 +4567,11 @@ int ha_connect::external_lock(THD *thd, int lock_type)
DBUG_RETURN(0); DBUG_RETURN(0);
} else if (g->Xchk) { } else if (g->Xchk) {
if (!tdbp) { if (!tdbp) {
if (!(tdbp= GetTDB(g))) if (!(tdbp = GetTDB(g))) {
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error
else if (!tdbp->GetDef()->Indexable()) { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
DBUG_RETURN(0);
} else if (!tdbp->GetDef()->Indexable()) {
sprintf(g->Message, "external_lock: Table %s is not indexable", tdbp->GetName()); sprintf(g->Message, "external_lock: Table %s is not indexable", tdbp->GetName());
// DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error // DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
......
...@@ -355,7 +355,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -355,7 +355,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
if (Zipped) { if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (Recfm == RECFM_VAR) { if (Recfm == RECFM_VAR) {
if (mode == MODE_READ || mode == MODE_ANY) { if (mode == MODE_READ || mode == MODE_ANY || mode == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
} else if (mode == MODE_INSERT) { } else if (mode == MODE_INSERT) {
txfp = new(g) ZIPFAM(this); txfp = new(g) ZIPFAM(this);
...@@ -366,7 +366,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -366,7 +366,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
tdbp = new(g) TDBDOS(this, txfp); tdbp = new(g) TDBDOS(this, txfp);
} else { } else {
if (mode == MODE_READ || mode == MODE_ANY) { if (mode == MODE_READ || mode == MODE_ANY || mode == MODE_ALTER) {
txfp = new(g) UZXFAM(this); txfp = new(g) UZXFAM(this);
} else if (mode == MODE_INSERT) { } else if (mode == MODE_INSERT) {
txfp = new(g) ZPXFAM(this); txfp = new(g) ZPXFAM(this);
......
...@@ -517,7 +517,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -517,7 +517,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
/*******************************************************************/ /*******************************************************************/
if (Zipped) { if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (mode == MODE_READ || mode == MODE_ANY) { if (mode == MODE_READ || mode == MODE_ANY || mode == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
} else if (mode == MODE_INSERT) { } else if (mode == MODE_INSERT) {
txfp = new(g) ZIPFAM(this); txfp = new(g) ZIPFAM(this);
......
...@@ -494,7 +494,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -494,7 +494,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
#endif // !MONGO_SUPPORT #endif // !MONGO_SUPPORT
} else if (Zipped) { } else if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_READX) { if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
} else if (m == MODE_INSERT) { } else if (m == MODE_INSERT) {
txfp = new(g) ZIPFAM(this); txfp = new(g) ZIPFAM(this);
...@@ -539,7 +539,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) ...@@ -539,7 +539,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
} else { } else {
if (Zipped) { if (Zipped) {
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_READX) { if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) {
txfp = new(g) UNZFAM(this); txfp = new(g) UNZFAM(this);
} else if (m == MODE_INSERT) { } else if (m == MODE_INSERT) {
strcpy(g->Message, "INSERT supported only for zipped JSON when pretty=0"); strcpy(g->Message, "INSERT supported only for zipped JSON when pretty=0");
......
...@@ -965,7 +965,7 @@ bool XINDEX::Init(PGLOBAL g) ...@@ -965,7 +965,7 @@ bool XINDEX::Init(PGLOBAL g)
// For DBF tables, Cardinality includes bad or soft deleted lines // For DBF tables, Cardinality includes bad or soft deleted lines
// that are not included in the index, and can be larger then the // that are not included in the index, and can be larger then the
// index size. // index size.
estim = (Tdbp->Ftype == RECFM_DBF); estim = (Tdbp->Ftype == RECFM_DBF || Tdbp->Txfp->GetAmType() == TYPE_AM_ZIP);
n = Tdbp->Cardinality(g); // n is exact table size n = Tdbp->Cardinality(g); // n is exact table size
} else { } else {
// Variable table not optimized // Variable table not optimized
......
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