pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Inadequate infrastructure for NextValueExpr
7+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2017-07-14 decb08ebdf  Code review for NextValueExpr expression node type.
* Inadequate infrastructure for NextValueExpr
@ 2017-07-13 21:34  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2017-07-13 21:34 UTC (permalink / raw)
  To: pgsql-hackers

Somebody decided they could add a new primnode type without bothering to
build out very much infrastructure for it.  Thus:

regression=# create table foo (f1 int, f2 int generated always as identity);
CREATE TABLE
regression=# insert into foo values(1);
INSERT 0 1
regression=# explain verbose insert into foo values(1);
ERROR:  unrecognized node type: 146

because ruleutils.c has never heard of NextValueExpr.  The lack of
outfuncs/readfuncs support for it is rather distressing as well.
That doesn't break parallel queries today, because (I think)
you can't get one of these nodes in a parallelizable query, but it
is going to cause problems for debugging.  It will also break
(more or less) pg_stat_statements.  I also wonder whether costsize.c
oughtn't be charging some estimated execution cost for it.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-07-14 01:46  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 7+ messages in thread

From: Thomas Munro @ 2017-07-14 01:46 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers

On Fri, Jul 14, 2017 at 9:34 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Somebody decided they could add a new primnode type without bothering to
> build out very much infrastructure for it.  Thus:
>
> regression=# create table foo (f1 int, f2 int generated always as identity);
> CREATE TABLE
> regression=# insert into foo values(1);
> INSERT 0 1
> regression=# explain verbose insert into foo values(1);
> ERROR:  unrecognized node type: 146
>
> because ruleutils.c has never heard of NextValueExpr.  The lack of
> outfuncs/readfuncs support for it is rather distressing as well.
> That doesn't break parallel queries today, because (I think)
> you can't get one of these nodes in a parallelizable query, but it
> is going to cause problems for debugging.  It will also break
> (more or less) pg_stat_statements.  I also wonder whether costsize.c
> oughtn't be charging some estimated execution cost for it.

I wrote a script to cross-check various node handling functions and it told me:

T_NextValueExpr not handled in outfuncs.c
T_ObjectWithArgs not handled in outfuncs.c
T_AccessPriv not handled in outfuncs.c
T_CreateOpClassItem not handled in outfuncs.c
T_FunctionParameter not handled in outfuncs.c
T_InferClause not handled in outfuncs.c
T_OnConflictClause not handled in outfuncs.c
T_RoleSpec not handled in outfuncs.c
T_PartitionCmd not handled in outfuncs.c
T_NamedTuplestoreScan can be produced by outfuncs.c with tagname
NAMEDTUPLESTORESCAN but that tagname is not recognized by readfuncs.c
T_Alias not handled in ruleutils.c
T_RangeVar not handled in ruleutils.c
T_Expr not handled in ruleutils.c
T_CaseWhen not handled in ruleutils.c
T_TargetEntry not handled in ruleutils.c
T_RangeTblRef not handled in ruleutils.c
T_JoinExpr not handled in ruleutils.c
T_FromExpr not handled in ruleutils.c
T_OnConflictExpr not handled in ruleutils.c
T_IntoClause not handled in ruleutils.c
T_NextValueExpr not handled in ruleutils.c

It classifies all node types into categories PLAN NODES, PRIMITIVE
NODES, ... using the per-group comments in nodes.h, and then checks
some rules that I inferred (obviously incorrectly) about which of
those categories should be handled by copy, out, equal, read and
get_rule_expr functions and also checks that readfuncs.c and
outfuncs.c agree on the name string.  It needs some work though:
anyone got any ideas on how to improve the categories and rules to
make it right?  To use this approach, it would need to be the case
that each checked function exhaustively handles a subset of node tags
that can be described by listing those categories.

That revealed a defect in commit
18ce3a4ab22d2984f8540ab480979c851dae5338 which I think should be
corrected with something like the attached, though I'm not sure if
it's possible to reach it.  It would be nice to do something more
mechanised for this type of code...

-- 
Thomas Munro
http://www.enterprisedb.com

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

