• R/O
  • HTTP
  • SSH
  • HTTPS

ludia_funcs: Commit

This is the main ludia_funcs git repository.


Commit MetaInfo

Revision46536e8eacd637046ad0dff70396758ccf536712 (tree)
Zeit2020-02-26 18:39:41
AutorFujii Masao <fujii@post...>
CommiterFujii Masao

Log Message

Support terse logging in enable_debug.

This commit allows us to set enable_debug option to 'terse' as
a setting value. When it's 'terse', the contents dealt in ludia_funcs
internal functions are excluded from the debug messages.
For example, if it's set to 'on', not only the name of function
pgs2norm() but also the target string that the function normalizes
are included in the debug messages. But if it's 'terse', only the
terse information like function name is output.

Previously we set enable_debug to 'on', in order to check
whether recheck is skipped or not in the regression test.
But the order of the contents in the debug messages varied
depending on the block size in PostgreSQL server. Which
would lead to unexpected failure of regression test in PostgreSQL
built with non-default block size. In order to stabilize the result
of this regression test, this patch make the test use debug level
'terse'.

Author: Torikoshi Atsushi
Reviewed-by: Fujii Masao
Discussion: https://osdn.net/projects/ludiafuncs/lists/archive/hackers/2020-February/000046.html

Ändern Zusammenfassung

Diff

