firtst release
修订版 | d6c600fc9635b4fb170bd48ba8fe559869099c75 (tree) |
---|---|
时间 | 2018-11-13 16:24:07 |
作者 | Kyotaro Horiguchi <horiguchi.kyotaro@lab....> |
Commiter | Kyotaro Horiguchi |
Fix debug output level control
Previously parse_messages and message_level were binded to the same
internal variable. Separate the two GUCs. On the way doing this some
mssages that did not honor the variable were fixed. Default behavior
is not changed but the the two variables works differently from the
previous version, perhaps closer to expected.
@@ -8417,3 +8417,48 @@ error hint: | ||
8417 | 8417 | (9 rows) |
8418 | 8418 | |
8419 | 8419 | \! rm results/pg_hint_plan.tmpout |
8420 | +-- hint error level | |
8421 | +set client_min_messages to 'DEBUG1'; | |
8422 | +set pg_hint_plan.debug_level to 'verbose'; | |
8423 | +/*+ SeqScan( */ SELECT 1; | |
8424 | +INFO: pg_hint_plan: hint syntax error at or near "" | |
8425 | +DETAIL: Closing parenthesis is necessary. | |
8426 | + ?column? | |
8427 | +---------- | |
8428 | + 1 | |
8429 | +(1 row) | |
8430 | + | |
8431 | +/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0; | |
8432 | +LOG: pg_hint_plan: | |
8433 | +used hint: | |
8434 | +SeqScan(t1) | |
8435 | +not used hint: | |
8436 | +duplication hint: | |
8437 | +error hint: | |
8438 | + | |
8439 | + id | val | |
8440 | +----+----- | |
8441 | +(0 rows) | |
8442 | + | |
8443 | +set pg_hint_plan.message_level to 'DEBUG1'; | |
8444 | +set pg_hint_plan.parse_messages to 'NOTICE'; | |
8445 | +/*+ SeqScan( */ SELECT 1; | |
8446 | +NOTICE: pg_hint_plan: hint syntax error at or near "" | |
8447 | +DETAIL: Closing parenthesis is necessary. | |
8448 | + ?column? | |
8449 | +---------- | |
8450 | + 1 | |
8451 | +(1 row) | |
8452 | + | |
8453 | +/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0; | |
8454 | +DEBUG: pg_hint_plan: | |
8455 | +used hint: | |
8456 | +SeqScan(t1) | |
8457 | +not used hint: | |
8458 | +duplication hint: | |
8459 | +error hint: | |
8460 | + | |
8461 | + id | val | |
8462 | +----+----- | |
8463 | +(0 rows) | |
8464 | + |
@@ -89,12 +89,12 @@ PG_MODULE_MAGIC; | ||
89 | 89 | |
90 | 90 | #define HINT_ARRAY_DEFAULT_INITSIZE 8 |
91 | 91 | |
92 | -#define hint_ereport(str, detail) \ | |
92 | +#define hint_ereport(str, detail) hint_parse_ereport(str, detail) | |
93 | +#define hint_parse_ereport(str, detail) \ | |
93 | 94 | do { \ |
94 | - ereport(pg_hint_plan_message_level, \ | |
95 | - (errmsg("pg_hint_plan%s: hint syntax error at or near \"%s\"", qnostr, (str)), \ | |
95 | + ereport(pg_hint_plan_parse_message_level, \ | |
96 | + (errmsg("pg_hint_plan: hint syntax error at or near \"%s\"", (str)), \ | |
96 | 97 | errdetail detail)); \ |
97 | - msgqno = qno; \ | |
98 | 98 | } while(0) |
99 | 99 | |
100 | 100 | #define skip_space(str) \ |
@@ -494,7 +494,8 @@ static int set_config_int32_option(const char *name, int32 value, | ||
494 | 494 | /* GUC variables */ |
495 | 495 | static bool pg_hint_plan_enable_hint = true; |
496 | 496 | static int debug_level = 0; |
497 | -static int pg_hint_plan_message_level = INFO; | |
497 | +static int pg_hint_plan_parse_message_level = INFO; | |
498 | +static int pg_hint_plan_debug_message_level = LOG; | |
498 | 499 | /* Default is off, to keep backward compatibility. */ |
499 | 500 | static bool pg_hint_plan_enable_hint_table = false; |
500 | 501 |
@@ -637,7 +638,7 @@ _PG_init(void) | ||
637 | 638 | DefineCustomEnumVariable("pg_hint_plan.parse_messages", |
638 | 639 | "Message level of parse errors.", |
639 | 640 | NULL, |
640 | - &pg_hint_plan_message_level, | |
641 | + &pg_hint_plan_parse_message_level, | |
641 | 642 | INFO, |
642 | 643 | parse_messages_level_options, |
643 | 644 | PGC_USERSET, |
@@ -649,8 +650,8 @@ _PG_init(void) | ||
649 | 650 | DefineCustomEnumVariable("pg_hint_plan.message_level", |
650 | 651 | "Message level of debug messages.", |
651 | 652 | NULL, |
652 | - &pg_hint_plan_message_level, | |
653 | - INFO, | |
653 | + &pg_hint_plan_debug_message_level, | |
654 | + LOG, | |
654 | 655 | parse_messages_level_options, |
655 | 656 | PGC_USERSET, |
656 | 657 | 0, |
@@ -1227,7 +1228,7 @@ HintStateDump(HintState *hstate) | ||
1227 | 1228 | |
1228 | 1229 | if (!hstate) |
1229 | 1230 | { |
1230 | - elog(LOG, "pg_hint_plan:\nno hint"); | |
1231 | + elog(pg_hint_plan_debug_message_level, "pg_hint_plan:\nno hint"); | |
1231 | 1232 | return; |
1232 | 1233 | } |
1233 | 1234 |
@@ -1239,7 +1240,8 @@ HintStateDump(HintState *hstate) | ||
1239 | 1240 | desc_hint_in_state(hstate, &buf, "duplication hint", HINT_STATE_DUPLICATION, false); |
1240 | 1241 | desc_hint_in_state(hstate, &buf, "error hint", HINT_STATE_ERROR, false); |
1241 | 1242 | |
1242 | - elog(LOG, "%s", buf.data); | |
1243 | + ereport(pg_hint_plan_debug_message_level, | |
1244 | + (errmsg ("%s", buf.data))); | |
1243 | 1245 | |
1244 | 1246 | pfree(buf.data); |
1245 | 1247 | } |
@@ -1251,7 +1253,7 @@ HintStateDump2(HintState *hstate) | ||
1251 | 1253 | |
1252 | 1254 | if (!hstate) |
1253 | 1255 | { |
1254 | - elog(pg_hint_plan_message_level, | |
1256 | + elog(pg_hint_plan_debug_message_level, | |
1255 | 1257 | "pg_hint_plan%s: HintStateDump: no hint", qnostr); |
1256 | 1258 | return; |
1257 | 1259 | } |
@@ -1264,7 +1266,7 @@ HintStateDump2(HintState *hstate) | ||
1264 | 1266 | desc_hint_in_state(hstate, &buf, "}, {error hints", HINT_STATE_ERROR, true); |
1265 | 1267 | appendStringInfoChar(&buf, '}'); |
1266 | 1268 | |
1267 | - ereport(pg_hint_plan_message_level, | |
1269 | + ereport(pg_hint_plan_debug_message_level, | |
1268 | 1270 | (errmsg("%s", buf.data), |
1269 | 1271 | errhidestmt(true), |
1270 | 1272 | errhidecontext(true))); |
@@ -2594,7 +2596,7 @@ set_config_int32_option(const char *name, int32 value, GucContext context) | ||
2594 | 2596 | |
2595 | 2597 | if (snprintf(buf, 16, "%d", value) < 0) |
2596 | 2598 | { |
2597 | - ereport(pg_hint_plan_message_level, | |
2599 | + ereport(pg_hint_plan_parse_message_level, | |
2598 | 2600 | (errmsg ("Failed to convert integer to string: %d", value))); |
2599 | 2601 | return false; |
2600 | 2602 | } |
@@ -2602,7 +2604,7 @@ set_config_int32_option(const char *name, int32 value, GucContext context) | ||
2602 | 2604 | return |
2603 | 2605 | set_config_option_noerror(name, buf, context, |
2604 | 2606 | PGC_S_SESSION, GUC_ACTION_SAVE, true, |
2605 | - pg_hint_plan_message_level); | |
2607 | + pg_hint_plan_parse_message_level); | |
2606 | 2608 | } |
2607 | 2609 | |
2608 | 2610 | /* setup scan method enforcement according to given options */ |
@@ -2621,7 +2623,7 @@ setup_guc_enforcement(SetHint **options, int noptions, GucContext context) | ||
2621 | 2623 | |
2622 | 2624 | result = set_config_option_noerror(hint->name, hint->value, context, |
2623 | 2625 | PGC_S_SESSION, GUC_ACTION_SAVE, true, |
2624 | - pg_hint_plan_message_level); | |
2626 | + pg_hint_plan_parse_message_level); | |
2625 | 2627 | if (result != 0) |
2626 | 2628 | hint->base.state = HINT_STATE_USED; |
2627 | 2629 | else |
@@ -2856,7 +2858,7 @@ pg_hint_plan_post_parse_analyze(ParseState *pstate, Query *query) | ||
2856 | 2858 | if (debug_level > 1) |
2857 | 2859 | { |
2858 | 2860 | if (current_hint_str) |
2859 | - ereport(pg_hint_plan_message_level, | |
2861 | + ereport(pg_hint_plan_debug_message_level, | |
2860 | 2862 | (errmsg("pg_hint_plan[qno=0x%x]: " |
2861 | 2863 | "post_parse_analyze_hook: " |
2862 | 2864 | "hints from table: \"%s\": " |
@@ -2867,7 +2869,7 @@ pg_hint_plan_post_parse_analyze(ParseState *pstate, Query *query) | ||
2867 | 2869 | errhidestmt(msgqno != qno), |
2868 | 2870 | errhidecontext(msgqno != qno))); |
2869 | 2871 | else |
2870 | - ereport(pg_hint_plan_message_level, | |
2872 | + ereport(pg_hint_plan_debug_message_level, | |
2871 | 2873 | (errmsg("pg_hint_plan[qno=0x%x]: " |
2872 | 2874 | "no match found in table: " |
2873 | 2875 | "application name = \"%s\", " |
@@ -2907,13 +2909,13 @@ pg_hint_plan_post_parse_analyze(ParseState *pstate, Query *query) | ||
2907 | 2909 | { |
2908 | 2910 | if (debug_level == 1 && |
2909 | 2911 | (stmt_name || strcmp(query_str, debug_query_string))) |
2910 | - ereport(pg_hint_plan_message_level, | |
2912 | + ereport(pg_hint_plan_debug_message_level, | |
2911 | 2913 | (errmsg("hints in comment=\"%s\"", |
2912 | 2914 | current_hint_str ? current_hint_str : "(none)"), |
2913 | 2915 | errhidestmt(msgqno != qno), |
2914 | 2916 | errhidecontext(msgqno != qno))); |
2915 | 2917 | else |
2916 | - ereport(pg_hint_plan_message_level, | |
2918 | + ereport(pg_hint_plan_debug_message_level, | |
2917 | 2919 | (errmsg("hints in comment=\"%s\", stmt=\"%s\", query=\"%s\", debug_query_string=\"%s\"", |
2918 | 2920 | current_hint_str ? current_hint_str : "(none)", |
2919 | 2921 | stmt_name, query_str, debug_query_string), |
@@ -2941,7 +2943,7 @@ pg_hint_plan_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) | ||
2941 | 2943 | if (!pg_hint_plan_enable_hint || hint_inhibit_level > 0) |
2942 | 2944 | { |
2943 | 2945 | if (debug_level > 1) |
2944 | - ereport(pg_hint_plan_message_level, | |
2946 | + ereport(pg_hint_plan_debug_message_level, | |
2945 | 2947 | (errmsg ("pg_hint_plan%s: planner: enable_hint=%d," |
2946 | 2948 | " hint_inhibit_level=%d", |
2947 | 2949 | qnostr, pg_hint_plan_enable_hint, |
@@ -3009,7 +3011,7 @@ pg_hint_plan_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) | ||
3009 | 3011 | |
3010 | 3012 | if (debug_level > 1) |
3011 | 3013 | { |
3012 | - ereport(pg_hint_plan_message_level, | |
3014 | + ereport(pg_hint_plan_debug_message_level, | |
3013 | 3015 | (errhidestmt(msgqno != qno), |
3014 | 3016 | errmsg("pg_hint_plan%s: planner", qnostr))); |
3015 | 3017 | msgqno = qno; |
@@ -3056,7 +3058,7 @@ pg_hint_plan_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) | ||
3056 | 3058 | standard_planner_proc: |
3057 | 3059 | if (debug_level > 1) |
3058 | 3060 | { |
3059 | - ereport(pg_hint_plan_message_level, | |
3061 | + ereport(pg_hint_plan_debug_message_level, | |
3060 | 3062 | (errhidestmt(msgqno != qno), |
3061 | 3063 | errmsg("pg_hint_plan%s: planner: no valid hint", |
3062 | 3064 | qnostr))); |
@@ -3484,7 +3486,7 @@ restrict_indexes(PlannerInfo *root, ScanMethodHint *hint, RelOptInfo *rel, | ||
3484 | 3486 | initStringInfo(&rel_buf); |
3485 | 3487 | quote_value(&rel_buf, disprelname); |
3486 | 3488 | |
3487 | - ereport(LOG, | |
3489 | + ereport(pg_hint_plan_debug_message_level, | |
3488 | 3490 | (errmsg("available indexes for %s(%s):%s", |
3489 | 3491 | hint->base.keyword, |
3490 | 3492 | rel_buf.data, |
@@ -3614,7 +3616,7 @@ setup_hint_enforcement(PlannerInfo *root, RelOptInfo *rel, | ||
3614 | 3616 | if (inhparent) |
3615 | 3617 | { |
3616 | 3618 | if (debug_level > 1) |
3617 | - ereport(pg_hint_plan_message_level, | |
3619 | + ereport(pg_hint_plan_debug_message_level, | |
3618 | 3620 | (errhidestmt(true), |
3619 | 3621 | errmsg ("pg_hint_plan%s: setup_hint_enforcement" |
3620 | 3622 | " skipping inh parent: relation=%u(%s), inhparent=%d," |
@@ -3733,7 +3735,7 @@ setup_hint_enforcement(PlannerInfo *root, RelOptInfo *rel, | ||
3733 | 3735 | if (shint == current_hint_state->parent_scan_hint) |
3734 | 3736 | additional_message = " by parent hint"; |
3735 | 3737 | |
3736 | - ereport(pg_hint_plan_message_level, | |
3738 | + ereport(pg_hint_plan_debug_message_level, | |
3737 | 3739 | (errhidestmt(true), |
3738 | 3740 | errmsg ("pg_hint_plan%s: setup_hint_enforcement" |
3739 | 3741 | " index deletion%s:" |
@@ -3763,7 +3765,7 @@ setup_hint_enforcement(PlannerInfo *root, RelOptInfo *rel, | ||
3763 | 3765 | if (!shint && ! phint) |
3764 | 3766 | { |
3765 | 3767 | if (debug_level > 1) |
3766 | - ereport(pg_hint_plan_message_level, | |
3768 | + ereport(pg_hint_plan_debug_message_level, | |
3767 | 3769 | (errhidestmt (true), |
3768 | 3770 | errmsg ("pg_hint_plan%s: setup_hint_enforcement" |
3769 | 3771 | " no hint applied:" |
@@ -1023,3 +1023,14 @@ EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON (t3.id = t2.id); | ||
1023 | 1023 | \o |
1024 | 1024 | \! sql/maskout.sh results/pg_hint_plan.tmpout |
1025 | 1025 | \! rm results/pg_hint_plan.tmpout |
1026 | + | |
1027 | +-- hint error level | |
1028 | +set client_min_messages to 'DEBUG1'; | |
1029 | +set pg_hint_plan.debug_level to 'verbose'; | |
1030 | +/*+ SeqScan( */ SELECT 1; | |
1031 | +/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0; | |
1032 | +set pg_hint_plan.message_level to 'DEBUG1'; | |
1033 | +set pg_hint_plan.parse_messages to 'NOTICE'; | |
1034 | +/*+ SeqScan( */ SELECT 1; | |
1035 | +/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0; | |
1036 | + |