read-namedtuplestorescan.patch (application/octet-stream, 877B) download diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 1380703cbc6..73c82826ed3 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -1876,6 +1876,21 @@ _readCteScan(void) } /* + * _readNamedtuplestoreScan + */ +static NamedTuplestoreScan * +_readNamedTuplestoreScan(void) +{ + READ_LOCALS(NamedTuplestoreScan); + + ReadCommonScan(&local_node->scan); + + READ_STRING_FIELD(enrname); + + READ_DONE(); +} + +/* * _readWorkTableScan */ static WorkTableScan * @@ -2587,6 +2602,8 @@ parseNodeString(void) return_value = _readTableFuncScan(); else if (MATCH("CTESCAN", 7)) return_value = _readCteScan(); + else if (MATCH("NAMEDTUPLESTORESCAN", 19)) + return_value = _readNamedTuplestoreScan(); else if (MATCH("WORKTABLESCAN", 13)) return_value = _readWorkTableScan(); else if (MATCH("FOREIGNSCAN", 11))
check_node_infrastructure.py (text/x-python-script, 5.0K) download #!/usr/bin/env python # # Cross-check node handling code in PostgreSQL looking for bugs. import re def scan_node_categories(path): """Find all type tags and put them into categories.""" results = {} with open(path) as file: current_list = [] results["INVALID"] = current_list for line in file: matches = re.search(r"TAGS FOR ([A-Z].*(NODES|STUFF))", line) if matches: category = matches.group(1) current_list = [] results[category] = current_list continue matches = re.search(r"(T_[a-zA-Z0-9_]+)", line) if matches: assert current_list != None tag = matches.group(1) current_list.append(tag) return results def scan_switch(path, function): """Find all cases handled by "function" in translation unit "path".""" cases = [] in_function = False with open(path) as file: for line in file: if line.startswith(function + "("): in_function = True elif line.startswith("}"): in_function = False elif in_function: matches = re.search(r"case (T_.+):", line) if matches: cases.append(matches.group(1)) return cases def scan_read_tagnames(path): """Find all tagnames that readfuncs.c recognizes.""" results = [] with open(path) as file: for line in file: matches = re.search("MATCH\(\"([A-Z]+)\", ([0-9]+)", line) if matches: tagname = matches.group(1) length = int(matches.group(2)) results.append(tagname) if length != len(tagname): print "Unexpected length:", line return results def scan_out_tagnames(path): """Learn what tagname outfuncs.c uses to output each type.""" results = {} current_tag = None with open(path) as file: for line in file: matches = re.match(r"_out.*, const ([^ ]+) \*", line) if matches: # see makeNode macro definition: typedef Foo must have enum T_Foo current_tag = "T_" + matches.group(1) elif line.startswith("}"): current_tag = None elif current_tag != None: matches = re.search("WRITE_NODE_TYPE\(\"([A-Z]+)\"\)", line) if matches: results[current_tag] = matches.group(1) return results # cases that don't fit the general pattern for out/read/equals but we'll just # trust that they work special_cases = [ "T_List", "T_IntList", "T_OidList", "T_Integer", "T_Float", "T_String", "T_BitString", "T_Expr", "T_Null", "T_Value" ] node_categories = scan_node_categories("src/include/nodes/nodes.h") copyfuncs = scan_switch("src/backend/nodes/copyfuncs.c", "copyObjectImpl") equalfuncs = scan_switch("src/backend/nodes/equalfuncs.c", "equal") outfuncs = scan_switch("src/backend/nodes/outfuncs.c", "outNode") get_rule_expr = scan_switch("src/backend/utils/adt/ruleutils.c", "get_rule_expr") exprSetCollation = scan_switch("src/backend/nodes/nodeFuncs.c", "exprSetCollation") expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_walker") expression_tree_mutator = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator") raw_expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator") outfuncs_tagname_map = scan_out_tagnames("src/backend/nodes/outfuncs.c") readfuncs_tagnames = scan_read_tagnames("src/backend/nodes/readfuncs.c") # the following node categories must be supported by copy, out for tag in node_categories["PLAN NODES"] + node_categories["PRIMITIVE NODES"] + node_categories["VALUE NODES"] + node_categories["LIST NODES"] + node_categories["PARSE TREE NODES"]: if tag in special_cases: continue if tag not in copyfuncs: print "%s not handled in copyfuncs.c" % (tag,) if tag not in outfuncs: print "%s not handled in outfuncs.c" % (tag,) # the following node categories must be supported by equals for tag in node_categories["PRIMITIVE NODES"] + node_categories["VALUE NODES"] + node_categories["LIST NODES"] + node_categories["PARSE TREE NODES"]: if tag in special_cases: continue if tag not in equalfuncs: print "%s not handled in equalfuncs.c" % (tag,) # the following node categories must be supported by parseNodeString using the # tagname that is output by outfuncs.c for tag in node_categories["PLAN NODES"] + node_categories["PRIMITIVE NODES"]: if tag in outfuncs_tagname_map and outfuncs_tagname_map[tag] not in readfuncs_tagnames: print "%s can be produced by outfuncs.c with tagname %s but that tagname is not recognized by readfuncs.c" % (tag, outfuncs_tagname_map[tag]) # the following node categories must be supported by ruleutils.c for tag in node_categories["PRIMITIVE NODES"]: if tag not in get_rule_expr: print "%s not handled in ruleutils.c" % (tag,) # TODO: figure out what the deal is with the various tree walker functions #for tag in node_categories["PRIMITIVE NODES"] + node_categories["PLAN NODES"] + node_categories["PARSE TREE NODES"]: # if tag not in raw_expression_tree_walker: # print "%s not handled in raw_expression_tree_walker" % (tag,)
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-07-25 18:35  Robert Haas <robertmhaas@gmail.com>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Robert Haas @ 2017-07-25 18:35 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers

