From cb1b6cbfc353e900a208302c00e4c22aa0e1da0a Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:19:06 +0900 Subject: [PATCH] [CUBRIDQA-1235] fixed join graph output to print the remaining join graph results when more than one join graphs exist (#685) Related Join graph PR: #680 Drivers considered: jdbc, cci * fixed join graph output to print the remaining join graph results when more than one join graphs exist (e.g., inline views) * fixed code style * fixed cci joingraph logic to support multiple join graphs * refactored variables & minor revision * memory leak check enhancements * malloc failure error handling revision --- .../cubridqa/cqt/console/util/StringUtil.java | 15 ++- CTP/sql_by_cci/execute.c | 109 ++++++++++-------- 2 files changed, 73 insertions(+), 51 deletions(-) diff --git a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/util/StringUtil.java b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/util/StringUtil.java index 3e68fb78..3ba2c664 100644 --- a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/util/StringUtil.java +++ b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/util/StringUtil.java @@ -243,15 +243,18 @@ public static String replaceJoingraph(String queryPlan) { message = reader.readLine(); continue; } else if (message.startsWith("Query plan:")) { - break; - } - + // ignore + flag = "queryplan"; + message = reader.readLine(); + continue; + } + // make chageable values hidden. if ("join".equals(flag)) { - message = message.replaceAll("sel [0-9]+\\.[0-9]+", "sel ?"); + message = message.replaceAll("sel [0-9]+\\.[0-9]+", "sel ?"); + ret.append(message + separator); } - - ret.append(message + separator); + message = reader.readLine(); } } catch (Exception e) { diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 2681a3ac..33296271 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1183,61 +1183,80 @@ formatjoingraph (FILE * fp, char *joingraph) { char *str, *p; int i, joingraphLen, newline; - bool joingraph_found = false; + int joinflag = 0; + + if (joingraph == NULL) + { + return; + } + joingraphLen = strlen (joingraph); str = (char *) malloc (sizeof (char) * (joingraphLen + 1)); - memset (str, 0, sizeof (char) * (joingraphLen + 1)); p = (char *) malloc (sizeof (char) * (joingraphLen + 1)); - memset (p, 0, sizeof (char) * (joingraphLen + 1)); + + if (str == NULL || p == NULL) + { + if (str != NULL) + { + free(str); + } + + if (p != NULL) + { + free(p); + } + + fprintf(stdout, "formatjoingraph: malloc failure\n"); + return; + } + + memset(str, 0, sizeof (char) * (joingraphLen + 1)); + memset(p, 0, sizeof (char) * (joingraphLen + 1)); + newline = 0; - - if (joingraph != NULL) + + for (i = 0; i < joingraphLen; i++) { - for (i = 0; i < joingraphLen; i++) + if (joingraph[i] == '\n') { - if (joingraph[i] == '\n') + strncpy (str, joingraph + newline, i - newline + 1); + strncpy (p, joingraph + newline, i - newline + 1); + str[i - newline + 1] = 0x00; + p[i - newline + 1] = 0x00; + newline = i + 1; + + trimline (p); + if (strlen (p) == 0) { - strncpy (str, joingraph + newline, i - newline + 1); - strncpy (p, joingraph + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - p[i - newline + 1] = 0x00; - newline = i + 1; - - trimline (p); - if (strlen (p) == 0) - { - continue; - } - - if (startswith (p, "Join graph")) - { - joingraph_found = true; - fprintf (fp, "%s", str); - continue; - } - else if (startswith (p, "Query plan:")) - { - break; - } - else - { - if (joingraph_found) - { - regex_t regex; - // hide selectivity rewriting '?'. - replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); - fprintf (fp, "%s", str); - continue; - } - } + continue; + } + + if (startswith (p, "Join graph")) + { + joinflag = 1; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query plan:")) + { + joinflag = 0; + continue; + } + + if (joinflag == 1) + { + // hide selectivity by rewriting it as 'sel ?' + replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); + fprintf (fp, "%s", str); } } - strncpy (str, joingraph + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - fprintf (fp, "%s", str); - free (str); - free (p); } + strncpy (str, joingraph + newline, i - newline + 1); + str[i - newline + 1] = 0x00; + fprintf (fp, "%s", str); + + free (str); + free (p); } int