Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 125 additions & 15 deletions gdbpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def format_oid_list(lst, indent=0):
return add_indent(str(tlist), indent)


def format_node_list(lst, indent=0, newline=False):
def format_node_list(lst, indent=0, newline=False, kind='node'):
'format list containing Node values'

# handle NULL pointer (for List we return NIL)
Expand All @@ -104,12 +104,23 @@ def format_node_list(lst, indent=0, newline=False):
# walk the list until we reach the last item
while str(item) != '0x0':

# we assume the list contains Node instances, so grab a reference
# and cast it to (Node*)
node = cast(item['data']['ptr_value'], 'Node')
if (kind == 'node'):
# we assume the list contains Node instances, so grab a reference
# and cast it to (Node*)
node = cast(item['data']['ptr_value'], 'Node')

# append the formatted Node to the result list
tlist.append(format_node(node))
# append the value to the result list
tlist.append(format_node(node))
elif (kind == 'oid'):
val = (int(item['data']['oid_value']))

# append the formatted Node to the result list
tlist.append(val)
else:
val = (int(item['data']['int_value']))

# append the value to the result list
tlist.append(val)

# next item
item = item['next']
Expand Down Expand Up @@ -182,6 +193,18 @@ def format_node(node, indent=0):
'levelsup' : node['varlevelsup']
}

elif is_a(node, 'Const'):

# we assume the list contains Node instances (probably safe for Plan fields)
node = cast(node, 'Const')

retval = 'Const (consttype=%(type)s consttypmod=%(typmod)s constlen=%(len)s (raw)constvalue=%(value)s)' % {
'type' : node['consttype'],
'typmod' : node['consttypmod'],
'len' : node['constlen'],
'value' : node['constvalue']
}

elif is_a(node, 'RangeTblRef'):

node = cast(node, 'RangeTblRef')
Expand All @@ -192,14 +215,17 @@ def format_node(node, indent=0):

node = cast(node, 'RelOptInfo')