On Thu, Jul 13, 2017 at 9:46 PM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> I wrote a script to cross-check various node handling functions and it told me:
>
> T_NextValueExpr not handled in outfuncs.c
> T_ObjectWithArgs not handled in outfuncs.c
> T_AccessPriv not handled in outfuncs.c
> T_CreateOpClassItem not handled in outfuncs.c
> T_FunctionParameter not handled in outfuncs.c
> T_InferClause not handled in outfuncs.c
> T_OnConflictClause not handled in outfuncs.c
> T_RoleSpec not handled in outfuncs.c
> T_PartitionCmd not handled in outfuncs.c
> T_NamedTuplestoreScan can be produced by outfuncs.c with tagname
> NAMEDTUPLESTORESCAN but that tagname is not recognized by readfuncs.c
> T_Alias not handled in ruleutils.c
> T_RangeVar not handled in ruleutils.c
> T_Expr not handled in ruleutils.c
> T_CaseWhen not handled in ruleutils.c
> T_TargetEntry not handled in ruleutils.c
> T_RangeTblRef not handled in ruleutils.c
> T_JoinExpr not handled in ruleutils.c
> T_FromExpr not handled in ruleutils.c
> T_OnConflictExpr not handled in ruleutils.c
> T_IntoClause not handled in ruleutils.c
> T_NextValueExpr not handled in ruleutils.c

That's pretty cool.  Per long-standing precedent, anything we use in a
build needs to be in Perl, not Python, but I think it would be great
to fix all of these (or the script) and then add this to our standard
build process.  It would be *great* to stop making mistakes like this.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-07-26 04:04  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Thomas Munro @ 2017-07-26 04:04 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers

On Wed, Jul 26, 2017 at 6:35 AM, Robert Haas <robertmhaas@gmail.com> wrote:
> That's pretty cool.  Per long-standing precedent, anything we use in a
> build needs to be in Perl, not Python, but I think it would be great
> to fix all of these (or the script) and then add this to our standard
> build process.  It would be *great* to stop making mistakes like this.

Ok, here is a Perl version.  It is literally my first Perl program so
I probably got all those squiggles wrong.  Ouput as of today:

