Skip to content

Commit

Permalink
123
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoidFrappe committed Jun 21, 2023
1 parent dc27516 commit 805be45
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 34 deletions.
101 changes: 74 additions & 27 deletions backend/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,21 @@ ipcMain.handle(
event.sender.send('async-started');
const arr: any[] = [];
const numberOfSample: number = runQueryNumber;
let totalSampleTime: any = 0;
let minmumSampleTime: any;
let maximumSampleTime: any;
let averageSampleTime: any;
let totalSampleTime: number = 0;
let minmumSampleTime: number = 0;
let maximumSampleTime: number = 0;
let averageSampleTime: number = 0;

function parseExplainExplanation(explain) {
const regex = /actual time=(\d+\.\d+)\.\.(\d+\.\d+) rows=\d+ loops=(\d+)/g;
const matches: any[] = Array.from(explain.matchAll(regex));
let result: number = 0;

for(let i = 0; i < matches.length; i+=1){
result += (parseFloat(matches[i][2]) - parseFloat(matches[i][1])) * parseFloat(matches[i][3]);
}
return result;
}
///// /////////// /////////// /////////// ///////////

try {
Expand All @@ -405,7 +416,7 @@ ipcMain.handle(
null,
dbType
);
// console.log(LogType.WARNING, results);

console.log('ericCheck------------------------------------------------------------------ericCheck');
console.log('postgerSQL_results-----------------------------------------------------------------postgerSQL_results', results);
console.log('postgerSQL_results[1].rows-----------------------------------------------------------------postgerSQL_results[1].rows', results[1].rows);
Expand All @@ -425,28 +436,64 @@ ipcMain.handle(
console.log('ericCheck------------------------------------------------------------------ericCheck');
console.log('mySQL_results-----------------------------------------------------------------mySQL_results', results);
console.log('results[0][0]-----------------------------------------------------------------results[0][0]', results[0][0]);
// function parseExplainExplanation(explain) {
// const regex = /actual time=(\d+\.\d+)\.\.(\d+\.\d+) rows=\d+ loops=(\d+)/g;
// const matches: any[] = Array.from(explain.matchAll(regex));
// const result: any[] = [];

// for (const match of matches) {
// const actualTimeStart: any = parseFloat(match[1]);
// const actualTimeEnd: any = parseFloat(match[2]);
// const loopNumber: any = parseInt(match[3]);

// result.push({ actualTimeStart, actualTimeEnd, loopNumber });
// }

// return result;
// }

// arr.push(parseExplainExplanation(results[0][0]));
// console.log('ericCheck------------------------------------------------------------------ericCheck');
// console.log('arr-------------------------------------------------------------------arr', arr);

const eachSampleTime: any = parseExplainExplanation(results[0][0].EXPLAIN);
arr.push(eachSampleTime);
totalSampleTime += eachSampleTime;
console.log('ericCheck------------------------------------------------------------------ericCheck');
console.log('arr-------------------------------------------------------------------arr', arr);


explainResults = results[0][0];

// //////////not real result just try to get rid of bugs first///////////////
explainResults = {
Plan: {
'Node Type': 'Seq Scan',
'Parallel Aware': false,
'Async Capable': false,
'Relation Name': 'newtable1',
Schema: 'public',
Alias: 'newtable1',
'Startup Cost': 0,
'Total Cost': 7,
'Plan Rows': 200,
'Plan Width': 132,
'Actual Startup Time': 0.015,
'Actual Total Time': 0.113,
'Actual Rows': 200,
'Actual Loops': 1,
Output: [ 'newcolumn1' ],
'Shared Hit Blocks': 5,
'Shared Read Blocks': 0,
'Shared Dirtied Blocks': 0,
'Shared Written Blocks': 0,
'Local Hit Blocks': 0,
'Local Read Blocks': 0,
'Local Dirtied Blocks': 0,
'Local Written Blocks': 0,
'Temp Read Blocks': 0,
'Temp Written Blocks': 0
},
Planning: {
'Shared Hit Blocks': 64,
'Shared Read Blocks': 0,
'Shared Dirtied Blocks': 0,
'Shared Written Blocks': 0,
'Local Hit Blocks': 0,
'Local Read Blocks': 0,
'Local Dirtied Blocks': 0,
'Local Written Blocks': 0,
'Temp Read Blocks': 0,
'Temp Written Blocks': 0
},
'Planning Time': 9999,
Triggers: [],
'Execution Time': 9999
};
// ////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////


// explainResults = results[0][0];
// console.log('mysql explain results', explainResults);

// console.log(LogType.WARNING, results);
Expand All @@ -459,7 +506,7 @@ ipcMain.handle(
maximumSampleTime = Math.max(...arr);
averageSampleTime = totalSampleTime/numberOfSample;
console.log('minmumSampleTime------------------------------------------------------------------------------------------minmumSampleTime', minmumSampleTime);
console.log('maximumSampleTime------------------------------------------------------------------------------------------averageSampleTime', maximumSampleTime);
console.log('maximumSampleTime------------------------------------------------------------------------------------------maximumSampleTime', maximumSampleTime);
console.log('averageSampleTime------------------------------------------------------------------------------------------averageSampleTime', averageSampleTime);
} catch (e) {
error = `Failed to get Execution Plan. EXPLAIN might not support this query.`;
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const App = () => {
*/
const createNewQuery: CreateNewQuery = (query: QueryData) => {
// Only save query to saved queries if it contains all minimum information
console.log("ericFrontendCheck-------------------------------------------------------------------------------ericFrontendCheck");
console.log("query--------------------------------------------------------------------------------------------------query", query);
if (query.label && query.db && query.sqlString && query.group) {
const newQueries = createQuery(queries, query);
setQueries(newQueries);
Expand Down
24 changes: 17 additions & 7 deletions frontend/components/views/QueryView/QueryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,16 @@ const QueryView = ({
transformedData = {
sqlString,
returnedRows,
executionPlan: explainResults[0]['QUERY PLAN'][0],
executionPlan: {
numberOfSample, // executionPlan.numberOfSample = numberOfSample
totalSampleTime,
minmumSampleTime,
maximumSampleTime,
averageSampleTime,
...explainResults[0]['QUERY PLAN'][0],},
label: localQuery.label,
db,
group: localQuery.group,
numberOfSample: numberOfSample,
totalSampleTime: totalSampleTime,
minmumSampleTime: minmumSampleTime,
maximumSampleTime: maximumSampleTime,
averageSampleTime: averageSampleTime
};
}
if (curDBType === DBType.MySQL) {
Expand All @@ -202,6 +203,15 @@ const QueryView = ({
label: localQuery.label,
db,
group: localQuery.group,
executionPlan: {
numberOfSample, // executionPlan.numberOfSample = numberOfSample
totalSampleTime,
minmumSampleTime,
maximumSampleTime,
averageSampleTime,
// ...explainResults[0]['QUERY PLAN'][0],
...explainResults,
},
};
}

Expand Down Expand Up @@ -262,7 +272,7 @@ const QueryView = ({
Run Query
</RunButton>
</CenterButton>
<QuerySummary executionPlan={query?.executionPlan} />
<QuerySummary executionPlan={query?.executionPlan}/>
<QueryTabs
results={query?.returnedRows}
executionPlan={query?.executionPlan}
Expand Down

0 comments on commit 805be45

Please sign in to comment.