/ This fonction is used while making XDB2 block optimization. */ It constructs for each elligible columns, the sorted list of the */ distinct values existing in the column. This function uses an */ algorithm that permit to get several sets of distinct values by */ reading the table only once, which cannot be done using a standard */ SQL query.
| 1224 | /* SQL query. */ |
| 1225 | /***********************************************************************/ |
| 1226 | bool TDBDOS::GetDistinctColumnValues(PGLOBAL g, int nrec) |
| 1227 | { |
| 1228 | char *p; |
| 1229 | int rc, blk, n = 0; |
| 1230 | PDOSCOL colp; |
| 1231 | PDBUSER dup = PlgGetUser(g); |
| 1232 | |
| 1233 | /*********************************************************************/ |
| 1234 | /* Initialize progress information */ |
| 1235 | /*********************************************************************/ |
| 1236 | p = (char *)PlugSubAlloc(g, NULL, 48 + strlen(Name)); |
| 1237 | snprintf(p, 48 + strlen(Name), "%s%s", MSG(GET_DIST_VALS), Name); |
| 1238 | dup->Step = p; |
| 1239 | dup->ProgMax = GetProgMax(g); |
| 1240 | dup->ProgCur = 0; |
| 1241 | |
| 1242 | while ((rc = ReadDB(g)) == RC_OK) { |
| 1243 | for (colp = (PDOSCOL)Columns; colp; colp = (PDOSCOL)colp->Next) |
| 1244 | if (colp->Clustered == 2) |
| 1245 | if (colp->AddDistinctValue(g)) |
| 1246 | return true; // Too many distinct values |
| 1247 | |
| 1248 | #if defined(SOCKET_MODE) |
| 1249 | if (SendProgress(dup)) { |
| 1250 | safe_strcpy(g->Message, sizeof(g->Message), MSG(OPT_CANCELLED)); |
| 1251 | return true; |
| 1252 | } else |
| 1253 | #elif defined(THREAD) |
| 1254 | if (!dup->Step) { |
| 1255 | safe_strcpy(g->Message, sizeof(g->Message), MSG(OPT_CANCELLED)); |
| 1256 | return true; |
| 1257 | } else |
| 1258 | #endif // THREAD |
| 1259 | dup->ProgCur = GetProgCur(); |
| 1260 | |
| 1261 | n++; |
| 1262 | } // endwhile |
| 1263 | |
| 1264 | if (rc != RC_EF) |
| 1265 | return true; |
| 1266 | |
| 1267 | // Reset the number of table blocks |
| 1268 | //nrec = ((PDOSDEF)To_Def)->GetElemt(); (or default value) |
| 1269 | blk = (n + nrec - 1) / nrec; |
| 1270 | Txfp->Block = blk; // Useful mainly for ZLBFAM ??? |
| 1271 | |
| 1272 | // Set Nbm, Bmap for XDB2 columns |
| 1273 | for (colp = (PDOSCOL)Columns; colp; colp = (PDOSCOL)colp->Next) |
| 1274 | if (colp->Clustered == 2) { |
| 1275 | // colp->Cdp->SetNdv(colp->Ndv); |
| 1276 | colp->Nbm = (colp->Ndv + MAXBMP - 1) / MAXBMP; |
| 1277 | colp->Bmap = AllocValBlock(g, NULL, TYPE_INT, colp->Nbm * blk); |
| 1278 | } // endif Clustered |
| 1279 | |
| 1280 | return false; |
| 1281 | } // end of GetDistinctColumnValues |
| 1282 | |
| 1283 | /***********************************************************************/ |
nothing calls this directly
no test coverage detected