--- a/expected/pg_bigm.out
+++ b/expected/pg_bigm.out
@@ -1066,30 +1066,39 @@ EXPLAIN (costs off) SELECT replace(col1, E'\t', '*') FROM text_tbl
10661066 Index Cond: (pgs2norm(col1) ~~ '% %'::text)
10671067 (6 rows)
10681068
1069--- Test whether recheck is skipped expectedly when keyword length is 1 or 2
1070-SET ludia_funcs.enable_debug TO on;
1069+-- Test whether recheck is skipped expectedly when keyword length is 1 or 2.
1070+-- We can judge that recheck is skipped successfully if the debug messages
1071+-- indicating the calls to pgs2norm() and pgs2malloc() are logged only once
1072+-- respectively. So this test must run with enable_debug enabled.
1073+-- Note that enable_debug must be set to 'terse' in order to stabilize the
1074+-- result of this regression test. Otherwise, i.e., when enable_debug is set to
1075+-- 'on', the contents dealt in function pgs2malloc() and pgs2norm() are logged,
1076+-- and the order of those debug messages varies depending on the block size
1077+-- in PostgreSQL server. Those detailed information are not necessary to
1078+-- judge whether the recheck is skipped or not.
1079+SET ludia_funcs.enable_debug TO terse;
10711080 SELECT col1 FROM text_tbl
10721081 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('東京都')) ORDER BY col1;
1073-LOG: pgs2malloc(): buflen 2048, needed 22, maxlen 4194304
1074-LOG: pgs2norm(): complete (set result cache): 東京都
1075-LOG: pgs2malloc(): buflen 2048, needed 46, maxlen 4194304
1076-LOG: pgs2norm(): complete (set result cache): 東京都山田太郎
1077-LOG: pgs2malloc(): buflen 2048, needed 22, maxlen 4194304
1078-LOG: pgs2norm(): complete (set result cache): 東京都
1079-LOG: pgs2malloc(): buflen 2048, needed 48, maxlen 4194304
1080-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1081-LOG: pgs2malloc(): buflen 2048, needed 48, maxlen 4194304
1082-LOG: pgs2norm(): complete (set result cache): 東京都山田 太郎
1083-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1084-LOG: pgs2norm(): complete (set result cache): 東京都 山田 太郎
1085-LOG: pgs2malloc(): buflen 2048, needed 47, maxlen 4194304
1086-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1087-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1088-LOG: pgs2norm(): complete (set result cache): 東京都山田 太郎
1089-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1090-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1091-LOG: pgs2malloc(): buflen 2048, needed 34, maxlen 4194304
1092-LOG: pgs2norm(): complete (set result cache): 東京と京都
1082+LOG: pgs2malloc()
1083+LOG: pgs2norm(): complete
1084+LOG: pgs2malloc()
1085+LOG: pgs2norm(): complete
1086+LOG: pgs2malloc()
1087+LOG: pgs2norm(): complete
1088+LOG: pgs2malloc()
1089+LOG: pgs2norm(): complete
1090+LOG: pgs2malloc()
1091+LOG: pgs2norm(): complete
1092+LOG: pgs2malloc()
1093+LOG: pgs2norm(): complete
1094+LOG: pgs2malloc()
1095+LOG: pgs2norm(): complete
1096+LOG: pgs2malloc()
1097+LOG: pgs2norm(): complete
1098+LOG: pgs2malloc()
1099+LOG: pgs2norm(): complete
1100+LOG: pgs2malloc()
1101+LOG: pgs2norm(): complete
10931102 col1
10941103 ------------------
10951104 東京都
@@ -1104,8 +1113,8 @@ LOG: pgs2norm(): complete (set result cache): 東京と京都
11041113
11051114 SELECT col1 FROM text_tbl
11061115 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('京都')) ORDER BY col1;
1107-LOG: pgs2malloc(): buflen 2048, needed 16, maxlen 4194304
1108-LOG: pgs2norm(): complete (set result cache): 京都
1116+LOG: pgs2malloc()
1117+LOG: pgs2norm(): complete
11091118 col1
11101119 ------------------
11111120 東京と京都
@@ -1121,8 +1130,8 @@ LOG: pgs2norm(): complete (set result cache): 京都
11211130
11221131 SELECT col1 FROM text_tbl
11231132 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('京')) ORDER BY col1;
1124-LOG: pgs2malloc(): buflen 2048, needed 10, maxlen 4194304
1125-LOG: pgs2norm(): complete (set result cache): 京
1133+LOG: pgs2malloc()
1134+LOG: pgs2norm(): complete
11261135 col1
11271136 ------------------
11281137 東京と京都
@@ -1138,16 +1147,16 @@ LOG: pgs2norm(): complete (set result cache): 京
11381147
11391148 SELECT pgs2snippet1(1, 50, 1, '*', '*', 0, '東', col1) FROM text_tbl
11401149 WHERE pgs2norm(col2) LIKE likequery(pgs2norm('東')) ORDER BY col1;
1141-LOG: pgs2malloc(): buflen 2048, needed 10, maxlen 4194304
1142-LOG: pgs2norm(): complete (set result cache): 東
1143-LOG: GetSennaQuery(): quick exit: 東
1144-LOG: GetSennaQuery(): quick exit: 東
1145-LOG: GetSennaQuery(): quick exit: 東
1146-LOG: GetSennaQuery(): quick exit: 東
1147-LOG: GetSennaQuery(): quick exit: 東
1148-LOG: GetSennaQuery(): quick exit: 東
1149-LOG: GetSennaQuery(): quick exit: 東
1150-LOG: GetSennaQuery(): quick exit: 東
1150+LOG: pgs2malloc()
1151+LOG: pgs2norm(): complete
1152+LOG: GetSennaQuery(): quick exit
1153+LOG: GetSennaQuery(): quick exit
1154+LOG: GetSennaQuery(): quick exit
1155+LOG: GetSennaQuery(): quick exit
1156+LOG: GetSennaQuery(): quick exit
1157+LOG: GetSennaQuery(): quick exit
1158+LOG: GetSennaQuery(): quick exit
1159+LOG: GetSennaQuery(): quick exit
11511160 pgs2snippet1
11521161 --------------------------
11531162 *東*京と京都
@@ -1164,10 +1173,10 @@ LOG: GetSennaQuery(): quick exit: 東
11641173 SELECT col1 FROM text_tbl
11651174 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('山'))
11661175 AND pgs2norm(col1) LIKE likequery(pgs2norm('京'));
1167-LOG: pgs2malloc(): buflen 2048, needed 10, maxlen 4194304
1168-LOG: pgs2norm(): complete (set result cache): 山
1169-LOG: pgs2malloc(): buflen 2048, needed 10, maxlen 4194304
1170-LOG: pgs2norm(): complete (set result cache): 京
1176+LOG: pgs2malloc()
1177+LOG: pgs2norm(): complete
1178+LOG: pgs2malloc()
1179+LOG: pgs2norm(): complete
11711180 col1
11721181 ------------------
11731182 東京都山田太郎
@@ -1182,10 +1191,10 @@ LOG: pgs2norm(): complete (set result cache): 京
11821191 SELECT col1 FROM text_tbl
11831192 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('山田'))
11841193 AND pgs2norm(col1) LIKE likequery(pgs2norm('京都'));
1185-LOG: pgs2malloc(): buflen 2048, needed 16, maxlen 4194304
1186-LOG: pgs2norm(): complete (set result cache): 山田
1187-LOG: pgs2malloc(): buflen 2048, needed 16, maxlen 4194304
1188-LOG: pgs2norm(): complete (set result cache): 京都
1194+LOG: pgs2malloc()
1195+LOG: pgs2norm(): complete
1196+LOG: pgs2malloc()
1197+LOG: pgs2norm(): complete
11891198 col1
11901199 ------------------
11911200 東京都山田太郎
@@ -1200,31 +1209,31 @@ LOG: pgs2norm(): complete (set result cache): 京都
12001209 SELECT col1 FROM text_tbl
12011210 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('東京都'))
12021211 AND pgs2norm(col1) LIKE likequery(pgs2norm('太'));
1203-LOG: pgs2malloc(): buflen 2048, needed 22, maxlen 4194304
1204-LOG: pgs2norm(): complete (set result cache): 東京都
1205-LOG: pgs2malloc(): buflen 2048, needed 10, maxlen 4194304
1206-LOG: pgs2norm(): complete (set result cache): 太
1207-LOG: pgs2malloc(): buflen 2048, needed 46, maxlen 4194304
1208-LOG: pgs2norm(): complete (set result cache): 東京都山田太郎
1209-LOG: pgs2norm(): quick exit: 東京都山田太郎
1210-LOG: pgs2malloc(): buflen 2048, needed 48, maxlen 4194304
1211-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1212-LOG: pgs2norm(): quick exit: 東京都 山田太郎
1213-LOG: pgs2malloc(): buflen 2048, needed 48, maxlen 4194304
1214-LOG: pgs2norm(): complete (set result cache): 東京都山田 太郎
1215-LOG: pgs2norm(): quick exit: 東京都山田 太郎
1216-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1217-LOG: pgs2norm(): complete (set result cache): 東京都 山田 太郎
1218-LOG: pgs2norm(): quick exit: 東京都 山田 太郎
1219-LOG: pgs2malloc(): buflen 2048, needed 47, maxlen 4194304
1220-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1221-LOG: pgs2norm(): quick exit: 東京都 山田太郎
1222-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1223-LOG: pgs2norm(): complete (set result cache): 東京都山田 太郎
1224-LOG: pgs2norm(): quick exit: 東京都山田 太郎
1225-LOG: pgs2malloc(): buflen 2048, needed 50, maxlen 4194304
1226-LOG: pgs2norm(): complete (set result cache): 東京都 山田太郎
1227-LOG: pgs2norm(): quick exit: 東京都 山田太郎
1212+LOG: pgs2malloc()
1213+LOG: pgs2norm(): complete
1214+LOG: pgs2malloc()
1215+LOG: pgs2norm(): complete
1216+LOG: pgs2malloc()
1217+LOG: pgs2norm(): complete
1218+LOG: pgs2norm(): quick exit
1219+LOG: pgs2malloc()
1220+LOG: pgs2norm(): complete
1221+LOG: pgs2norm(): quick exit
1222+LOG: pgs2malloc()
1223+LOG: pgs2norm(): complete
1224+LOG: pgs2norm(): quick exit
1225+LOG: pgs2malloc()
1226+LOG: pgs2norm(): complete
1227+LOG: pgs2norm(): quick exit
1228+LOG: pgs2malloc()
1229+LOG: pgs2norm(): complete
1230+LOG: pgs2norm(): quick exit
1231+LOG: pgs2malloc()
1232+LOG: pgs2norm(): complete
1233+LOG: pgs2norm(): quick exit
1234+LOG: pgs2malloc()
1235+LOG: pgs2norm(): complete
1236+LOG: pgs2norm(): quick exit
12281237 col1
12291238 ------------------
12301239 東京都山田太郎
--- a/ludia_funcs.c
+++ b/ludia_funcs.c
@@ -40,8 +40,31 @@ PG_MODULE_MAGIC;
4040
4141 /* GUC variables */
4242 #ifdef PGS2_DEBUG
43-static bool pgs2_enable_debug = false;
44-#endif
43+typedef enum pgs2_enable_debug_type
44+{
45+ PGS2_ENABLE_DEBUG_OFF, /* logs no debug log */
46+ PGS2_ENABLE_DEBUG_TERSE, /* logs tersely, e.g., just names of
47+ functions */
48+ PGS2_ENABLE_DEBUG_ON /* logs detailed infomation */
49+} pgs2_enable_debug_type;
50+
51+/* We accept all the likely variants of "on" and "off" */
52+static const struct config_enum_entry pgs2_enable_debug_options[] = {
53+ {"off", PGS2_ENABLE_DEBUG_OFF, false},
54+ {"terse", PGS2_ENABLE_DEBUG_TERSE, false},
55+ {"on", PGS2_ENABLE_DEBUG_ON, false},
56+ {"true", PGS2_ENABLE_DEBUG_ON, true},
57+ {"false", PGS2_ENABLE_DEBUG_OFF, true},
58+ {"yes", PGS2_ENABLE_DEBUG_ON, true},
59+ {"no", PGS2_ENABLE_DEBUG_OFF, true},
60+ {"1", PGS2_ENABLE_DEBUG_ON, true},
61+ {"0", PGS2_ENABLE_DEBUG_OFF, true},
62+ {NULL, 0, false}
63+};
64+
65+static int pgs2_enable_debug = PGS2_ENABLE_DEBUG_OFF;
66+#endif /* PGS2_DEBUG */
67+
4568 static char *pgs2_last_update = NULL;
4669 static int norm_cache_limit = -1;
4770 static bool escape_snippet_keyword = false;
@@ -132,11 +155,12 @@ _PG_init(void)
132155
133156 #ifdef PGS2_DEBUG
134157 /* Define custom GUC variable for debugging */
135- DefineCustomBoolVariable("ludia_funcs.enable_debug",
158+ DefineCustomEnumVariable("ludia_funcs.enable_debug",
136159 "Emit ludia_funcs debugging output.",
137160 NULL,
138161 &pgs2_enable_debug,
139- false,
162+ PGS2_ENABLE_DEBUG_OFF,
163+ pgs2_enable_debug_options,
140164 PGC_USERSET,
141165 0,
142166 NULL,
@@ -626,13 +650,15 @@ EscapeSnippetKeyword(char **s, size_t *slen)
626650 *slen = ep - *s;
627651
628652 #ifdef PGS2_DEBUG
629- if (pgs2_enable_debug)
653+ if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_ON)
630654 {
631655 char *tmp = pnstrdup(*s, *slen);
632656
633657 elog(LOG, "escaped snippet keyword: %s", tmp);
634658 pfree(tmp);
635659 }
660+ else if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_TERSE)
661+ elog(LOG, "escaped snippet keyword");
636662 #endif
637663
638664 return true;
@@ -662,13 +688,15 @@ GetSennaQuery(char *str, size_t len)
662688 escape_snippet_keyword == guc_cache)
663689 {
664690 #ifdef PGS2_DEBUG
665- if (pgs2_enable_debug)
691+ if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_ON)
666692 {
667693 char *tmp = pnstrdup(str, len);
668694
669695 elog(LOG, "GetSennaQuery(): quick exit: %s", tmp);
670696 pfree(tmp);
671697 }
698+ else if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_TERSE)
699+ elog(LOG, "GetSennaQuery(): quick exit");
672700 #endif
673701 return query_cache;
674702 }
@@ -809,9 +837,11 @@ static inline void
809837 pgs2malloc(void **buf, long *buflen, long needed, long maxlen)
810838 {
811839 #ifdef PGS2_DEBUG
812- if (pgs2_enable_debug)
840+ if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_ON)
813841 elog(LOG, "pgs2malloc(): buflen %ld, needed %ld, maxlen %ld",
814842 *buflen, needed, maxlen);
843+ else if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_TERSE)
844+ elog(LOG, "pgs2malloc()");
815845 #endif
816846
817847 if (*buf != NULL && *buflen >= needed && (*buflen <= maxlen || maxlen == 0))
@@ -907,13 +937,15 @@ pgs2norm(PG_FUNCTION_ARGS)
907937 strncmp(norm_cache, s, slen) == 0)
908938 {
909939 #ifdef PGS2_DEBUG
910- if (pgs2_enable_debug)
940+ if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_ON)
911941 {
912942 char *tmp = text_to_cstring(str);
913943
914944 elog(LOG, "pgs2norm(): quick exit: %s", tmp);
915945 pfree(tmp);
916946 }
947+ else if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_TERSE)
948+ elog(LOG, "pgs2norm(): quick exit");
917949 #endif
918950
919951 result = (text *) palloc(norm_reslen);
@@ -987,7 +1019,7 @@ retry:
9871019 }
9881020
9891021 #ifdef PGS2_DEBUG
990- if (pgs2_enable_debug)
1022+ if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_ON)
9911023 {
9921024 char *tmp = text_to_cstring(str);
9931025
@@ -995,6 +1027,8 @@ retry:
9951027 (norm_cache == NULL) ? "unset" : "set", tmp);
9961028 pfree(tmp);
9971029 }
1030+ else if (pgs2_enable_debug == PGS2_ENABLE_DEBUG_TERSE)
1031+ elog(LOG, "pgs2norm(): complete");
9981032 #endif
9991033
10001034 PG_RETURN_TEXT_P(result);
--- a/sql/pg_bigm.sql
+++ b/sql/pg_bigm.sql
@@ -384,8 +384,17 @@ EXPLAIN (costs off) SELECT replace(col1, E'\t', '*') FROM text_tbl
384384 WHERE pgs2norm(col1) LIKE likequery(pgs2norm(' '))
385385 ORDER BY col1;
386386
387--- Test whether recheck is skipped expectedly when keyword length is 1 or 2
388-SET ludia_funcs.enable_debug TO on;
387+-- Test whether recheck is skipped expectedly when keyword length is 1 or 2.
388+-- We can judge that recheck is skipped successfully if the debug messages
389+-- indicating the calls to pgs2norm() and pgs2malloc() are logged only once
390+-- respectively. So this test must run with enable_debug enabled.
391+-- Note that enable_debug must be set to 'terse' in order to stabilize the
392+-- result of this regression test. Otherwise, i.e., when enable_debug is set to
393+-- 'on', the contents dealt in function pgs2malloc() and pgs2norm() are logged,
394+-- and the order of those debug messages varies depending on the block size
395+-- in PostgreSQL server. Those detailed information are not necessary to
396+-- judge whether the recheck is skipped or not.
397+SET ludia_funcs.enable_debug TO terse;
389398 SELECT col1 FROM text_tbl
390399 WHERE pgs2norm(col1) LIKE likequery(pgs2norm('東京都')) ORDER BY col1;
391400 SELECT col1 FROM text_tbl
Show on old repository browser