Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2006-08-29 15:19:51 +0000
committerTom Lane2006-08-29 15:19:51 +0000
commit0434c46db059a80b0e89397a137dfa10421573f4 (patch)
tree43f7d6fd2e7a47c1d243ff1cb55f8df06a75b1ba /src/bin/psql/variables.h
parentb681bfdd59918e3b65bd0b499075f99b39e511b5 (diff)
Invent an assign-hook mechanism for psql variables similar to the one
existing for backend GUC variables, and use this to eliminate repeated fetching/parsing of psql variables in psql's inner loops. In a trivial test with lots of 'select 1;' commands, psql's CPU time went down almost 10%, although of course the effect on total elapsed time was much less. Per discussion about how to ensure the upcoming FETCH_COUNT patch doesn't cost any performance when not being used.
Diffstat (limited to 'src/bin/psql/variables.h')
-rw-r--r--src/bin/psql/variables.h53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/bin/psql/variables.h b/src/bin/psql/variables.h
index 37abadb66ca..e4dce97a0a7 100644
--- a/src/bin/psql/variables.h
+++ b/src/bin/psql/variables.h
@@ -3,62 +3,57 @@
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/variables.h,v 1.18 2006/03/05 15:58:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/variables.h,v 1.19 2006/08/29 15:19:51 tgl Exp $
*/
+#ifndef VARIABLES_H
+#define VARIABLES_H
/*
* This implements a sort of variable repository. One could also think of it
- * as cheap version of an associative array. In each one of these
- * datastructures you can store name/value pairs.
+ * as a cheap version of an associative array. In each one of these
+ * datastructures you can store name/value pairs. There can also be an
+ * "assign hook" function that is called whenever the variable's value is
+ * changed.
+ *
+ * An "unset" operation causes the hook to be called with newval == NULL.
+ *
+ * Note: if value == NULL then the variable is logically unset, but we are
+ * keeping the struct around so as not to forget about its hook function.
*/
-
-#ifndef VARIABLES_H
-#define VARIABLES_H
-
-#define VALID_VARIABLE_CHARS "abcdefghijklmnopqrstuvwxyz"\
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789_"
+typedef void (*VariableAssignHook) (const char *newval);
struct _variable
{
char *name;
char *value;
+ VariableAssignHook assign_hook;
struct _variable *next;
};
typedef struct _variable *VariableSpace;
+/* Allowed chars in a variable's name */
+#define VALID_VARIABLE_CHARS "abcdefghijklmnopqrstuvwxyz"\
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789_"
VariableSpace CreateVariableSpace(void);
const char *GetVariable(VariableSpace space, const char *name);
-bool GetVariableBool(VariableSpace space, const char *name);
-bool VariableEquals(VariableSpace space, const char name[], const char *opt);
-/* Read numeric variable, or defaultval if it is not set, or faultval if its
- * value is not a valid numeric string. If allowtrail is false, this will
- * include the case where there are trailing characters after the number.
- */
+bool ParseVariableBool(const char *val);
+int ParseVariableNum(const char *val,
+ int defaultval,
+ int faultval,
+ bool allowtrail);
int GetVariableNum(VariableSpace space,
- const char name[],
+ const char *name,
int defaultval,
int faultval,
bool allowtrail);
-
-/* Find value of variable <name> among NULL-terminated list of alternative
- * options. Returns VAR_NOTSET if the variable was not set, VAR_NOTFOUND
- * if its value did not occur in the list of options, or the number of the
- * matching option. The first option is 1, the second is 2 and so on.
- */
-enum
-{
-VAR_NOTSET = 0, VAR_NOTFOUND = -1};
-int
-SwitchVariable(VariableSpace space, const char name[],
- const char *opt,...);
-
void PrintVariables(VariableSpace space);
bool SetVariable(VariableSpace space, const char *name, const char *value);
+bool SetVariableAssignHook(VariableSpace space, const char *name, VariableAssignHook hook);
bool SetVariableBool(VariableSpace space, const char *name);
bool DeleteVariable(VariableSpace space, const char *name);