Commit 7ad2db71 authored by Mike Hibler's avatar Mike Hibler

Fix more issues with reverse (aka, "show most recent") option.

If both -r and -n (number of records) was given (i.e., as called via the
web page), then we were still fetching the oldest N records but then
presenting those most recent first. Not real useful. Now we use sub-query fu
to fetch the most recent N records but still keep those in oldest-to-newest
order for processing.

Also, removed two-field-order-by hack as sorting on just the timestamp now
seems to use the index and no longer does a filesort.

Don't generate summary info when the -x (history index) option is given.
parent 85ee474d
#!/usr/bin/perl -w
#
# Copyright (c) 2005-2014 University of Utah and the Flux Group.
# Copyright (c) 2005-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -152,9 +152,6 @@ if (defined($options{"l"})) {
if (defined($options{"n"})) {
$numrecs = $options{"n"};
}
if (defined($options{"x"})) {
$startrecord = $options{"x"};
}
if (defined($options{"r"})) {
$revorder = 1;
}
......@@ -165,6 +162,10 @@ if (defined($options{"d"})) {
$datetime = timelocal(strptime($options{"d"}));
$summary = 0;
}
if (defined($options{"x"})) {
$startrecord = $options{"x"};
$summary = 0;
}
if (defined($options{"t"})) {
if (!defined($datetime)) {
$datetime = time() - $options{"t"};
......@@ -356,21 +357,34 @@ if ($datelimit) {
$querymod .= " AND stamp<='$datelimit'";
}
# XXX maybe it would be better to sort them here in perl, outside the DB?
# Note that the combo field order by is strictly to convince mysql
# to use an index for sort instead of filesort. I have no idea why
# it does this, but it cuts the query from 70 seconds to under 1 second.
#
my $orderby = " ORDER BY history_id,stamp ASC";
# Bogus, but reading the entire table is nuts! Millions of rows.
my $limitby = ($showall && $numrecs ? "limit " . $numrecs * 10 : "");
my $query_result =
DBQueryFatal("SELECT node_id,stamp,op,uid,pid,eid, ".
" experiment_stats.exptidx,cnet_ip,phys_nodeid,history_id ".
"FROM node_history,experiment_stats ".
"WHERE node_history.exptidx=experiment_stats.exptidx ".
"$querymod $orderby $limitby");
#
# If we are not getting all the records and we want the most recent
# then we have to reverse the initial DB sort and then reverse again
# using mysql sub-query fu.
#
my $query_result;
if ($revorder && $limitby) {
my $orderby = " ORDER BY stamp DESC";
$query_result =
DBQueryFatal("SELECT * from (SELECT node_id,stamp,op,uid,pid,eid, ".
" experiment_stats.exptidx,cnet_ip,phys_nodeid, ".
" history_id ".
"FROM node_history,experiment_stats ".
"WHERE node_history.exptidx=experiment_stats.exptidx ".
"$querymod $orderby $limitby) SUB ORDER BY stamp ASC");
} else {
my $orderby = " ORDER BY stamp ASC";
$query_result =
DBQueryFatal("SELECT node_id,stamp,op,uid,pid,eid, ".
" experiment_stats.exptidx,cnet_ip,phys_nodeid, ".
" history_id ".
"FROM node_history,experiment_stats ".
"WHERE node_history.exptidx=experiment_stats.exptidx ".
"$querymod $orderby $limitby");
}
my $lastid = 0;
my $laststamp = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment