WL#2473: Item tree dumper

Affects: Server-7.1   —   Status: Un-Assigned   —   Priority: Medium

For potential developers in the community, as well as new developers who join 
the MySQL AB, it would be nice to have the following: 
A dump_Item_tree() function which recurses through the Item structure, and 
prints all info specific to each item. 
I realize this would take additional code in each Item member, so this should 
only be enabled when MySQL is built with a special debug flag enabled. The 
output could simply go into a file: the original query string, then the 
and a delimiter line === to separate it from a possible next one. 
The dump code and the output together would give potential server developers 
insight into how the Item structure works. As each Item would only print the 
info relevant for its type, the person will be able to see things more 
As we wish to encourage more involvement in server coding, and also want to 
our own new developers a quick start, this seems like a good way. It still 
requires some homework, but a decent programmer will be able to work it out. 
The output format does not need to be particularly pretty... so let's not let 
this  stall because of the bikeshed colour... simple all pertinent info 
belonging with each Item. "label: content". 
+-+--+-item Label1: bla 
  |  |      Label2: bla 
  |  | 
  |  +-item ... 
  +-item ... 
Can be used to lay out the structure. 
Possible code to get someone started (contrib by atcurtis): 
void node_dump(Item *elem, String *prefix) 
  printf("%s Blah blah blah...\n",prefix); 
void dump_item(Item *elem, char *pfx1=0, char *pfx2=0) 
  String pfx2; 
  char *s; 
  if (pfx1) 
    pfx1= ""; 
  if (elem->type() != FUNC_ITEM || !((Item_func *) elem)->argument_count()) 
    s= "--"; 
    my_pfx2.append("  "); 
    s= "+-"; 
    my_pfx2.append("| "); 
  printf("%s%s Item: 0x%08x\n", pfx1, s, elem); 
  node_dump(elem, pfx2.c_ptr()); 
  if (elem->type() != FUNC_ITEM || !((Item_func *) elem)->argument_count()) 
    String pfx1; 
    uint arg_count= ((Item_func *) elem)->argument_count(); 
    Item** args= ((Item_func *) elem)->arguments(); 
    for (int i=0; i<arg_count; i++) 
      dump_item(args[i], my_pfx1.c_ptr(), my_pfx2.c_ptr());