[svn-commits] r194 - in branches/advisor/src: back/scf/scm front/misc/analyzedb

thial01 at ingres.com thial01 at ingres.com
Mon Aug 18 13:18:22 PDT 2008


Author: thial01
Date: 2008-08-18 13:18:21 -0700 (Mon, 18 Aug 2008)
New Revision: 194

Modified:
   branches/advisor/src/back/scf/scm/scmmain.c
   branches/advisor/src/back/scf/scm/scmonitor.sc
   branches/advisor/src/front/misc/analyzedb/Analyze.py
   branches/advisor/src/front/misc/analyzedb/Present.py
Log:
Fixing bugs in analyzedb and monitordb - see #174


Modified: branches/advisor/src/back/scf/scm/scmmain.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmmain.c	2008-08-18 09:22:05 UTC (rev 193)
+++ branches/advisor/src/back/scf/scm/scmmain.c	2008-08-18 20:18:21 UTC (rev 194)
@@ -410,7 +410,7 @@
 	/* Set the time we saw the query */
 	SYSTIME now;
 	TMnow(&now);
-	statement->time = now.TM_secs;;
+	statement->time = now.TM_secs;
 	
 	/* 
 	** Now create a new workload entry for this statement 

Modified: branches/advisor/src/back/scf/scm/scmonitor.sc
===================================================================
--- branches/advisor/src/back/scf/scm/scmonitor.sc	2008-08-18 09:22:05 UTC (rev 193)
+++ branches/advisor/src/back/scf/scm/scmonitor.sc	2008-08-18 20:18:21 UTC (rev 194)
@@ -241,7 +241,8 @@
         	{
         		exec sql update statements
         			set 
-	        			frequency = :statement.frequency
+	        			frequency = :statement.frequency,
+	        			time = :statement.time
         			where database = :db_name
         				and query_key = :statement.query_key;
         	}
@@ -1236,24 +1237,24 @@
 	}
         
 	/* Use the difference between this and the last value */
-	statistics.deadlocks = scm->statistics[scm->cur_sts_idx].deadlocks - deadlocks;
-	deadlocks = scm->statistics[scm->cur_sts_idx].deadlocks;
+	statistics.deadlocks = scm->statistics[scm->cur_sts_idx-1].deadlocks - deadlocks;
+	deadlocks = scm->statistics[scm->cur_sts_idx-1].deadlocks;
 	
-	statistics.escalated_locks = scm->statistics[scm->cur_sts_idx].escalated_locks - escalated_locks;
-	escalated_locks = scm->statistics[scm->cur_sts_idx].escalated_locks;
+	statistics.escalated_locks = scm->statistics[scm->cur_sts_idx-1].escalated_locks - escalated_locks;
+	escalated_locks = scm->statistics[scm->cur_sts_idx-1].escalated_locks;
 	
-	statistics.lock_wait = scm->statistics[scm->cur_sts_idx].lock_wait - lock_wait;
-	lock_wait = scm->statistics[scm->cur_sts_idx].lock_wait; 
+	statistics.lock_wait = scm->statistics[scm->cur_sts_idx-1].lock_wait - lock_wait;
+	lock_wait = scm->statistics[scm->cur_sts_idx-1].lock_wait; 
                
 	/* Use the latest value we've seen */
-	statistics.current_connections = scm->statistics[scm->cur_sts_idx].current_connections;
-	statistics.current_sessions = scm->statistics[scm->cur_sts_idx].current_sessions;
-	statistics.max_sessions = scm->statistics[scm->cur_sts_idx].max_sessions;
-	statistics.total_rows = scm->statistics[scm->cur_sts_idx].total_rows;
-	statistics.selects_processed = scm->statistics[scm->cur_sts_idx].selects_processed;
-	statistics.locks_per_tx = scm->statistics[scm->cur_sts_idx].locks_per_tx;
-	statistics.max_locks = scm->statistics[scm->cur_sts_idx].max_locks;
-	STprintf(statistics.server, scm->statistics[i].server);
+	statistics.current_connections = scm->statistics[scm->cur_sts_idx-1].current_connections;
+	statistics.current_sessions = scm->statistics[scm->cur_sts_idx-1].current_sessions;
+	statistics.max_sessions = scm->statistics[scm->cur_sts_idx-1].max_sessions;
+	statistics.total_rows = scm->statistics[scm->cur_sts_idx-1].total_rows;
+	statistics.selects_processed = scm->statistics[scm->cur_sts_idx-1].selects_processed;
+	statistics.locks_per_tx = scm->statistics[scm->cur_sts_idx-1].locks_per_tx;
+	statistics.max_locks = scm->statistics[scm->cur_sts_idx-1].max_locks;
+	STprintf(statistics.server, scm->statistics[scm->cur_sts_idx-1].server);
 	
 	/* Reset the array pointer */
 	scm->cur_sts_idx = 0;

