Su estructura se basa en:
archivos:
id
nombre
...
tags: (2.000.000 registros)
id
idsong (contiene el id de archivos)
tag
El caso es que la consulta a la db es la siguiente:
$sacar = "SELECT DISTINCT idsong\r\n" .
"FROM tags AS found_song\r\n" .
"WHERE (tag = '{$tags[0]}')\r\n";
for ($x = 1; $x < count($tags); $x++) {
$sacar .= "AND (0 < (SELECT COUNT(id) FROM tags WHERE tag = '{$tags[$x]}' AND idsong = found_song.idsong))\r\n";
}
$sacar .= "LIMIT $ini,$prints\r\n";
$sacar = mysql_query($sacar);
El problema es que de esta menera se me satura la mysql, son muchas consultas a la vez y me petan el servidor.
Me han dicho que se puede mejorar haciendolo en 3 tablas con ésta estructura:
Storing tags:
"Item" table:
CREATE TABLE item (
itemid INT UNSIGNED NOT NULL auto_increment,
c1 VARCHAR(50) NOT NULL DEFAULT '',
PRIMARY KEY (itemid)
);
Tags table:
CREATE TABLE tag (
tagid INT UNSIGNED NOT NULL auto_increment,
tagname VARCHAR(50) NOT NULL DEFAULT '',
tagcount INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (tagid),
UNIQUE KEY (tagname)
);
Item-to-tag table:
CREATE TABLE itemtag (
itemid INT UNSIGNED NOT NULL DEFAULT '0',
tagid INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (itemid, tagid),
UNIQUE KEY (tagid, itemid)
);
-----
No se que pinta tagconut en la tabla tags y otra cosa, como sería la consulta a la db en este caso?
Si alguien puede aclararme esto se lo agradecería.
Un saludo!
![Aplauso](http://static.forosdelweb.com/fdwtheme/images/smilies/aplausos.gif)
Mikel