$ ./src/tools/check_node_support_code.pl
T_ObjectWithArgs (category PARSE TREE NODES) not handled in outfuncs.c
T_AccessPriv (category PARSE TREE NODES) not handled in outfuncs.c
T_CreateOpClassItem (category PARSE TREE NODES) not handled in outfuncs.c
T_FunctionParameter (category PARSE TREE NODES) not handled in outfuncs.c
T_InferClause (category PARSE TREE NODES) not handled in outfuncs.c
T_OnConflictClause (category PARSE TREE NODES) not handled in outfuncs.c
T_RoleSpec (category PARSE TREE NODES) not handled in outfuncs.c
T_PartitionCmd (category PARSE TREE NODES) not handled in outfuncs.c
T_NamedTuplestoreScan is written by outfuncs.c as NAMEDTUPLESTORESCAN
but that name is not recognized by readfuncs.c
T_Alias (category PRIMITIVE NODES) not handled in equalfuncs.c
T_RangeVar (category PRIMITIVE NODES) not handled in equalfuncs.c
T_Expr (category PRIMITIVE NODES) not handled in equalfuncs.c
T_CaseWhen (category PRIMITIVE NODES) not handled in equalfuncs.c
T_TargetEntry (category PRIMITIVE NODES) not handled in equalfuncs.c
T_RangeTblRef (category PRIMITIVE NODES) not handled in equalfuncs.c
T_JoinExpr (category PRIMITIVE NODES) not handled in equalfuncs.c
T_FromExpr (category PRIMITIVE NODES) not handled in equalfuncs.c
T_OnConflictExpr (category PRIMITIVE NODES) not handled in equalfuncs.c
T_IntoClause (category PRIMITIVE NODES) not handled in equalfuncs.c

-- 
Thomas Munro
http://www.enterprisedb.com

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

check-node-support-code-v1.patch (application/octet-stream, 6.1K) download diff --git a/src/tools/check_node_support_code.pl b/src/tools/check_node_support_code.pl new file mode 100755 index 00000000000..0b15ad9b042 --- /dev/null +++ b/src/tools/check_node_support_code.pl @@ -0,0 +1,182 @@ +#!/usr/bin/env perl + +################################################################# +# +# Perform some simple checks on on the handling of node types. +# +# Execute with the top of the PostgreSQL source tree as current +# directory. +# +# Copyright (c) 2017, PostgreSQL Global Development Group +# +################################################################# + +use strict; +use warnings; + +sub scan_node_categories { + my $path = "src/include/nodes/nodes.h"; + my $category = "INVALID"; + my %results = (); + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /TAGS FOR ([A-Z].*(NODES|STUFF))/) { + $category = $1; + $results{ $category } = []; + } elsif ($line =~ /\W(T_[a-zA-Z0-9_]+)/) { + push @{ $results{ $category } }, $1; + } + } + return %results; +} + +sub scan_switch { + my ($path, $function) = @_; + my @results = []; + my $in_function = 0; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /^$function\(/) { + $in_function = 1; + } elsif ($line =~ /^}/) { + $in_function = 0; + } elsif ($in_function && $line =~ /case (T_.+):/) { + push @results, $1; + } + } + return @results; +} + +sub scan_read_tagnames { + my $path = "src/backend/nodes/readfuncs.c"; + my @results = []; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /MATCH\(\"([A-Z]+)\", ([0-9]+)/) { + push @results, $1; + if (length($1) != $2) { + print "Unexpected length in readfuncs.c: $line"; + } + } + } + return @results; +} + +sub scan_out_tagnames { + my $path = "src/backend/nodes/outfuncs.c"; + my %results = (); + my $current_tag = ""; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /_out.*, const ([^ ]+) \*/) { + # see makeNode macro definition: typedef Foo must have enum T_Foo + $current_tag = "T_" . $1; + } elsif ($line =~ /^}/) { + $current_tag = ""; + } elsif ($current_tag ne "" && + $line =~ /WRITE_NODE_TYPE\(\"([A-Z]+)\"\)/) { + $results{$current_tag} = $1; + } + } + return %results; +} + +# how are you supposed to write the equivalent of python x is in <list>? +sub is_in { + my ($needle, @haystack) = @_; + foreach my $value (@haystack) { + if ($needle eq $value) { + return 1; + } + } + return 0; +} + +my %node_categories = scan_node_categories(); + +################################################################# +# +# Check node categories that must be supported by copy, out. We'll +# exclude some special cases that don't fit the usual pattern, trusting +# that they just work. +# +################################################################# + +my @copyfuncs = scan_switch("src/backend/nodes/copyfuncs.c", "copyObjectImpl"); +my @outfuncs = scan_switch("src/backend/nodes/outfuncs.c", "outNode"); +my @special_cases = ( "T_List", "T_IntList", "T_OidList", "T_Integer", + "T_Float", "T_String", "T_BitString", "T_Expr", + "T_Null", "T_Value" ); + +foreach my $category ("PLAN NODES", "PRIMITIVE NODES", "VALUE NODES", "LIST NODES", "PARSE TREE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (!is_in($node, @special_cases)) { + if (!is_in($node, @copyfuncs)) { + print "$node (category $category) not handled in copyfuncs.c\n"; + } + if (!is_in($node, @outfuncs)) { + print "$node (category $category) not handled in outfuncs.c\n"; + } + } + } +} + +################################################################# +# +# Check node categories that must be supported by equals. +# +################################################################# + +my @equalfuncs = scan_switch("src/backend/nodes/equalfuncs.c", "equal"); + +foreach my $category ("PRIMITIVE NODES", "VALUE NODES", "LIST NODES", "PARSE TREE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (!is_in($node, @special_cases)) { + if (!is_in($node, @equalfuncs)) { + print "$node (category $category) not handled in equalfuncs.c\n"; + } + } + } +} + +################################################################# +# +# Check node categories that must be supported by parseNodeString +# using the tagname that is output by outfuncs.c +# +################################################################# + +my @readfuncs_tagnames = scan_read_tagnames(); +my %outfuncs_tagnames = scan_out_tagnames(); + +foreach my $category ("PLAN NODES", "PRIMITIVE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (exists($outfuncs_tagnames{ $node }) && + !is_in($outfuncs_tagnames{ $node }, @readfuncs_tagnames)) { + print "$node is written by outfuncs.c as $outfuncs_tagnames{ $node } but that name is not recognized by readfuncs.c\n"; + } + } +} + +################################################################# +# +# Check node categories that must be supported by ruleutils.c. +# +################################################################# + +my @get_rule_expr = scan_switch("src/backend/utils/adt/ruleutils.c", "get_rule_expr"); + +foreach my $category ("PRIMITIVE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if(!is_in($node, @get_rule_expr)) { + print "$node (category $category) not handled in equalfuncs.c\n"; + } + } +} + +# TODO: Figure out what checks to run on these switch statements (and more...) + +my @exprSetCollation = scan_switch("src/backend/nodes/nodeFuncs.c", "exprSetCollation"); +my @expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_walker"); +my @expression_tree_mutator = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator"); +my @raw_expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator");
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-07-26 04:51  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Thomas Munro @ 2017-07-26 04:51 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers

