Index: branches/5.2.x/core/units/helpers/search_helper.php =================================================================== diff -u -N -r16513 -r16655 --- branches/5.2.x/core/units/helpers/search_helper.php (.../search_helper.php) (revision 16513) +++ branches/5.2.x/core/units/helpers/search_helper.php (.../search_helper.php) (revision 16655) @@ -1,6 +1,6 @@ getSearchTable(); - $this->Conn->Query('DROP TABLE IF EXISTS ' . $search_table); - $sql = 'CREATE TABLE ' . $search_table . ' ( + $sql = 'CREATE TABLE IF NOT EXISTS ' . $search_table . ' ( `Relevance` decimal(8,5) DEFAULT NULL, `ItemId` int(11) NOT NULL DEFAULT 0, `ResourceId` int(11) DEFAULT NULL, `ItemType` int(1) NOT NULL DEFAULT 0, `EdPick` tinyint(4) NOT NULL DEFAULT 0, KEY `ResourceId` (`ResourceId`), KEY `Relevance` (`Relevance`) - )'; + ) ENGINE = MEMORY'; $this->Conn->Query($sql); + + $sql = 'TRUNCATE TABLE ' . $search_table; + $this->Conn->Query($sql); } /** Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r16621 -r16655 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 16621) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 16655) @@ -1,6 +1,6 @@ Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); + if (!$this->Application->GetVar('do_not_drop_search_table')) { - $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event + if ( $search_table_exists ) { + $this->Conn->Query('TRUNCATE TABLE '.$search_table); + } + $this->Application->SetVar('do_not_drop_search_table', true); } - $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); if ($search_table_exists) { $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; } else { - $select_intro = 'CREATE TABLE '.$search_table.' AS '; + $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS '; } $edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0'; @@ -1647,25 +1651,38 @@ // Building final search query. $search_table = $search_helper->getSearchTable(); - $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); + $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); + if ($search_table_exists) { + $this->Conn->Query('TRUNCATE TABLE '.$search_table); + $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; + } + else { + $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS '; + } + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); $pick_field = isset($fields['EditorsPick']) ? $items_table.'.EditorsPick' : '0'; - $sql = ' CREATE TABLE '.$search_table.' - SELECT '.$relevance_clause.' AS Relevance, - '.$items_table.'.'.$id_field.' AS ItemId, - '.$items_table.'.ResourceId AS ResourceId, - 11 AS ItemType, - '.$pick_field.' AS EdPick - FROM '.$items_table.' - '.implode(' ', $join_clauses).' - WHERE '.$where_clause.' - GROUP BY '.$items_table.'.'.$id_field. - $having_clause; - + $sql = $select_intro.'SELECT '.$relevance_clause.' AS Relevance, + '.$items_table.'.'.$id_field.' AS ItemId, + '.$items_table.'.ResourceId AS ResourceId, + 11 AS ItemType, + '.$pick_field.' AS EdPick + FROM '.$items_table.' + '.implode(' ', $join_clauses).' + WHERE '.$where_clause.' + GROUP BY '.$items_table.'.'.$id_field. + $having_clause; $this->Conn->Query($sql); + + if ( !$search_table_exists ) { + $sql = 'ALTER TABLE ' . $search_table . ' + ADD INDEX (ResourceId), + ADD INDEX (Relevance)'; + $this->Conn->Query($sql); + } } function getAdvancedSearchCondition($field_name, $record, $keywords, $verbs, &$highlight_keywords) Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r16621 -r16655 --- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 16621) +++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 16655) @@ -1,6 +1,6 @@ Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); + if (!$this->Application->GetVar('do_not_drop_search_table')) { - $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event + if ( $search_table_exists ) { + $this->Conn->Query('TRUNCATE TABLE '.$search_table); + } + $this->Application->SetVar('do_not_drop_search_table', true); } - $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); if ($search_table_exists) { $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; } else { - $select_intro = 'CREATE TABLE '.$search_table.' AS '; + $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS '; } $edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0';