Skip to content

Commit

Permalink
[CUBRIDQA-1235] fixed join graph output to print the remaining join g…
Browse files Browse the repository at this point in the history
…raph 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
  • Loading branch information
junsklee authored Nov 4, 2024
1 parent c893616 commit cb1b6cb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
109 changes: 64 additions & 45 deletions CTP/sql_by_cci/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cb1b6cb

Please sign in to comment.