On Wed, Jul 26, 2017 at 4:04 PM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> On Wed, Jul 26, 2017 at 6:35 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> That's pretty cool.  Per long-standing precedent, anything we use in a
>> build needs to be in Perl, not Python, but I think it would be great
>> to fix all of these (or the script) and then add this to our standard
>> build process.  It would be *great* to stop making mistakes like this.
>
> Ok, here is a Perl version.  It is literally my first Perl program so
> I probably got all those squiggles wrong.  Ouput as of today:

Argh, let me try that again with a copy-and-paste error corrected:

$ ./src/tools/check_node_support_code.pl
T_ObjectWithArgs (category PARSE TREE NODES) not handled in outfuncs.c
T_AccessPriv (category PARSE TREE NODES) not handled in outfuncs.c
T_CreateOpClassItem (category PARSE TREE NODES) not handled in outfuncs.c
T_FunctionParameter (category PARSE TREE NODES) not handled in outfuncs.c
T_InferClause (category PARSE TREE NODES) not handled in outfuncs.c
T_OnConflictClause (category PARSE TREE NODES) not handled in outfuncs.c
T_RoleSpec (category PARSE TREE NODES) not handled in outfuncs.c
T_PartitionCmd (category PARSE TREE NODES) not handled in outfuncs.c
T_NamedTuplestoreScan is written by outfuncs.c as NAMEDTUPLESTORESCAN
but that name is not recognized by readfuncs.c
T_Alias (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_RangeVar (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_Expr (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_CaseWhen (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_TargetEntry (category PRIMITIVE NODES) not handled in
ruleutils.c:get_rule_expr
T_RangeTblRef (category PRIMITIVE NODES) not handled in
ruleutils.c:get_rule_expr
T_JoinExpr (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_FromExpr (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr
T_OnConflictExpr (category PRIMITIVE NODES) not handled in
ruleutils.c:get_rule_expr
T_IntoClause (category PRIMITIVE NODES) not handled in ruleutils.c:get_rule_expr

-- 
Thomas Munro
http://www.enterprisedb.com

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

check-node-support-code-v2.patch (application/octet-stream, 6.1K) download diff --git a/src/tools/check_node_support_code.pl b/src/tools/check_node_support_code.pl new file mode 100755 index 00000000000..61193154c74 --- /dev/null +++ b/src/tools/check_node_support_code.pl @@ -0,0 +1,182 @@ +#!/usr/bin/env perl + +################################################################# +# +# Perform some simple checks on on the handling of node types. +# +# Execute with the top of the PostgreSQL source tree as current +# directory. +# +# Copyright (c) 2017, PostgreSQL Global Development Group +# +################################################################# + +use strict; +use warnings; + +sub scan_node_categories { + my $path = "src/include/nodes/nodes.h"; + my $category = "INVALID"; + my %results = (); + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /TAGS FOR ([A-Z].*(NODES|STUFF))/) { + $category = $1; + $results{ $category } = []; + } elsif ($line =~ /\W(T_[a-zA-Z0-9_]+)/) { + push @{ $results{ $category } }, $1; + } + } + return %results; +} + +sub scan_switch { + my ($path, $function) = @_; + my @results = []; + my $in_function = 0; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /^$function\(/) { + $in_function = 1; + } elsif ($line =~ /^}/) { + $in_function = 0; + } elsif ($in_function && $line =~ /case (T_.+):/) { + push @results, $1; + } + } + return @results; +} + +sub scan_read_tagnames { + my $path = "src/backend/nodes/readfuncs.c"; + my @results = []; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /MATCH\(\"([A-Z]+)\", ([0-9]+)/) { + push @results, $1; + if (length($1) != $2) { + print "Unexpected length in readfuncs.c: $line"; + } + } + } + return @results; +} + +sub scan_out_tagnames { + my $path = "src/backend/nodes/outfuncs.c"; + my %results = (); + my $current_tag = ""; + open my $file, $path or die "Could not open $path: $!"; + while (my $line = <$file>) { + if ($line =~ /_out.*, const ([^ ]+) \*/) { + # see makeNode macro definition: typedef Foo must have enum T_Foo + $current_tag = "T_" . $1; + } elsif ($line =~ /^}/) { + $current_tag = ""; + } elsif ($current_tag ne "" && + $line =~ /WRITE_NODE_TYPE\(\"([A-Z]+)\"\)/) { + $results{$current_tag} = $1; + } + } + return %results; +} + +# how are you supposed to write the equivalent of python x is in <list>? +sub is_in { + my ($needle, @haystack) = @_; + foreach my $value (@haystack) { + if ($needle eq $value) { + return 1; + } + } + return 0; +} + +my %node_categories = scan_node_categories(); + +################################################################# +# +# Check node categories that must be supported by copy, out. We'll +# exclude some special cases that don't fit the usual pattern, trusting +# that they just work. +# +################################################################# + +my @copyfuncs = scan_switch("src/backend/nodes/copyfuncs.c", "copyObjectImpl"); +my @outfuncs = scan_switch("src/backend/nodes/outfuncs.c", "outNode"); +my @special_cases = ( "T_List", "T_IntList", "T_OidList", "T_Integer", + "T_Float", "T_String", "T_BitString", "T_Expr", + "T_Null", "T_Value" ); + +foreach my $category ("PLAN NODES", "PRIMITIVE NODES", "VALUE NODES", "LIST NODES", "PARSE TREE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (!is_in($node, @special_cases)) { + if (!is_in($node, @copyfuncs)) { + print "$node (category $category) not handled in copyfuncs.c\n"; + } + if (!is_in($node, @outfuncs)) { + print "$node (category $category) not handled in outfuncs.c\n"; + } + } + } +} + +################################################################# +# +# Check node categories that must be supported by equals. +# +################################################################# + +my @equalfuncs = scan_switch("src/backend/nodes/equalfuncs.c", "equal"); + +foreach my $category ("PRIMITIVE NODES", "VALUE NODES", "LIST NODES", "PARSE TREE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (!is_in($node, @special_cases)) { + if (!is_in($node, @equalfuncs)) { + print "$node (category $category) not handled in equalfuncs.c\n"; + } + } + } +} + +################################################################# +# +# Check node categories that must be supported by parseNodeString +# using the tagname that is output by outfuncs.c +# +################################################################# + +my @readfuncs_tagnames = scan_read_tagnames(); +my %outfuncs_tagnames = scan_out_tagnames(); + +foreach my $category ("PLAN NODES", "PRIMITIVE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if (exists($outfuncs_tagnames{ $node }) && + !is_in($outfuncs_tagnames{ $node }, @readfuncs_tagnames)) { + print "$node is written by outfuncs.c as $outfuncs_tagnames{ $node } but that name is not recognized by readfuncs.c\n"; + } + } +} + +################################################################# +# +# Check node categories that must be supported by ruleutils.c. +# +################################################################# + +my @get_rule_expr = scan_switch("src/backend/utils/adt/ruleutils.c", "get_rule_expr"); + +foreach my $category ("PRIMITIVE NODES") { + foreach my $node (@{ $node_categories{ $category} }) { + if(!is_in($node, @get_rule_expr)) { + print "$node (category $category) not handled in ruleutils.c:get_rule_expr\n"; + } + } +} + +# TODO: Figure out what checks to run on these switch statements (and more...) + +my @exprSetCollation = scan_switch("src/backend/nodes/nodeFuncs.c", "exprSetCollation"); +my @expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_walker"); +my @expression_tree_mutator = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator"); +my @raw_expression_tree_walker = scan_switch("src/backend/nodes/nodeFuncs.c", "expression_tree_mutator");
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-08-17 22:47  Thomas Munro <thomas.munro@enterprisedb.com>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Thomas Munro @ 2017-08-17 22:47 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers; Kevin Grittner <kgrittn@gmail.com>; Andrew Gierth <andrew@tao11.riddles.org.uk>

On Fri, Jul 14, 2017 at 1:46 PM, Thomas Munro
<thomas.munro@enterprisedb.com> wrote:
> [...]
> T_NamedTuplestoreScan can be produced by outfuncs.c with tagname
> NAMEDTUPLESTORESCAN but that tagname is not recognized by readfuncs.c
> [...]
>
> That revealed a defect in commit
> 18ce3a4ab22d2984f8540ab480979c851dae5338 which I think should be
> corrected with something like the attached, though I'm not sure if
> it's possible to reach it.

Adding Kevin and Andrew G.  Thoughts on whether this is a defect that
should be corrected with something like
read-namedtuplestorescan.patch?

-- 
Thomas Munro
http://www.enterprisedb.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Inadequate infrastructure for NextValueExpr
@ 2017-08-18 00:43  Andrew Gierth <andrew@tao11.riddles.org.uk>
  parent: Thomas Munro <thomas.munro@enterprisedb.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Andrew Gierth @ 2017-08-18 00:43 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers; Kevin Grittner <kgrittn@gmail.com>

>>>>> "Thomas" == Thomas Munro <thomas.munro@enterprisedb.com> writes:

 >> [...]
 >> T_NamedTuplestoreScan can be produced by outfuncs.c with tagname
 >> NAMEDTUPLESTORESCAN but that tagname is not recognized by readfuncs.c
 >> [...]
 >> 
 >> That revealed a defect in commit
 >> 18ce3a4ab22d2984f8540ab480979c851dae5338 which I think should be
 >> corrected with something like the attached, though I'm not sure if
 >> it's possible to reach it.

 Thomas> Adding Kevin and Andrew G.  Thoughts on whether this is a
 Thomas> defect that should be corrected with something like
 Thomas> read-namedtuplestorescan.patch?

It's a defect that should probably be corrected for consistency, though
at present it looks like it's not actually possible to reach the code.
The patch looks good to me though I've not tested it.

Kevin, you want to take it? Or shall I deal with it?

-- 
Andrew (irc:RhodiumToad)


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2017-08-18 00:43 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-07-13 21:34 Inadequate infrastructure for NextValueExpr Tom Lane <tgl@sss.pgh.pa.us>
2017-07-14 01:46 ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-07-25 18:35   ` Robert Haas <robertmhaas@gmail.com>
2017-07-26 04:04     ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-07-26 04:51       ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-08-17 22:47   ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-08-18 00:43     ` Andrew Gierth <andrew@tao11.riddles.org.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox