| 1 |
# |
| 2 |
# When developing new tests, consider using a specific SELECT from ndbinfo |
| 3 |
# tables (including the wl#11968 tables: dictionary_tables, dictionary_columns, |
| 4 |
# blobs, index_columns, foreign_keys, events) to get brief and clear results. |
| 5 |
# |
| 6 |
# This file is meant to replace some uses of ndb_desc_print.inc with faster |
| 7 |
# and more compact queries of ndbinfo tables. |
| 8 |
# |
| 9 |
# Set $ndb_describe_table to table name |
| 10 |
# Set $ndb_describe_db to database name |
| 11 |
# |
| 12 |
# With $ndb_describe_indexes=1, include index info (like ndb_desc -i) |
| 13 |
# With $ndb_describe_blobs=1, include blob info (like ndb_desc -b) |
| 14 |
# |
| 15 |
# The basic table description is almost perfectly backward-compatible with |
| 16 |
# ndb_desc. The index and blob descriptions, however, differ substantial ways, |
| 17 |
# since "ndb_desc -i" prints details of hidden index tables that are not |
| 18 |
# generally available in NDB API. |
| 19 |
# |
| 20 |
# "ndb_desc -p" is not emulated at all here. It computes data distribution |
| 21 |
# in a way that is not yet available anywhere else. |
| 22 |
|
| 23 |
assert($ndb_describe_table); |
| 24 |
if(! $ndb_describe_db) |
| 25 |
{ |
| 26 |
let $ndb_describe_db=test; |
| 27 |
} |
| 28 |
|
| 29 |
disable_query_log ONCE; |
| 30 |
disable_result_log ONCE; |
| 31 |
eval SELECT table_id into @describe_table_id from ndbinfo.dictionary_tables |
| 32 |
WHERE table_name = "$ndb_describe_table" |
| 33 |
AND database_name = "$ndb_describe_db"; |
| 34 |
|
| 35 |
disable_query_log ONCE; |
| 36 |
eval SELECT CONCAT( |
| 37 |
"Version: Any", |
| 38 |
"\nFragment type: ", fragment_type, |
| 39 |
"\nK Value: 6", |
| 40 |
"\nMin load factor: 78", |
| 41 |
"\nMax load factor: 80", |
| 42 |
"\nTemporary table: ", IF(logging, "no", "yes"), |
| 43 |
"\nNumber of attributes: ", attributes, |
| 44 |
"\nNumber of primary keys: ", primary_key_cols, |
| 45 |
"\nLength of frm data: XXX", |
| 46 |
"\nMax Rows: ", max_rows, |
| 47 |
"\nRow Checksum: ", checksum, |
| 48 |
"\nRow GCI: ", contains_GCI, |
| 49 |
"\nSingleUserMode: ", single_user_mode-1, |
| 50 |
"\nForceVarPart: ", force_var_part, |
| 51 |
"\nPartitionCount: ", partitions, |
| 52 |
"\nFragmentCount: ", fragments, |
| 53 |
"\nPartitionBalance: ", partition_balance, |
| 54 |
"\nExtraRowGciBits: ", GCI_bits, |
| 55 |
"\nExtraRowAuthorBits: ", author_bits, |
| 56 |
"\nTableStatus: ", status, |
| 57 |
"\nTable options:", IF(read_backup, " readbackup", ""), |
| 58 |
IF(read_backup AND fully_replicated, ", ", ""), |
| 59 |
IF(fully_replicated, "fullyreplicated", ""), |
| 60 |
IF(CHAR_LENGTH(hash_map), CONCAT("\nHashMap: ", hash_map), "") |
| 61 |
) AS "-- $ndb_describe_table --" |
| 62 |
FROM ndbinfo.dictionary_tables |
| 63 |
WHERE table_id = @describe_table_id; |
| 64 |
|
| 65 |
let $tablespace=`SELECT tablespace FROM ndbinfo.dictionary_tables |
| 66 |
WHERE table_id = @describe_table_id`; |
| 67 |
if($tablespace) |
| 68 |
{ |
| 69 |
disable_query_log ONCE; |
| 70 |
eval SELECT CONCAT("Tablespace: ", fq_name) AS "Tablespace id: XX" |
| 71 |
FROM ndbinfo.dict_obj_info where id=$tablespace and type=20; |
| 72 |
} |
| 73 |
|
| 74 |
disable_query_log ONCE; |
| 75 |
replace_regex /NDB\$BLOB_[0-9]*_/NDB$BLOB_XX_/; |
| 76 |
SELECT CONCAT( |
| 77 |
name, " ", column_type, " ", |
| 78 |
IF(c.primary_key, "PRIMARY KEY", nullable), |
| 79 |
IF(c.partition_key, " DISTRIBUTION KEY", ""), |
| 80 |
" AT=", array_type, |
| 81 |
" ST=", storage_type, |
| 82 |
IF(c.auto_inc, " AUTO_INCR", ""), |
| 83 |
IF(ISNULL(blob_table_name), "", concat(" BV=2 BT=", blob_table_name)), |
| 84 |
IF(c.dynamic, " DYNAMIC", ""), |
| 85 |
IF(CHAR_LENGTH(c.default_value), CONCAT(" DEFAULT ", c.default_value), "") |
| 86 |
) |
| 87 |
AS "-- Attributes --" |
| 88 |
FROM ndbinfo.dictionary_columns c |
| 89 |
JOIN ndbinfo.dictionary_tables t USING (table_id) |
| 90 |
LEFT OUTER JOIN ndbinfo.blobs b USING (table_id, column_id) |
| 91 |
WHERE table_id = @describe_table_id; |
| 92 |
|
| 93 |
echo -- Indexes -- ; |
| 94 |
|
| 95 |
disable_query_log ONCE; |
| 96 |
disable_result_log ONCE; |
| 97 |
SELECT |
| 98 |
CONCAT("PRIMARY KEY(", REPLACE(primary_key,",",", "), ") - UniqueHashIndex") |
| 99 |
INTO @pkdescriptor FROM ndbinfo.dictionary_tables |
| 100 |
WHERE table_id = @describe_table_id; |
| 101 |
let $pk_descriptor=`SELECT @pkdescriptor`; |
| 102 |
|
| 103 |
disable_query_log ONCE; |
| 104 |
EVAL SELECT |
| 105 |
CONCAT(index_name, |
| 106 |
"(", REPLACE(columns,",",", "), ") - ", |
| 107 |
REPLACE(REPLACE(type_name," hash","Hash")," index","Index")) |
| 108 |
AS "$pk_descriptor" |
| 109 |
FROM ndbinfo.index_columns |
| 110 |
JOIN ndbinfo.dict_obj_types ON index_type = type_id |
| 111 |
WHERE table_id = @describe_table_id |
| 112 |
ORDER BY index_object_id; |
| 113 |
|
| 114 |
if($ndb_describe_indexes) |
| 115 |
{ |
| 116 |
disable_query_log ONCE; |
| 117 |
SELECT |
| 118 |
CONCAT("-- ", table_name, "/", index_name, " --\n", |
| 119 |
"Attributes: ", columns, "\n", |
| 120 |
"Index Type: ", type_name, "\n", |
| 121 |
"Index Status: ", status, "\n", |
| 122 |
"Partitions: ", tab_partitions, "\n", |
| 123 |
"Fragments: ", tab_fragments) AS "" |
| 124 |
FROM ndbinfo.index_columns t1 |
| 125 |
JOIN ndbinfo.dict_obj_types ON t1.index_type = type_id |
| 126 |
JOIN ndbinfo.table_distribution_status t3 ON index_object_id = t3.table_id |
| 127 |
WHERE t1.table_id = @describe_table_id |
| 128 |
ORDER BY index_object_id; |
| 129 |
} |
| 130 |
|
| 131 |
if($ndb_describe_blobs) |
| 132 |
{ |
| 133 |
echo; |
| 134 |
disable_query_log ONCE; |
| 135 |
replace_regex /NDB\$BLOB_[0-9]*_/NDB$BLOB_XX_/; |
| 136 |
SELECT CONCAT( |
| 137 |
"Column name: ", column_name, |
| 138 |
"\nInline size: ", inline_size, |
| 139 |
"\nPart size: ", part_size, |
| 140 |
"\nStipe size: ", stripe_size, |
| 141 |
"\nBlob Table Name: ", blob_table_name, |
| 142 |
"\nFragment type: ", fragment_type, |
| 143 |
"\nTemporary table: ", IF(logging, "no", "yes"), |
| 144 |
"\nNumber of attributes: ", attributes, |
| 145 |
"\nPrimary key: ", primary_key, |
| 146 |
"\nMax Rows: ", max_rows, |
| 147 |
"\nRow Checksum: ", checksum, |
| 148 |
"\nRow GCI: ", contains_GCI, |
| 149 |
"\nSingleUserMode: ", single_user_mode-1, |
| 150 |
"\nDynamic: ", dynamic, |
| 151 |
"\nPartitionCount: ", partitions, |
| 152 |
"\nFragmentCount: ", fragments, |
| 153 |
"\nPartitionBalance: ", partition_balance, |
| 154 |
"\nExtraRowGciBits: ", GCI_bits, |
| 155 |
"\nExtraRowAuthorBits: ", author_bits, |
| 156 |
"\nTableStatus: ", status, |
| 157 |
"\nTable options:", IF(read_backup, " readbackup", ""), |
| 158 |
IF(read_backup AND fully_replicated, ", ", ""), |
| 159 |
IF(fully_replicated, "fullyreplicated", ""), |
| 160 |
"\nHashMap: ", hash_map, |
| 161 |
"\n") AS "-- Blob Tables --" |
| 162 |
FROM ndbinfo.dictionary_tables t1 |
| 163 |
JOIN ndbinfo.blobs on t1.table_name = blob_table_name |
| 164 |
WHERE blobs.table_id = @describe_table_id; |
| 165 |
} |
| 166 |
|
| 167 |
# Reset argument variable in order to detect missing assignment |
| 168 |
let $ndb_describe_table=; |
| 169 |
let $ndb_describe_db=; |
| 170 |
let $ndb_describe_indexes=0; |
| 171 |
let $ndb_describe_blobs=0; |