Changeset 19090
- Timestamp:
- 07/26/18 20:06:53 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19079 r19090 36 36 ("no-fill", po_switch(), "Do not fill events into the root file (mainly for debugging purposes, e.g. performance studies)") 37 37 ("delimiter", var<string>(""), "The delimiter used if contents are displayed with --display (default=\\t)") 38 ("explain", po_switch(), "Requests an EXPLAIN from the server (shows the serveroptimized query)") 38 39 ("var.*", var<string>(), "Predefined SQL user variables (@VAR)") 39 40 ("env.*", vars<string>(), "Predefined environment for substitutions in the query ($ENV)") … … 123 124 const bool noout = conf.Get<bool>("null"); 124 125 const bool nofill = conf.Get<bool>("no-fill"); 126 const bool explain = conf.Get<bool>("explain"); 125 127 const uint16_t verbose = conf.Get<uint16_t>("verbose"); 126 128 const uint16_t compression = conf.Get<uint16_t>("compression"); … … 244 246 } 245 247 248 // ------------------------- Explain query if requested -------------------- 249 250 if (explain) 251 { 252 try 253 { 254 const auto res0 = 255 connection.query("EXPLAIN FORMAT=JSON "+query).store(); 256 257 cout << res0[0][0] << endl; 258 cout << endl; 259 260 const mysqlpp::StoreQueryResult res1 = 261 connection.query("EXPLAIN "+query).store(); 262 263 for (size_t i=0; i<res1.num_rows(); i++) 264 { 265 const mysqlpp::Row &row = res1[i]; 266 267 cout << "\nid : " << row["id"]; 268 cout << "\nselect type : " << row["select_type"]; 269 270 if (!row["table"].is_null()) 271 cout << "\ntable : " << row["table"]; 272 273 if (!row["partitions"].is_null()) 274 cout << "\npartitions : " << row["partitions"]; 275 276 if (!row["key"].is_null()) 277 cout << "\nselected key : " << row["key"] << " [len=" << row["key_len"] << "] out of (" << row["possible_keys"] << ")"; 278 279 if (!row["type"].is_null()) 280 cout << "\njoin type : " << row["type"]; 281 282 //if (!row["possible_keys"].is_null()) 283 // cout << "\npossible_keys: " << row["possible_keys"]; 284 285 //if (!row["key_len"].is_null()) 286 // cout << "\nkey_len : " << row["key_len"]; 287 288 if (!row["ref"].is_null()) 289 cout << "\nref : (" << row["ref"] << ") compared to the index"; 290 291 if (!row["rows"].is_null()) 292 cout << "\nrows : " << row["rows"]; 293 294 if (!row["filtered"].is_null()) 295 cout << "\nfiltered : " << row["filtered"]; 296 297 if (!row["extra"].is_null()) 298 cout << "\nExtra : " << row["extra"]; 299 300 cout << endl; 301 } 302 303 cout << endl; 304 305 return 0; 306 307 const mysqlpp::StoreQueryResult res2 = 308 connection.query("SHOW WARNINGS").store(); 309 310 for (size_t i=0; i<res2.num_rows(); i++) 311 { 312 const mysqlpp::Row &row = res2[i]; 313 314 // 1003 // 315 cout << row["Level"] << '[' << row["Code"] << "]:\n"; 316 cout << row["Message"] << '\n' << endl; 317 318 } 319 320 } 321 catch (const exception &e) 322 { 323 cerr << query << "\n\n"; 324 cerr << "SQL query failed:\n" << e.what() << endl; 325 return 6; 326 } 327 328 return 0; 329 } 330 246 331 // -------------------------- Request data from database ------------------- 247 332 if (verbose>0) … … 262 347 TFile tfile(path, update?"UPDATE":(force?"RECREATE":"CREATE"), "Rootify SQL", compression); 263 348 if (tfile.IsZombie()) 264 return 6;349 return 7; 265 350 266 351 // ------------------------------------------------------------------------- … … 271 356 { 272 357 cerr << "Empty set returned... nothing to write." << endl; 273 return 7;358 return 8; 274 359 } 275 360
Note:
See TracChangeset
for help on using the changeset viewer.