Modified: branches/advisor/src/front/misc/analyzedb/Analyze.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Analyze.py	2008-08-18 09:22:05 UTC (rev 193)
+++ branches/advisor/src/front/misc/analyzedb/Analyze.py	2008-08-18 20:18:21 UTC (rev 194)
@@ -32,9 +32,9 @@
 
 		""" Prepare for analysis within a given time frame """
 		if (self.__config.timefrom):
-			self.__timeframe = " and $.time >= '%s'" % self.__config.timefrom
+			self.__timeframe = " and time >= '%s'" % self.__config.timefrom
 		if (self.__config.timeto):
-			self.__timeframe += " and $.time <= '%s'" % self.__config.timeto
+			self.__timeframe += " and time <= '%s'" % self.__config.timeto
 		
 		self.__userdb = DB(self.__config, self.__config.userdb)
 		self.__imadb = DB(self.__config, "imadb")
@@ -83,7 +83,7 @@
 		""" Get all indexes """
 		results = self.__workloaddb.execute("select \
 			i.index_id, i.name, i.table_id, i.attribute_id, i.frequency, i.structure, i.data_pages, i.overflow_pages \
-			from indexes i where i.database = ? %s" % self.__timeframe.replace("$", "i"),
+			from indexes i where i.database = ?",
 			(self.__config.userdb,))
 
 		for row in results:
@@ -96,7 +96,7 @@
 		results = self.__workloaddb.execute("select \
 			a.attribute_id, a.name, a.table_id, a.frequency, a.statistics, t.name \
 			from attributes a, tables t where a.table_id = t.table_id \
-			and a.database = t.database and a.database = ? %s" % self.__timeframe.replace("$", "a"), 
+			and a.database = t.database and a.database = ?", 
 			(self.__config.userdb,) )
 		
 		for row in results:
@@ -109,7 +109,7 @@
 		results = self.__workloaddb.execute("select \
 			t.table_id, t.name, t.frequency, t.est_cpu, t.act_cpu, t.est_dio, t.act_dio, \
 			t.est_tup, t.act_tup, t.structure, t.data_pages, t.overflow_pages \
-			from tables t where t.database = ? %s" % self.__timeframe.replace("$", "t"),
+			from tables t where t.database = ?",
 			(self.__config.userdb,) )
 		
 		for row in results:
@@ -124,7 +124,7 @@
 			w.query_key, w.opf_cpu, w.opf_dio, w.qef_cpu, w.qef_dio, \
 			w.est_cpu, w.est_dio, w.pages_touched, w.time, w.wctime \
 			from workload w where database = ? %s \
-			order by time" % self.__timeframe.replace("$", "w"), 
+			order by time" % self.__timeframe, 
 			(self.__config.userdb,) )
 
 		for row in results:
@@ -133,7 +133,7 @@
 
 	def __load_statements(self):
 
