Operational Model
ctdbdistinct is a utility for managing distinct key counts in SQL tables and databases.
Command Syntax
ctdbdistinct.exe -s server -c command [-d database][-t table][-u user][-p passwd]
Options
The -c enable command assigns the CTDBINDEX_DUPCNTFLAG to all non-unique indexes in a database or a specific table. These indexes will start tracking distinct key counts. This command is intended to upgrade existing tables or databases created without distinct key counts.
The -c check command compares the distinct key counts stored in indexes with the actual key counts, and lists tables that fail validation. It operates while the table(s) may be in use by other users. Tables that fail the validation are logged to stdout.
The -c repair command updates distinct-key-count indexes with the current number of distinct key counts. It can run when tables are in use by other users. It briefly acquires a table read lock to update the distinct key count.
If the distinct count exceeds the desired limit of 2 per leaf node, it logs "Distinct key discrepancy: 20 != 32". If it exceeds 1/3 of the total keys in the index, the count will likely lead to bad SQL optimizer plans. It logs "Extreme distinct key discrepancy: 5 != 435123". When a table’s indexes should be repaired, it logs "Incorrect Distinct counts for table myTable index i_myTable_names".
Example 1:
Check distinct key counts on all files in the ctreeSQL database.
ctdbdistinct -s FAIRCOMS -c check -d ctreeSQL -u admin -p ADMIN
Example 2:
Repair distinct key counts on one table ./ctreeSQL.dbs/mytable.dat
ctdbdistinct -s FAIRCOMS -c repair -t ./ctreeSQL.dbs/mytable.dat -u admin -p ADMIN