-1

i have 13 tables with +- 100 000 records in each, same columns, but if i want search some records by column in all tables it takes +- 30sec... its so long :( if i search in 1 table first refresh takes 2-3sec secong refresh takes 0.3sec thats is good for me but only for one table and i need search and get result from all. so at all i have 1 300 000 records at now and i need some fast search :( any help? ty a lot

public function getTablesAoiData(){
        return $this->database->query("SELECT TABLE_NAME as `table` FROM information_schema.TABLES WHERE TABLE_NAME LIKE '%aoiData%'");
    }

public function searchBarcode($barcode){
        $result = array();
        foreach($this->getTablesAoiData() as $key => $value){
            $result[$key] = $this->database->query("SELECT * FROM `". $value->table ."` WHERE `Barcode`=" .$barcode)->fetch();
        }
        return $result;

    }

2 Answers2

0

First of all, you didn't posted table structure. You problably don't have proper indexes, which I can't tell for sure without knowing complete create table.

Second thing is, that searching across multiple tables will always be slow. You can use UNION to make it faster, but will it still be slow and temporary table in database will be created which is not good in most cases. If you can't update your structure to have data in one table, reather use some sort of service designed for indexing and searching data like ElasticSearch

Tomáš Jacík
  • 645
  • 4
  • 12
-1

its just need to be indexed that Column Barcode and now from 30sec search in all tables i got 4ms so ty for a question if i index it :D