retval = 'RelOptInfo (kind=%(kind)s relids=%(relids)s rtekind=%(rtekind)s relid=%(relid)s rows=%(rows)s width=%(width)s fk=%(fk)s)' % {
retval = '''RelOptInfo (kind=%(kind)s relids=%(relids)s rtekind=%(rtekind)s relid=%(relid)s rows=%(rows)s width=%(width)s nparts=%(nparts)s
baserestrictinfo:
%(baserestrictinfo)s''' % {
'kind' : node['reloptkind'],
'rows' : node['rows'],
'width' : node['width'],
'width' : node['reltarget']['width'],
'relid' : node['relid'],
'relids' : format_relids(node['relids']),
'rtekind' : node['rtekind'],
'fk' : (int(node['has_fk_join']) == 1)
'nparts' : node['nparts'],
'baserestrictinfo' : format_node(node['baserestrictinfo'], True),
}

elif is_a(node, 'RangeTblEntry'):
Expand All @@ -224,6 +250,14 @@ def format_node(node, indent=0):

retval = format_node_list(node, 0, True)

elif is_a(node, 'OidList'):

retval = format_node_list(node, 0, False, 'oid')

elif is_a(node, 'IntList'):

retval = format_node_list(node, 0, False, 'int')

elif is_a(node, 'Plan'):

retval = format_plan_tree(node)
Expand Down Expand Up @@ -252,10 +286,61 @@ def format_node(node, indent=0):

node = cast(node, 'BoolExpr')

print node
print(node)

retval = format_bool_expr(node)

elif is_a(node, 'AppendRelInfo'):

node = cast(node, 'AppendRelInfo')

retval = 'AppendRelInfo (parent_relid=%(parent_relid)s child_relid=%(child_relid)s parent_reloid=%(parent_reloid)s)' % {
'parent_relid' : node['parent_relid'],
'child_relid' : node['child_relid'],
'parent_reloid' : node['parent_reloid']
}

elif is_a(node, 'EquivalenceMember'):

node = cast(node, 'EquivalenceMember')

retval = 'EquivalenceMember (em_expr=%(em_expr)s em_is_const=%(em_is_const)s em_is_child=%(em_is_child)s em_datatype=%(em_datatype)s)' % {
'em_expr' : format_node(node['em_expr']),
'em_is_const' : (int(node['em_is_const']) == 1),
'em_is_child' : (int(node['em_is_child']) == 1),
'em_datatype' : node['em_datatype']
}

elif is_a(node, 'EquivalenceClass'):

node = cast(node, 'EquivalenceClass')

retval = format_equivalence_class(node, indent)

elif is_a(node, 'PathKey'):

node = cast(node, 'PathKey')

retval = '''Pathkey
pk_eclass:
%(pk_eclass)s
pk_opfamily=%(pk_opfamily)s pk_strategy=%(pk_strategy)s pk_nulls_first=%(pk_nulls_first)s)''' % {
'pk_eclass' : format_node(node['pk_eclass'], 1),
'pk_opfamily' : node['pk_opfamily'],
'pk_strategy' : node['pk_strategy'],
'pk_nulls_first' : (int(node['pk_nulls_first'] == 1)),
}

elif is_a(node, 'PartitionedChildRelInfo'):

node = cast(node, 'PartitionedChildRelInfo')

retval = 'PartitionedChildRelInfo (parent_relid=%(parent_relid)s) child_rels=%(child_rels)s part_cols_updated=%(part_cols_updated)s' % {
'parent_relid' : node['parent_relid'],
'child_rels' : format_node(node['child_rels']),
'part_cols_updated' : (int(node['part_cols_updated']) == 1)
}

else:
# default - just print the type name
retval = format_type(type_str)
Expand All @@ -275,8 +360,11 @@ def format_planner_info(info, indent=0):
%(rel)s
rte:
%(rte)s
append_rel_list:
%(arl)s
''' % {'rel' : format_node_array(info['simple_rel_array'], 1, int(info['simple_rel_array_size'])),
'rte' : format_node_array(info['simple_rte_array'], 1, int(info['simple_rel_array_size']))}
'rte' : format_node_array(info['simple_rte_array'], 1, int(info['simple_rel_array_size'])),
'arl' : format_node_list(info['append_rel_list'], 1, True)}

return add_indent(retval, indent)

Expand All @@ -291,7 +379,7 @@ def format_planned_stmt(plan, indent=0):
can set tag: %(can_set_tag)s
transient: %(transient)s
row security: %(row_security)s

plan tree: %(tree)s
range table:
%(rtable)s
Expand Down Expand Up @@ -329,6 +417,28 @@ def format_bool_expr(node, indent=0):
%(clauses)s""" % { 'op' : node['boolop'],
'clauses' : format_node_list(node['args'], 1, True)}

def format_equivalence_class(node, indent=0):

retval = '''EquivalenceClass (ec_opfamilies=%(ec_opfamilies)s ec_collation=%(ec_collation)s
ec_members=%(ec_members)s
ec_sources=%(ec_sources)s ec_derives=%(ec_derives)s ec_has_const=%(ec_has_const)s ec_has_volatile=%(ec_has_volatile)s
ec_below_outer_join=%(ec_below_outer_join)s ec_broken=%(ec_broken)s ec_sortref=%(ec_sortref)s
ec_min_security=%(ec_min_security)s ec_max_security=%(ec_max_security)s)''' % {
'ec_opfamilies' : format_node(node['ec_opfamilies']),
'ec_collation' : node['ec_collation'],
'ec_members' : "\n" + format_node(node['ec_members'], 1),
'ec_sources' : format_node(node['ec_sources']),
'ec_derives' : format_node(node['ec_derives']),
'ec_has_const' : (int(node['ec_has_const'] == 1)),
'ec_has_volatile' : (int(node['ec_has_volatile'] == 1)),
'ec_below_outer_join' : (int(node['ec_below_outer_join'] == 1)),
'ec_broken' : (int(node['ec_broken'] == 1)),
'ec_sortref' : node['ec_sortref'],
'ec_min_security' : node['ec_min_security'],
'ec_max_security' : node['ec_max_security']
}

return retval
def is_a(n, t):
'''checks that the node has type 't' (just like IsA() macro)'''

Expand Down Expand Up @@ -372,15 +482,15 @@ def invoke (self, arg, from_tty):

arg_list = gdb.string_to_argv(arg)
if len(arg_list) != 1:
print "usage: pgprint var"
print("usage: pgprint var")
return

l = gdb.parse_and_eval(arg_list[0])

if not is_node(l):
print "not a node type"
print("not a node type")

print format_node(l)
print(format_node(l))


PgPrintCommand()