User talk:Selenamarie

From PostgreSQL wiki
Jump to navigationJump to search

Looking at patch: https://commitfest.postgresql.org/action/patch_view?id=173

  • src/include/commands/copy.h:
    • typedef struct CopyStateData was moved here from copy.c

changes:

2036 +   bool        partitioning;   /* tuple routing in table hierarchy */
2037 +   bool        errlog;         /* log bad tuples? */
2038 +   bool        errlog_skip_bad_rows;   /* skip bad rows instead of logging? */                
2039 +   int         errlog_nb_errors;       /* number of bad tuples so far */                      
2040 +   int         errlog_max_errors;      /* maximum number of errors */
2041 +   char       *errlog_schema_name;     /* schema name in which to log */                      
2042 +   char       *errlog_table_name;      /* table name in which to log bad tuples */            
2043 +   char       *errlog_label;           /* error label for that COPY operation */              
2044 +   char       *errlog_key;             /* error key for that COPY operation */                
2045 +   bool       readlineOk;      /* true if we read a full line of data */          
  • src/include/commands/copy.c:
  • typedef struct CopyStateData -- moved to copy.h.

new includes added to copy.c:

+ #include "utils/errorlogging.h"
+ #include "utils/tqual.h"
+ #include "utils/fmgroids.h"
+ #include "optimizer/plancat.h"
+ 
+ /* For tuple routing */
+ #include "utils/relcache.h"
+ #include "catalog/pg_inherits.h"
+ #include "catalog/pg_inherits_fn.h"
+ #include "nodes/makefuncs.h"
+ #include "nodes/pg_list.h"
  • Error logging function:
+ /* <--- Error logging function ---> */
+ 
+ /* Non-export error logging function prototypes */
+ 
+ /**
+  * Helper method that will perform all the error logging decision logic and
+  * then possibly call \see MalformedTupleIs to insert a malformed tuple, or
+  * just skip it. This method should only be called from within a \see PG_CATCH()
+  * macro, as it makes assumptions about using the error subsystem from
+  * PostgreSQL.
+  *
+  * @param mycid Command id of the current copy command.
+  * @param cstate \see CopyState of the current copy command.
+  * @param errorData \see ErrorData struct for the malformed tuple.
+  * @param copyMemoryContext \see MemoryContext before the \see PG_TRY()
+  *    macro of the error logging logic.
+  */
+ static void PerformErrorLoggingForCopy(CommandId mycid, CopyState cstate,
+    ErrorData * errorData, MemoryContext copyMemoryContext);
+ 
+ /**
+  * Size of the LRU list of relations to keep in cache for routing
+  */
+ int partitioningCacheSize;
+ 
+ typedef struct OidCell OidCell;
+ 
+ typedef struct OidLinkedList
+ {
+       int             length;
+       OidCell *head;
+ } OidLinkedList;
+ 
+ struct OidCell
+ {
+       Oid             oid_value;
+       OidCell *next;
+ };
+ 
+ OidLinkedList *child_table_lru = NULL;
  • PerformErrorLoggingForCopy
    • Better formatting needed for comment starting on line 1990:
+               /* check the \see errorData->sqlerrcode to only log tuples
+                * that are indeed malformed
+                * this ensures that we let other errors pass through */
    • cur_lineno_str[11] --> ?, why not just use an int/bigint? (maybe MalformedTupleIs expects a string?)
    • whitespace is goofy at line: 2004-2009 in copy.c
    • line: 2668 -> need to fix that comment :) (/* Regular code */) -- ym: no partitioning for that table, eh?
    • line 2660 -> what if we are in ErrorLoggingForCopy ?
    • line 2881:
+       /* mark that we do not have read a line yet, this is necessary so
+        * that we can perform error logging on complete lines only */

maybe: "Mark that we have not read a line yet. This is necessary so that we can perform error logging on complete lines only."

  • src/backend/utils/adt/ruleutils.c:
    • definition removed -- static char *generate_relation_name(Oid relid, List *namespaces); (no longer static char?) *** ANSWER: was moved to builtins.h
  • doc/src/sgml/ref/copy.sgml:
    • line 313: failif needs a space
    • The error table log examples have relations shown in a different order than the CREATE TABLE declaration.
  • src/test/regress/sql/copyselect.sql:
    • Is this change documented elsewhere?


  • NEW FILE: src/backend/utils/misc/errorlogging.c
    • Needs a header (see copy.c for example)
    • could move currentCommand pg_stat call into MalformedTupleIs
  • NEW FILE: src/include/utils/errorlogging.h
    • Needs header
  • InitializeErrorLogging