From 19c04698c4cd5a75acb88424cef0a1a841e7e2c9 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:01:49 +0900 Subject: [PATCH 01/10] [CUBRIDQA-1236] add support for full query plans in SQL test cases with the keyword '--@fullplan' --- .../cubridqa/cqt/common/SQLParser.java | 7 +- .../cubridqa/cqt/console/bean/Sql.java | 11 +++ .../cubridqa/cqt/console/dao/ConsoleDAO.java | 18 +++- .../cubridqa/cqt/console/util/StringUtil.java | 98 ++++++++++++++++++- CTP/sql_by_cci/execute.c | 38 +++++-- 5 files changed, 154 insertions(+), 18 deletions(-) diff --git a/CTP/sql/src/com/navercorp/cubridqa/cqt/common/SQLParser.java b/CTP/sql/src/com/navercorp/cubridqa/cqt/common/SQLParser.java index 042f9499..f4de6ee7 100644 --- a/CTP/sql/src/com/navercorp/cubridqa/cqt/common/SQLParser.java +++ b/CTP/sql/src/com/navercorp/cubridqa/cqt/common/SQLParser.java @@ -61,7 +61,8 @@ public static List parseSqlFile(String sqlFile, String codeset, boolean isN boolean isCall = false; boolean isNewStatement = true; boolean isQueryplan = false; - boolean isJoingraph = false; + boolean isJoingraph = false; + boolean isFullplan = false; LineScanner lineScanner = new LineScanner(); @@ -76,6 +77,8 @@ public static List parseSqlFile(String sqlFile, String codeset, boolean isN isQueryplan = true; } else if ("--@joingraph".equals(line.trim())) { isJoingraph = true; + } else if ("--@fullplan".equals(line.trim())) { + isFullplan = true; } else { String controlCmd = getControlCommand(line); if (controlCmd != null) { @@ -119,12 +122,14 @@ public static List parseSqlFile(String sqlFile, String codeset, boolean isN Sql sql = new Sql(connId, ret.toString(), paramList, isCall); sql.setQueryplan(isQueryplan); sql.setJoingraph(isJoingraph); + sql.setFullplan(isFullplan); list.add(sql); // initialize state variables isNewStatement = true; isQueryplan = false; isJoingraph = false; + isFullplan = false; ret.setLength(0); paramList = null; isCall = false; diff --git a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/bean/Sql.java b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/bean/Sql.java index 6e47e730..9545c735 100644 --- a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/bean/Sql.java +++ b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/bean/Sql.java @@ -44,6 +44,9 @@ public class Sql { // Only join graph xxx private boolean isJoingraph = false; + // Adds both join graph and query plan + private boolean isFullplan = false; + private int type; private String result = ""; @@ -171,4 +174,12 @@ public boolean isJoingraph() { public void setJoingraph(boolean isJoingraph) { this.isJoingraph = isJoingraph; } + + public boolean isFullplan() { + return isFullplan; + } + + public void setFullplan(boolean isFullplan) { + this.isFullplan = isFullplan; + } } diff --git a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/dao/ConsoleDAO.java b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/dao/ConsoleDAO.java index fce2bf99..daed83b9 100644 --- a/CTP/sql/src/com/navercorp/cubridqa/cqt/console/dao/ConsoleDAO.java +++ b/CTP/sql/src/com/navercorp/cubridqa/cqt/console/dao/ConsoleDAO.java @@ -613,7 +613,8 @@ private void executePrepareStatement(Connection conn, Sql sql, boolean isPrintQu } String script = sql.getScript().trim().toUpperCase(); boolean isOnlyJoinGraph = sql.isJoingraph(); - if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph) { + boolean isFullplan = sql.isFullplan(); + if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph || isFullplan) { Method method2 = ps.getClass().getMethod("setQueryInfo", new Class[] {boolean.class}); method2.invoke(ps, new Object[] {true}); @@ -627,13 +628,16 @@ private void executePrepareStatement(Connection conn, Sql sql, boolean isPrintQu isRs = ps.execute(); } getAllResult(ps, isRs, sql); - if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph) { + if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph || isFullplan) { Method method = ps.getClass().getMethod("getQueryplan", new Class[] {}); String queryPlan = (String) method.invoke(ps, new Object[] {}); queryPlan = queryPlan + System.getProperty("line.separator"); if (isOnlyJoinGraph) { queryPlan = StringUtil.replaceJoingraph(queryPlan); - } else { + } else if (isFullplan) { + queryPlan = StringUtil.replaceFullplan(queryPlan); + } + else { queryPlan = StringUtil.replaceQureyPlan(queryPlan); } sql.setResult(sql.getResult() + queryPlan); @@ -675,13 +679,17 @@ private void executeStatement(Connection conn, Sql sql, boolean isPrintQueryPlan getAllResult(st, isRs, sql); String script = sql.getScript().trim().toUpperCase(); boolean isOnlyJoinGraph = sql.isJoingraph(); - if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph) { + boolean isFullplan = sql.isFullplan(); + if (((isPrintQueryPlan && script.startsWith("SELECT")) || sql.isQueryplan()) || isOnlyJoinGraph || isFullplan) { Method method = st.getClass().getMethod("getQueryplan", stringType); String queryPlan = (String) method.invoke(st, new Object[] {sql.getScript()}); queryPlan = queryPlan + System.getProperty("line.separator"); if (isOnlyJoinGraph) { queryPlan = StringUtil.replaceJoingraph(queryPlan); - } else { + } else if (isFullplan) { + queryPlan = StringUtil.replaceFullplan(queryPlan); + } + else { queryPlan = StringUtil.replaceQureyPlan(queryPlan); } sql.setResult(sql.getResult() + queryPlan); 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 3ba2c664..c628adbb 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,16 +243,108 @@ public static String replaceJoingraph(String queryPlan) { message = reader.readLine(); continue; } else if (message.startsWith("Query plan:")) { - // ignore + //ignore flag = "queryplan"; message = reader.readLine(); continue; - } - + } + // make chageable values hidden. if ("join".equals(flag)) { + message = message.replaceAll("sel [0-9]+\\.[0-9]+", "sel ?"); + ret.append(message + separator); + } + + message = reader.readLine(); + } + } catch (Exception e) { + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + } + } + } + return ret.toString(); + } + + /** + * replace the full query plan (query plan + join graph + query stmt) + * + * @param queryPlan + * @return + */ + public static String replaceFullplan(String queryPlan) { + if (queryPlan == null) { + return null; + } + + SystemModel systemModel = + (SystemModel) + XstreamHelper.fromXml( + EnvGetter.getenv("CTP_HOME") + + File.separator + + "sql/configuration/System.xml"); + StringBuilder ret = new StringBuilder(); + + String flag = "default"; + int stmtCount = 0; + String separator = System.getProperty("line.separator"); + BufferedReader reader = null; + try { + reader = new BufferedReader(new StringReader(queryPlan)); + + String message = reader.readLine(); + while (message != null) { + if (message.trim().equals("")) { + message = reader.readLine(); + continue; + } + + // Handle join graph section + if (message.startsWith("Join graph")) { + flag = "join"; + ret.append(message + separator); + message = reader.readLine(); + continue; + } + + // Handle query plan section + if (message.startsWith("Query plan:")) { + flag = "plan"; + ret.append(message + separator); + message = reader.readLine(); + continue; + } + + // Handle query statement section + if (message.startsWith("Query stmt:")) { + flag = "stmt"; + ret.append(message + separator); + stmtCount = 0; + message = reader.readLine(); + continue; + } + + // Append messages according to the current flag + if ("join".equals(flag)) { + // Modify join graph details if needed message = message.replaceAll("sel [0-9]+\\.[0-9]+", "sel ?"); ret.append(message + separator); + } else if ("plan".equals(flag) || "stmt".equals(flag)) { + if (systemModel.isQueryPlan()) { + ret.append(message + separator); + } else { + if ("plan".equals(flag)) { + ret.append(message + separator); + } else if ("stmt".equals(flag)) { + if (stmtCount == 0 || message.startsWith("/")) { + ret.append(message + separator); + stmtCount++; + } + } + } } message = reader.readLine(); diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 33296271..3e541346 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -58,6 +58,7 @@ typedef struct SqlStateStruct struct { bool hasqp; bool onlyjg; /*join graph without queryplan */ + bool hasfullp; }; bool iscallwithoutvalue; @@ -988,7 +989,7 @@ readFile (char *fileName) int ascii1 = 0, ascii2 = 0; char line[MAX_SQL_LEN]; char sql_buf[MAXLINELENGH]; - bool hasqp = 0,hasjg = 0; + bool hasqp = 0, hasjg = 0, hasfullp = 0; //initial the total sql count. total_sql = 0; @@ -1015,6 +1016,12 @@ readFile (char *fileName) hasjg = 1; hasqp = 1; } + else if (startswith (line, "--@fullplan")) + { + hasjg = 1; + hasqp = 1; + hasfullp = 1; + } else if (startswithCI (line, "--+ server-message") || startswithCI (line, "--+server-message") || startswithCI (line, "--+ holdcas") || startswithCI (line, "--+holdcas")) @@ -1023,6 +1030,7 @@ readFile (char *fileName) strcpy (sqlstate[total_sql].sql, line); sqlstate[total_sql].hasqp = 0; sqlstate[total_sql].onlyjg = 0; + sqlstate[total_sql].hasfullp = 0; //if script like "? = call" sqlstate[total_sql].iscallwithoutvalue = 0; @@ -1055,6 +1063,7 @@ readFile (char *fileName) strcpy (sqlstate[total_sql].sql, sql_buf); sqlstate[total_sql].hasqp = hasqp; sqlstate[total_sql].onlyjg = hasjg; + sqlstate[total_sql].hasfullp = hasfullp; //if script like "? = call" sqlstate[total_sql].iscallwithoutvalue = startswith (line, "?"); @@ -1064,6 +1073,7 @@ readFile (char *fileName) sql_len = 0; hasqp = 0; hasjg = 0; + hasfullp = 0; } if (is_statement_end ()) @@ -1260,7 +1270,7 @@ formatjoingraph (FILE * fp, char *joingraph) } int -dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph) +dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph, bool hasfullplan) { int res = 0; int ind = 0, index_count = 0, col_count = 0, setsize = -1, index_set = 0; @@ -1534,11 +1544,15 @@ dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph) { formatjoingraph (fp, plan); } + else if (hasfullplan) + { + formatfullplan (fp, plan); + } else { - formatplan (fp, plan); + formatqueryplan (fp, plan); } - } + } } } @@ -1789,6 +1803,7 @@ execute (FILE * fp, char conn, const SqlStateStruce *pSqlState) char *sql = pSqlState->sql; bool hasqueryplan = pSqlState->hasqp; bool onlyjoingraph = pSqlState->onlyjg; + bool hasfullplan = pSqlState->hasfullp; fprintf (fp, "===================================================\n"); @@ -1844,7 +1859,7 @@ execute (FILE * fp, char conn, const SqlStateStruce *pSqlState) if (cmd_type == CUBRID_STMT_SELECT || cmd_type == CUBRID_STMT_CALL || cmd_type == CUBRID_STMT_EVALUATE || cmd_type == CUBRID_STMT_GET_STATS) { - dumptable (fp, req, conn, hasqueryplan, onlyjoingraph); + dumptable (fp, req, conn, hasqueryplan, onlyjoingraph, hasfullplan); goto _END; } else if (cmd_type == CUBRID_STMT_UPDATE) @@ -1864,7 +1879,11 @@ execute (FILE * fp, char conn, const SqlStateStruce *pSqlState) { formatjoingraph (fp, plan); } - else + else if (hasfullplan) + { + formatfullplan (fp, plan); + } + else { formatplan (fp, plan); } @@ -1893,7 +1912,7 @@ execute (FILE * fp, char conn, const SqlStateStruce *pSqlState) res_col_info = cci_get_result_info (req, &cmd_type, &col_count); if (cmd_type == CUBRID_STMT_SELECT || cmd_type == CUBRID_STMT_CALL) { - dumptable (fp, req, conn, hasqueryplan, onlyjoingraph); + dumptable (fp, req, conn, hasqueryplan, onlyjoingraph, hasfullplan); } else { @@ -1931,6 +1950,7 @@ executebind (FILE * fp, char conn, char *param, const SqlStateStruce *pSqlState) char *sql = pSqlState->sql; bool hasqueryplan = pSqlState->hasqp; bool onlyjoingraph = pSqlState->onlyjg; + bool hasfullplan = pSqlState->hasfullp; bool iscall = pSqlState->iscallwithoutvalue; fprintf (fp, "===================================================\n"); @@ -2055,7 +2075,7 @@ executebind (FILE * fp, char conn, char *param, const SqlStateStruce *pSqlState) res_col_info = cci_get_result_info (req, &cmd_type, &col_count); if (cmd_type == CUBRID_STMT_SELECT || cmd_type == CUBRID_STMT_CALL) { - dumptable (fp, req, conn, hasqueryplan, onlyjoingraph); + dumptable (fp, req, conn, hasqueryplan, onlyjoingraph, hasfullplan); } else { @@ -2075,7 +2095,7 @@ executebind (FILE * fp, char conn, char *param, const SqlStateStruce *pSqlState) res_col_info = cci_get_result_info (req, &cmd_type, &col_count); if (cmd_type == CUBRID_STMT_SELECT || cmd_type == CUBRID_STMT_CALL) { - dumptable (fp, req, conn, hasqueryplan, onlyjoingraph); + dumptable (fp, req, conn, hasqueryplan, onlyjoingraph, hasfullplan); } else { From eb105c9842947611911c2307a7e73fa8a30bf542 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:38:13 +0900 Subject: [PATCH 02/10] [CUBRIDQA-1236] cci handling implementation and simple correction --- CTP/sql_by_cci/execute.c | 117 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 3e541346..bcbd689c 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1269,6 +1269,117 @@ formatjoingraph (FILE * fp, char *joingraph) free (p); } +void +formatfullplan (FILE * fp, char *queryPlan) +{ + char *str, *p; + int i, queryPlanLen, newline; + int isjoingraph = 0; + int isplan = 0; + int isstmt = 0; + + queryPlanLen = strlen (queryPlan); + str = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); + memset (str, 0, sizeof (char) * (queryPlanLen + 1)); + p = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); + memset (p, 0, sizeof (char) * (queryPlanLen + 1)); + newline = 0; + + if (queryPlan != NULL) + { + for (i = 0; i < queryPlanLen; i++) + { + if (queryPlan[i] == '\n') + { + strncpy (str, queryPlan + newline, i - newline + 1); + strncpy (p, queryPlan + 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")) + { + isjoingraph = 1; + isplan = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query plan:")) + { + isplan = 1; + isjoingraph = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query stmt:")) + { + isstmt = 1; + isjoingraph = 0; + isplan = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Trace Statistics:")) + { + isjoingraph = 0; + isplan = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } + + // Process Join graph section + if (isjoingraph) + { + replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); + fprintf (fp, "%s", str); + continue; + } + + // Process Query plan section + if (isplan) + { + trannum (str); + fprintf (fp, "%s", str); + continue; + } + + // Process Query statement section with handling for certain lines + if (isstmt == 1) + { + trannum (str); + fprintf (fp, "%s", str); + isstmt++; + continue; + } + else if (isstmt == 2) + { + trannum (str); + if (strindex (str, "skip ORDER BY") > -1 || strindex (str, "skip GROUP BY") > -1) + { + fprintf (fp, "%s", str); + isstmt = 0; + } + continue; + } + } + } + strncpy (str, queryPlan + newline, i - newline + 1); + str[i - newline + 1] = 0x00; + fprintf (fp, "%s", str); + free (str); + free (p); + } +} + int dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph, bool hasfullplan) { @@ -1550,7 +1661,7 @@ dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph, } else { - formatqueryplan (fp, plan); + formatplan (fp, plan); } } } @@ -1596,6 +1707,10 @@ dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph, { formatjoingraph (fp, plan); } + else if (hasfullplan) + { + formatfullplan (fp, plan); + } else { formatplan (fp, plan); From 5f10c580f0af93b346d7fb1bb2d3d1ec45a359a5 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:28:02 +0900 Subject: [PATCH 03/10] [CUBRIDQA-1236] method refactoring --- CTP/sql_by_cci/execute.c | 176 +++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 83 deletions(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index bcbd689c..186c7a76 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1278,108 +1278,118 @@ formatfullplan (FILE * fp, char *queryPlan) int isplan = 0; int isstmt = 0; + if (queryPlan == NULL) + { + return; + } + queryPlanLen = strlen (queryPlan); str = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); - memset (str, 0, sizeof (char) * (queryPlanLen + 1)); p = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); - memset (p, 0, sizeof (char) * (queryPlanLen + 1)); + + if (str == NULL || p == NULL) + { + free (str); + free (p); + return; + } + newline = 0; - if (queryPlan != NULL) + for (i = 0; i < queryPlanLen; i++) { - for (i = 0; i < queryPlanLen; i++) + if (queryPlan[i] == '\n') { - if (queryPlan[i] == '\n') - { - strncpy (str, queryPlan + newline, i - newline + 1); - strncpy (p, queryPlan + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - p[i - newline + 1] = 0x00; - newline = i + 1; - - trimline (p); - if (strlen (p) == 0) - { - continue; - } + strncpy (str, queryPlan + newline, i - newline + 1); + str[i - newline + 1] = '\0'; - if (startswith (p, "Join graph")) - { - isjoingraph = 1; - isplan = 0; - isstmt = 0; - fprintf (fp, "%s", str); - continue; - } - else if (startswith (p, "Query plan:")) - { - isplan = 1; - isjoingraph = 0; - isstmt = 0; - fprintf (fp, "%s", str); - continue; - } - else if (startswith (p, "Query stmt:")) - { - isstmt = 1; - isjoingraph = 0; - isplan = 0; - fprintf (fp, "%s", str); - continue; - } - else if (startswith (p, "Trace Statistics:")) - { - isjoingraph = 0; - isplan = 0; - isstmt = 0; - fprintf (fp, "%s", str); - continue; - } + strncpy (p, queryPlan + newline, i - newline + 1); + p[i - newline + 1] = '\0'; + newline = i + 1; - // Process Join graph section - if (isjoingraph) - { - replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); - fprintf (fp, "%s", str); - continue; - } + trimline (p); + if (strlen (p) == 0) + { + continue; + } - // Process Query plan section - if (isplan) - { - trannum (str); - fprintf (fp, "%s", str); - continue; - } + // Section Identification + if (startswith (p, "Join graph")) + { + isjoingraph = 1; + isplan = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query plan:")) + { + isplan = 1; + isjoingraph = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Query stmt:")) + { + isstmt = 1; + isjoingraph = 0; + isplan = 0; + fprintf (fp, "%s", str); + continue; + } + else if (startswith (p, "Trace Statistics:")) + { + isjoingraph = 0; + isplan = 0; + isstmt = 0; + fprintf (fp, "%s", str); + continue; + } - // Process Query statement section with handling for certain lines - if (isstmt == 1) + // Processing Based on Section + if (isjoingraph) + { + replace_substring (str, "sel [0-9]+\\.[0-9]+", "sel ?"); + fprintf (fp, "%s", str); + continue; + } + if (isplan) + { + trannum (str); + fprintf (fp, "%s", str); + continue; + } + if (isstmt == 1) + { + trannum (str); + fprintf (fp, "%s", str); + isstmt++; + continue; + } + else if (isstmt == 2) + { + trannum (str); + if (strindex (str, "skip ORDER BY") > -1 || strindex (str, "skip GROUP BY") > -1) { - trannum (str); fprintf (fp, "%s", str); - isstmt++; - continue; - } - else if (isstmt == 2) - { - trannum (str); - if (strindex (str, "skip ORDER BY") > -1 || strindex (str, "skip GROUP BY") > -1) - { - fprintf (fp, "%s", str); - isstmt = 0; - } - continue; + isstmt = 0; } + continue; } } - strncpy (str, queryPlan + newline, i - newline + 1); - str[i - newline + 1] = 0x00; - fprintf (fp, "%s", str); - free (str); - free (p); } + + // Final flush of remaining characters + strncpy (str, queryPlan + newline, queryPlanLen - newline); + str[queryPlanLen - newline] = '\0'; + fprintf (fp, "%s", str); + + free (str); + free (p); } + int dumptable (FILE * fp, int req, char con, bool hasqueryplan, bool onlyjoingraph, bool hasfullplan) { From bf772623116cc8903b818f5de7e8f97c1e0b7670 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:02:28 +0900 Subject: [PATCH 04/10] [CUBRIDQA-1236] fixed logic so that the fullplan hint goes through --- CTP/sql_by_cci/execute.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 186c7a76..130f0797 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1018,9 +1018,8 @@ readFile (char *fileName) } else if (startswith (line, "--@fullplan")) { - hasjg = 1; - hasqp = 1; hasfullp = 1; + hasqp = 1; } else if (startswithCI (line, "--+ server-message") || startswithCI (line, "--+server-message") || @@ -1285,8 +1284,9 @@ formatfullplan (FILE * fp, char *queryPlan) queryPlanLen = strlen (queryPlan); str = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); + memset (str, 0, sizeof (char) * (queryPlanLen + 1)); p = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); - + memset (p, 0, sizeof (char) * (queryPlanLen + 1)); if (str == NULL || p == NULL) { free (str); @@ -1379,8 +1379,6 @@ formatfullplan (FILE * fp, char *queryPlan) } } } - - // Final flush of remaining characters strncpy (str, queryPlan + newline, queryPlanLen - newline); str[queryPlanLen - newline] = '\0'; fprintf (fp, "%s", str); From 8270e533ccd754da668491302ea29f0060d2f0c1 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:55:40 +0900 Subject: [PATCH 05/10] [CUBRIDQA-1236] added malloc failure check --- CTP/sql_by_cci/execute.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 130f0797..e4e9670f 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1288,14 +1288,22 @@ formatfullplan (FILE * fp, char *queryPlan) p = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); memset (p, 0, sizeof (char) * (queryPlanLen + 1)); if (str == NULL || p == NULL) + { + if (str != NULL) { - free (str); - free (p); - return; + free(str); } + if (p != NULL) + { + free(p); + } + + fprintf(stdout, "formatjoingraph: malloc failure\n"); + return; + } + newline = 0; - for (i = 0; i < queryPlanLen; i++) { if (queryPlan[i] == '\n') From 5919b60dc463021b29605ab2e095e8c0f04ad329 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:05:32 +0900 Subject: [PATCH 06/10] [CUBRIDQA-1236] merged changes from revise_print_join_graph --- .../cubridqa/cqt/console/util/StringUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 c628adbb..01c92374 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,18 +243,18 @@ public static String replaceJoingraph(String queryPlan) { message = reader.readLine(); continue; } else if (message.startsWith("Query plan:")) { - //ignore + // 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); } - + message = reader.readLine(); } } catch (Exception e) { From a4d08e23b7a373fba96e8bcd87a32f15266ccd25 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:23:22 +0900 Subject: [PATCH 07/10] [CUBRIDQA-1236] edited error msg --- CTP/sql_by_cci/execute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index e4e9670f..953f1095 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1299,7 +1299,7 @@ formatfullplan (FILE * fp, char *queryPlan) free(p); } - fprintf(stdout, "formatjoingraph: malloc failure\n"); + fprintf(stdout, "formatfullplan: malloc failure\n"); return; } From a25e8bf151ddbb924b579d6441880a6140d94b97 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:52:42 +0900 Subject: [PATCH 08/10] [CUBRIDQA-1236] added ( numeric value -> ? ) conversion functionality to jdbc query plan output --- .../src/com/navercorp/cubridqa/cqt/console/util/StringUtil.java | 2 ++ 1 file changed, 2 insertions(+) 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 01c92374..5b8a1ff7 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 @@ -337,9 +337,11 @@ public static String replaceFullplan(String queryPlan) { ret.append(message + separator); } else { if ("plan".equals(flag)) { + message = message.replaceAll("[0-9]+", "?"); ret.append(message + separator); } else if ("stmt".equals(flag)) { if (stmtCount == 0 || message.startsWith("/")) { + message = message.replaceAll("[0-9]+", "?"); ret.append(message + separator); stmtCount++; } From 96687aa7efb7ca779d7718176d65fbdc33002d46 Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:08:14 +0900 Subject: [PATCH 09/10] [CUBRIDQA-1236] revised spacing --- CTP/sql_by_cci/execute.c | 58 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/CTP/sql_by_cci/execute.c b/CTP/sql_by_cci/execute.c index 953f1095..a033f110 100644 --- a/CTP/sql_by_cci/execute.c +++ b/CTP/sql_by_cci/execute.c @@ -1011,16 +1011,16 @@ readFile (char *fileName) { hasqp = 1; } - else if (startswith(line, "--@joingraph")) + else if (startswith (line, "--@joingraph")) { hasjg = 1; hasqp = 1; } - else if (startswith (line, "--@fullplan")) - { - hasfullp = 1; - hasqp = 1; - } + else if (startswith (line, "--@fullplan")) + { + hasfullp = 1; + hasqp = 1; + } else if (startswithCI (line, "--+ server-message") || startswithCI (line, "--+server-message") || startswithCI (line, "--+ holdcas") || startswithCI (line, "--+holdcas")) @@ -1029,7 +1029,7 @@ readFile (char *fileName) strcpy (sqlstate[total_sql].sql, line); sqlstate[total_sql].hasqp = 0; sqlstate[total_sql].onlyjg = 0; - sqlstate[total_sql].hasfullp = 0; + sqlstate[total_sql].hasfullp = 0; //if script like "? = call" sqlstate[total_sql].iscallwithoutvalue = 0; @@ -1062,7 +1062,7 @@ readFile (char *fileName) strcpy (sqlstate[total_sql].sql, sql_buf); sqlstate[total_sql].hasqp = hasqp; sqlstate[total_sql].onlyjg = hasjg; - sqlstate[total_sql].hasfullp = hasfullp; + sqlstate[total_sql].hasfullp = hasfullp; //if script like "? = call" sqlstate[total_sql].iscallwithoutvalue = startswith (line, "?"); @@ -1072,7 +1072,7 @@ readFile (char *fileName) sql_len = 0; hasqp = 0; hasjg = 0; - hasfullp = 0; + hasfullp = 0; } if (is_statement_end ()) @@ -1284,25 +1284,27 @@ formatfullplan (FILE * fp, char *queryPlan) queryPlanLen = strlen (queryPlan); str = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); - memset (str, 0, sizeof (char) * (queryPlanLen + 1)); p = (char *) malloc (sizeof (char) * (queryPlanLen + 1)); - memset (p, 0, sizeof (char) * (queryPlanLen + 1)); + if (str == NULL || p == NULL) - { - if (str != NULL) { - free(str); - } + if (str != NULL) + { + free(str); + } - if (p != NULL) - { - free(p); + if (p != NULL) + { + free(p); + } + + fprintf(stdout, "formatfullplan: malloc failure\n"); + return; } - - fprintf(stdout, "formatfullplan: malloc failure\n"); - return; - } - + + memset (str, 0, sizeof (char) * (queryPlanLen + 1)); + memset (p, 0, sizeof (char) * (queryPlanLen + 1)); + newline = 0; for (i = 0; i < queryPlanLen; i++) { @@ -2007,14 +2009,14 @@ execute (FILE * fp, char conn, const SqlStateStruce *pSqlState) if (res >= 0) { if (onlyjoingraph) - { + { formatjoingraph (fp, plan); } else if (hasfullplan) - { - formatfullplan (fp, plan); - } - else + { + formatfullplan (fp, plan); + } + else { formatplan (fp, plan); } From c614d765d3a2d25291fe8ed81d61684ba26ed39f Mon Sep 17 00:00:00 2001 From: junsklee <50674368+junsklee@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:25:58 +0900 Subject: [PATCH 10/10] [CUBRIDQA-1236] added missing logic --- .../com/navercorp/cubridqa/cqt/console/util/StringUtil.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 5b8a1ff7..473d459d 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 @@ -340,10 +340,13 @@ public static String replaceFullplan(String queryPlan) { message = message.replaceAll("[0-9]+", "?"); ret.append(message + separator); } else if ("stmt".equals(flag)) { - if (stmtCount == 0 || message.startsWith("/")) { + if (stmtCount == 0) { message = message.replaceAll("[0-9]+", "?"); ret.append(message + separator); stmtCount++; + } else if (message.startsWith("/")) { + message = message.replaceAll("[0-9]+", "?"); + ret.append(message + separator); } } }