-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresRun.java
More file actions
166 lines (145 loc) · 3.94 KB
/
Copy pathPostgresRun.java
File metadata and controls
166 lines (145 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package quest;
import java.io.*;
import java.util.Arrays;
public class PostgresRun
{
boolean time_limited_exec=true;
public PostgresRun(AllObjects allObjects)
{
allObjects.setPostgresRunObj(this);
}
public void run_postgres(AllObjects allObjects)
{
BouquetData bouquetDataObj = allObjects.getBouquetDataObj();
int contPlans[][] = bouquetDataObj.getContourPlans();
int steps = bouquetDataObj.getTotalContours();
int contourPlanCount[] = bouquetDataObj.getContourPlansCount();
int totalPlans = bouquetDataObj.getTotalPlans();
String bouquetPath = bouquetDataObj.getBouquetLocation();
int dimension = bouquetDataObj.getDimension();
int finalPlansSet[] = new int[totalPlans];
String queryStringForPlans[] = new String[totalPlans];
String planWithExplain[] = new String[totalPlans];
double queryValues[]= bouquetDataObj.getQueryValues();
double time_limit[] = new double [steps];
String errorProneRelationNames[] = new String[dimension];
String query_file_path = bouquetPath + "/PServerLog_XML";
/*
* actual value for query.
* when a query is given for execution these values will be fetched from original query.
*/
finalPlansSet = bouquetDataObj.getFinalPlanSet();
int finalPlansSetLength = bouquetDataObj.totalPlans;
for(int i=0;i<finalPlansSetLength;i++)
{
System.out.print(finalPlansSet[i]+",");
}
System.out.println();
try
{
FileReader f = new FileReader(query_file_path);
BufferedReader br = new BufferedReader (f);
int i=0;
while (i<finalPlansSetLength)
{
String new_fpc_str,tempstr;
String str = br.readLine();
int hash_index = str.indexOf('#');
while (hash_index==-1)
{
str = br.readLine();
hash_index = str.indexOf('#');
}
int plan_num = Integer.parseInt(str.substring(hash_index+1));
if(plan_num==finalPlansSet[i])
{
/* <input query> fpc <xml plan to use>*/
new_fpc_str = bouquetDataObj.getQuery();
str = br.readLine();
int lastbrace = str.lastIndexOf(')');
tempstr = str.substring(0,lastbrace-1);
new_fpc_str = "explain analyse " + new_fpc_str + tempstr + ";";
String remainingPart = str.substring(lastbrace+1);
String planStr="";
String line=remainingPart;
while(line.length()!=0)
{
planStr += line+" ";
line = br.readLine();
}
queryStringForPlans[i]= new_fpc_str;//str+" "+planStr;
planWithExplain[i]="explain "+planStr;
System.out.println(queryStringForPlans[i]);
i++;
}
}
br.close();
}
catch(Exception e)
{
System.out.println("Error occured in plan file reading:"+ e);
}
int fIndex = 0;
bouquetDataObj.setQueryStringForPlans(queryStringForPlans);
CreatePlanTree createPlanTree = new CreatePlanTree();
createPlanTree.createAllPlanTreeStructure(planWithExplain, totalPlans, allObjects);
}
//Column major
int addressCalc(int resolution,int index[], int d)
{
for(int i=0;i<d;i++)
{
if(index[i]>=resolution)
{
System.err.println("Error: Indeces are out of range");
System.exit(0);
}
}
int address = 0;
for(int i=d-1;i>=0;i--)
{
int temp = index[i];
for(int j=i-1;j>=0;j--)
{
temp = temp * resolution;
}
address += temp;
}
return(address);
}
int maxInArray(int arr[])
{
int max=0;
int index=-1;
for(int i=0;i<arr.length;i++)
{
if(max<arr[i])
{
max=arr[i];
index=i;
}
}
if(index != -1)
arr[index] = -1;
return(index);
}
//because of exp selectivity location in ESS space.
int[] selLocationToESSLocation(double selectivity[],int resolution, int dimension, BouquetDriver bouquetDriverObj)
{
int flag[] = new int [dimension];
int loc[] = new int[dimension];
Arrays.fill(flag, 0);
for(int i=0;i<resolution;i++)
{
for(int j=0;j<dimension;j++)
{
if(selectivity[j] < bouquetDriverObj.picsel[i] && flag[j]==0)
{
loc[j] = Math.max(i-1, 0);
flag[j] = 1;
}
}
}
return(loc);
}
}