460
451
log_message("Sleeping");
461
452
usleep($this->emit_delays);
464
$valres = $this->db->Query("SELECT $req FROM " . $this->db->tbl_quote_l . $grzeus->table . $this->db->tbl_quote_r, DATABASE::FETCH_NUM);
465
$vals = $valres->fetch(PDO::FETCH_NUM);
456
$opts = $this->req->GetGroupOptions($grzeus);
457
$limit = $opts->GetDateLimit();
459
$tc = $this->columns['time'];
460
if ((is_numeric($limit[0]))&&((is_numeric($limit[1]))))
461
$condition = $this->db->col_quote_l . $tc . "{$this->db->col_quote_r} BETWEEN " . $this->ImportUnixTime($limit[0]) . " and " . $this->ImportUnixTime($limit[1]);
462
elseif (is_numeric($limit[0]))
463
$condition = $this->db->col_quote_l . $tc . "{$this->db->col_quote_r} >= " . $this->ImportUnixTime($limit[0]);
464
elseif (is_numeric($limit[1]))
465
$condition = $this->db->col_quote_l . $tc . "{$this->db->col_quote_r} <= " . $this->ImportUnixTime($limit[1]);
470
if (($flags&REQUEST::PREFER_EXACTINFO) == 0)
471
$req = "MIN($tc), MAX($tc)";
473
if ($flags&REQUEST::NEED_COUNT) {
474
if ($req) $req .= ", ";
475
$req .= "COUNT($tc)";
478
// Too slow: COUNT/MIN/MAX (any of them) queries on subset (>/</BETWEEN) results in temporary table generation with MySQL InnoDB (ordering is not helping).
479
if ($req) $query = "SELECT $req FROM " . $this->db->tbl_quote_l . $grzeus->table . $this->db->tbl_quote_r;
482
if ($flags&REQUEST::PREFER_EXACTINFO) {
483
$sel = array('limit' => 1, 'condition' => $condition);
484
$query_first = $this->db->SelectRequest($grzeus->table, $tc, array_merge($sel, array('order' => "$tc ASC")));
485
$query_last = $this->db->SelectRequest($grzeus->table, $tc, array_merge($sel, array('order' => "$tc DESC")));
488
$valres = $this->db->Query($query_first, DATABASE::FETCH_NUM);
489
$vtmp = $valres->fetch(PDO::FETCH_NUM);
490
if ($vtmp) $vals[0] = $vtmp[0];
491
$valres = $this->db->Query($query_last, DATABASE::FETCH_NUM);
492
$vtmp = $valres->fetch(PDO::FETCH_NUM);
493
if ($vtmp) $vals[1] = $vtmp[0];
496
// Even without WHERE condition, this is SLOW with INNODB tables. We also can't use SHOW TABLE STATUS for approximates because it not work for VIEWs.
497
// SHOW VIEW permission is needed for this variant to work.
498
if ($condition) $condition = " WHERE $condition";
500
if (!strcasecmp($this->db->driver, "mysql")) {
501
$valres = $this->db->Query("EXPLAIN $query");
502
$vtmp = $valres->fetch(PDO::FETCH_ASSOC);
503
if ($vtmp) $vals[2] = $vtmp['rows'];
505
$valres = $this->db->Query("$query", DATABASE::FETCH_NUM);
506
$vtmp = $valres->fetch(PDO::FETCH_NUM);
507
if ($vtmp) $vals[2] = $vtmp[0];
509
} catch (PDOException $e) {
510
// Likely missing SHOW VIEW permission
516
$valres = $this->db->Query($query, DATABASE::FETCH_NUM);
517
$vals = $valres->fetch(PDO::FETCH_NUM);
468
521
if ($this->monitor_timings) {
469
if (1000000 * microtime(true) > $tt_limit) {
470
$msg = translate("The query on group '%s' is exceeded allowed execution time (exceeding %d msec). This normally indicates inappropriate indexing of the source database. You can overcome the problem by setting '%s' and '%s' options", $grp->gid, ceil(1000*microtime(true) - $tt_limit/1000), "use_cache_reader", "fill_raw_first");
522
$microtime = microtime(true);
523
$groups[$gid]['query_time'] = $microtime - $microtime_before;
524
if (1000000 * $microtime > $tt_limit) {
525
$msg = translate("The query on table '%s' is exceeded allowed execution time (exceeding %d ms). This normally indicates inappropriate indexing of the source database. You can overcome the problem by setting '%s' and '%s' options", $grzeus->table, ceil(1000*$microtime - $tt_limit/1000), "use_cache_reader", "fill_raw_first");
471
526
if ($tt_exception)
472
527
throw new ADEIException($msg);
474
log_message($this->req->GetLocationString() . ": " . $msg);
528
// else log_message($this->req->GetLocationString() . ": " . $msg);
478
532
if (($vals)&&(($vals[0])||($vals[1]))) {
479
$opts = $this->req->GetGroupOptions($grzeus);
480
$limit = $opts->GetDateLimit();
482
533
$groups[$gid]['first'] = $this->ExportUnixTime($vals[0]);
483
if ((is_int($limit[0]))&&($limit[0] > $groups[$gid]['first'])) {
534
if ((is_numeric($limit[0]))&&($limit[0] > $groups[$gid]['first'])) {
484
535
$groups[$gid]['first'] = $limit[0];
485
536
} else if ($groups[$gid]['first'] < 0) {
486
537
$groups[$gid]['first'] = 0;
489
540
$groups[$gid]['last'] = $this->ExportUnixTime($vals[1]);
490
if ((is_int($limit[1]))&&($limit[1] < $groups[$gid]['last'])) {
541
if ((is_numeric($limit[1]))&&($limit[1] < $groups[$gid]['last'])) {
491
542
$groups[$gid]['last'] = $limit[1];
492
543
} else if ($groups[$gid]['last'] < 0) {
493
544
$groups[$gid]['last'] = 0;