-		result = self.__workloaddb.execute("select count(query_key) from statements s where 1 = 1 %s" % self.__timeframe.replace("$", "s"));
+		result = self.__workloaddb.execute("select count(*) from (select distinct query_key from workload where 1 = 1 %s) as s" % self.__timeframe);
 		self.__workloadsize = result[0][0]
 		
 		""" 
@@ -144,11 +144,11 @@
 		results = self.__workloaddb.execute("select \
 			s.query_key, query_text, frequency, \
 			opf_cpu, opf_dio, qef_cpu, qef_dio, est_cpu, est_dio, pages_touched, s.time, wctime \
-			from (select query_key, max(time) as time from workload where database = ? group by query_key) as t \
+			from (select query_key, max(time) as time from workload w where database = ? %s group by query_key) as t \
 			join workload w on t.query_key = w.query_key and t.time = w.time \
 			join statements s on s.query_key = w.query_key \
-			where s.database = ? and w.database = s.database %s \
-			order by frequency * (opf_cpu+opf_dio+qef_cpu+qef_dio) desc" % self.__timeframe.replace("$", "s"), 
+			where s.database = ? and w.database = s.database \
+			order by frequency * (opf_cpu+opf_dio+qef_cpu+qef_dio) desc" % self.__timeframe, 
 			(self.__config.userdb, self.__config.userdb) )
 
 		count = 1
@@ -173,8 +173,8 @@
 		""" Get all tables used in this statement """
 		results = self.__workloaddb.execute("select \
 			t.table_id from tables t, references r where t.table_id = r.object_id and r.object_type = 0 \
-			and r.query_key = ? and r.database = ?  and t.database = r.database %s \
-			order by t.frequency desc" % self.__timeframe.replace("$", "t"),
+			and r.query_key = ? and r.database = ?  and t.database = r.database \
+			order by t.frequency desc",
 			(statement.query_key, self.__config.userdb))
 	
 		table_references = []
@@ -193,8 +193,8 @@
 			results1 = self.__workloaddb.execute("select \
 				a.attribute_id, a.table_id from attributes a, references r where a.table_id = ? \
 				and a.table_id = r.table_id and a.attribute_id = r.object_id and r.object_type = 1 \
-				and r.query_key = ? and r.database = ? and a.database = r.database %s \
-				order by a.frequency desc" % self.__timeframe.replace("$", "a"),
+				and r.query_key = ? and r.database = ? and a.database = r.database \
+				order by a.frequency desc",
 				(table.id, statement.query_key, self.__config.userdb))
 
 			attr_list = []
@@ -211,9 +211,9 @@
 		""" Get indexes used in this statement """
 		results = self.__workloaddb.execute("select \
 			i.index_id from indexes i, references r where i.index_id = r.object_id \
-			and r.object_type = 2 and r.query_key = ? %s \
+			and r.object_type = 2 and r.query_key = ? \
 			and r.database = ? and i.database = r.database \
-			and i.frequency > 0 order by i.frequency desc" % self.__timeframe.replace("$", "i"),
+			and i.frequency > 0 order by i.frequency desc",
 			(statement.query_key, self.__config.userdb))
 
 		debug("  ## Used indexes:")
@@ -399,7 +399,7 @@
 		results = self.__workloaddb.execute("select \
 			time, current_connections, current_sessions, max_sessions, total_rows, selects_processed, \
 			locks_per_tx, max_locks, locks_used, deadlocks, escalated_locks, lock_wait \
-			from statistics s where 1 = 1 %s order by time" % self.__timeframe.replace("$", "s"))
+			from statistics where 1 = 1 %s order by time" % self.__timeframe)
 
 		last_row = False
 		for row in results:

Modified: branches/advisor/src/front/misc/analyzedb/Present.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Present.py	2008-08-18 09:22:05 UTC (rev 193)
+++ branches/advisor/src/front/misc/analyzedb/Present.py	2008-08-18 20:18:21 UTC (rev 194)
@@ -224,20 +224,20 @@
 		for rec in self.__results.recommendations:
 			if rec.object.__class__.__name__ == "Statement":
 				if not rec.object.query_key in stm:
-					stm[rec.object.query_key] = []
-				stm[rec.object.query_key].append(rec)
+					stm[id(rec.object)] = []
+				stm[id(rec.object)].append(rec)
 			if rec.object.__class__.__name__ == "Table":
 				if not rec.object.name in tab:
-					tab[rec.object.name] = []
-				tab[rec.object.name].append(rec)
+					tab[id(rec.object)] = []
+				tab[id(rec.object)].append(rec)
 			if rec.object.__class__.__name__ == "Attribute":
 				if not rec.object.name in atr:
-					atr[rec.object.name] = []
-				atr[rec.object.name].append(rec)
+					atr[id(rec.object)] = []
+				atr[id(rec.object)].append(rec)
 			if rec.object.__class__.__name__ == "Index":
 				if not rec.object.name in idx:
-					idx[rec.object.name] = []
-				idx[rec.object.name].append(rec)
+					idx[id(rec.object)] = []
+				idx[id(rec.object)].append(rec)
 
 		recom_str = """
 			<i>(Recommended %d time(s))</i><br />
@@ -246,7 +246,7 @@
 
 		stm_str = "<h3>Statements:</h3>"
 		for s in stm:
-			stm_str += "<b>Query %s:</b><br /> " % self.__querylink(s)
+			stm_str += "<b>Query %s:</b><br /> " % self.__querylink(stm[s][0].object.query_key)
 			for v in stm[s]:
 				stm_str += recom_str % (
 					v.frequency,
@@ -256,7 +256,7 @@
 				
 		tab_str = "<h3>Tables:</h3>"
 		for t in tab:
-			tab_str += "<b>Table %s:</b><br /> " % t
+			tab_str += "<b>Table %s:</b><br /> " % tab[t][0].object.name
 			tab[t].sort(lambda x, y: cmp(x.frequency, y.frequency), reverse=True)
 			for v in tab[t]:
 				tab_str += recom_str % (
@@ -267,7 +267,7 @@
 				
 		atr_str = "<h3>Attributes:</h3>"
 		for a in atr:
-			atr_str += "<b>Attribute %s(%s):</b><br /> " % (atr[a][0].object.table_name, a)
+			atr_str += "<b>Attribute %s(%s):</b><br /> " % (atr[a][0].object.table_name, atr[a][0].object.name)
 			atr[a].sort(lambda x, y: cmp(x.frequency, y.frequency), reverse=True)
 			for v in atr[a]:
 				atr_str += recom_str % (
@@ -278,7 +278,7 @@
 				
 		idx_str = "<h3>Indexes:</h3>"
 		for i in idx:
-			idx_str += "<b>Index %s:</b><br /> " % (i)
+			idx_str += "<b>Index %s:</b><br /> " % (idx[i][0].object.name)
 			idx[i].sort(lambda x, y: cmp(x.frequency, y.frequency), reverse=True)
 			for v in idx[i]:
 				idx_str += recom_str % (




More information about the svn-commits mailing list