CREATE TABLE `categ` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `categ` varchar(32) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

INSERT INTO `categ` (`id`, `categ`) VALUES 
(1, 'General'),
(2, 'Politica'),
(3, 'Sport'),
(4, 'International'),
(5, 'Cultura'),
(6, 'Hitech'),
(7, 'Showbizz');
CREATE TABLE `ziare` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `ziar` varchar(255) NOT NULL default '',
  `www` varchar(255) NOT NULL default '',
  `xml` varchar(255) NOT NULL default '',
  `tara` char(2) NOT NULL default '',
  `status` char(1) NOT NULL default '1',
  `comentariu` varchar(255) NOT NULL default '',
  `lastupdate` int(9) NOT NULL default '0',
  `total` int(9) NOT NULL default '0',
  `totallast` int(3) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=103 ;

INSERT INTO `ziare` (`id`, `ziar`, `www`, `xml`, `tara`, `status`, `comentariu`, `lastupdate`, `total`, `totallast`) VALUES 
(1, 'Name 1', 'http://www.qwert.ro/', 'http://www.qwert.ro/stiri/rss/toate-stirile.rss', 'ro', '1', 'done', 1221054319, 0, 367),
(2, 'Name 2', 'http://www.qwert.ro/', 'http://www.qwert.ro/rss.php/evz.xml', 'ro', '1', 'done', 1221045320, 0, 110),
(3, 'Name 3', 'http://www.qwert.ro/', 'http://www.qwert.ro/rss.xml', 'ro', '1', 'done', 1221056176, 0, 98),
(4, 'Name 4', 'http://www.qwert.ro/', 'http://www.qwert.ro/usr/rss/index20.xml', 'ro', '1', 'done', 1221054308, 0, 20),
(5, 'Name 5', 'http://www.qwert.ro/', 'http://www.qwert.ro/index20.xml', 'ro', '1', 'done', 1221044479, 0, 58),
(6, 'Name 6', 'http://www.qwert.ro/', 'http://www.qwert.ro/rss.php?section=0', 'ro', '1', 'done', 1221044476, 0, 472),
(7, 'Name 7', 'http://www.qwert.ro/', 'http://www.qwert.ro/stiri.xml', 'ro', '1', 'done', 1221056264, 0, 70),
(8, 'Name 8', 'http://www.qwert.info/', 'http://www.qwert.info/rss-feed.xml', 'ro', '1', 'done', 1221041776, 0, 20),
.....
(101, 'Name 101', 'http://www.rgnpress.ro/', 'http://www.rgnpress.ro/index.php?option=com_rss&feed=RSS2.0&no_html=1', 'ro', '1', 'done', 0, 0, 0);
CREATE TABLE stiri (
  `id_ziar` int(10) unsigned NOT NULL default '0',
  `title` varchar(255) collate utf8_unicode_ci NOT NULL default '',
  `titlemd5` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `descriere` text collate utf8_unicode_ci NOT NULL,
  `adresa` varchar(255) collate utf8_unicode_ci NOT NULL default '',
  `data` int(11) NOT NULL default '0',
  `id_categ` int(2) NOT NULL default '0',
  PRIMARY KEY  (`titlumd5`),
  UNIQUE KEY `adresa` (`adresa`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `stiri` (`id_ziar`, `titlu`, `titlumd5`, `descriere`, `adresa`, `data`, `id_categ`) VALUES 
(43, 'SoluÅ£ii de control al crizelor', '5a5a5f5d9ef452e0516881316ebcd2de', 'România are cuvânt de ordine optimizarea afacerilor prin intermediul infrastructurilor IT&C. CIO COUNCIL, Institutul Bancar Român ÅŸi Agora Media au organizat conferinÅ£a „Gestionarea eficientă a infrastructurilor IT&Câ€Â, pe 10 septembie 2008, în Aula Institutului Bancar Român\n\n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24570&qs_f_id=5', 1221135303, 6),
(43, 'Netapp partner academy', 'a4d10b4572d8f2cc21cb8fcfd38d67de', 'Pe data de 10 septembrie 2008, a avut loc în Bucureşti evenimentul NetApp Partner Academy. Evenimentul s-a adresat doar partenerilor NetApp din România şi a constituit într-o serie de prezentări tehnice şi de vânzări\n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24574&qs_f_id=5', 1221135303, 6),
(43, 'Ascenta va realiza un proiect it de gestiune a producţiei şi trasabilitate', '0d1b74ed1ab73f80af04ccd50e349c8f', 'ASCENTA, divizia de consultanţă IT a Grupului Softwin anunţă semnarea unui contract cu Agricola Bacău, ce presupune implementarea unui sistem informatic integrat de gestiune a producţiei. Proiectul se bazează pe soluţiile norvegiene Scase, Ascenta încheind un parteneriat cu producătorul scandinav la începutul lunii iulie a.c.\n\n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24577&qs_f_id=5', 1221135303, 6),
(43, 'Orange şi rim lansează blackberry bold în românia', 'cbb57127f453aef3ff9d940f90b70b28', 'Bucureşti, 10 septembrie. Orange şi Research In Motion (RIM) – (Nasdaq: RIMM; TSX: RIM) anunţă lansarea noului BlackBerry Bold cu capacităţi 3G pe piaţa românească. \n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24573&qs_f_id=5', 1221135303, 6),
(43, 'Programul intelteach - instruirea în societatea cunoaşterii', 'f53a7e0d7803e87e5e76671dbdf30dbc', 'Recent, la Târgovişte, s-a desfăşurat o nouă sesiune de training în cadrul Programului IntelTeach - Instruirea în Societatea Cunoaşterii. Ca şi la precedenta ediţie, evenimentul a vizat pregătirea cadrelor didactice pentru obţinerea certificării de Master Teacher\n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24575&qs_f_id=5', 1221135303, 6),
(43, 'Securitatea informaţiilor în mediile enterprise', '69a51b7acf26b15c896e5962fdd759ea', 'Cea mai mare problemă de securitate a datelor în mediile enterprise rămâne controlul asupra informaţiilor confidenţiale de pe laptopuri şi de pe dispozitivele mobile. Există în continuare un număr mare de calculatoare pierdute sau furate, iar studiile recente au dezvăluit că angajaţii, în special cei tineri, nu sunt foarte îngrijoraţi de regulile de securitate ale companiei\n', 'http://www.agora.ro/index.php?qs_sect_id=126&qs_stire_id=24576&qs_f_id=5', 1221135303, 6),
......
Over 1.300.000 records

The table 'stiri' is the only one I will use to insert data (over 1.300.000 records) This table has will link ziare with id_ziare and categ with id_categ.
I need to have 'adresa' field UNIQUE because with cronjob I will try to insert the same records (from RSS) more time and to skip duplicate row.

At the beginning all looks ok but now with over 1.300.000 records I can't make any search or Order BY

For search I use:

SELECT s.*, z.* FROM stiri s, ziare z WHERE z.id = s.id_ziar AND MATCH ( s.titlu, s.descriere ) AGAINST ( word1 IN BOOLEAN MODE ) AND z.tara = 'ro' ORDER BY s.data DESC LIMIT 100 OFFSET 0

or for multiple words

SELECT s.*, z.* FROM stiri s, ziare z WHERE z.id = s.id_ziar AND MATCH ( s.titlu, s.descriere ) AGAINST ( word1+word2+word3  IN BOOLEAN MODE ) AND z.tara = 'ro' ORDER BY s.data DESC LIMIT 100 OFFSET 0

Any idea how to optimize the tables structure?

Recommended Answers

All 2 Replies

any column you are querying against you will want to use an index
assuming you are querying a lot against the title and description, you might want to separate them out to a separate table, and have bigint field inside of the stiri table that is a foreign key to that table
query the smaller table that has the description on title, get the id
then query the larget table with your ids, much quicker to search based upon an int value, and search a smaller when searching for text

Instead bigint field foreign key is a big difference if I will use already created titlemd5 ? Will be much easy to create and use the new table.

Thank you for suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.