I have a table with the following structure:
CAMPO TIPO NULL KEY DEAFULT EXTRA
id_laudes int(11) NO PRI NULL auto_increment
id_liturgia int(11) NO UNI NULL
la_himno int(10) unsigned zerofill NO MUL NULL
la_salmos int(10) unsigned zerofill NO NULL
la_biblica int(10) unsigned zerofill NO NULL
la_benedictus int(10) unsigned zerofill NO NULL
la_preces int(10) unsigned zerofill NO NULL
la_oracion int(10) unsigned zerofill NO NULL
The index information shows the following:
Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Index_type
PRIMARY 1 id_laudes A 241 NULL NULL BTREE
unique_index 1 la_himno A 120 NULL NULL BTREE
unique_index 2 la_salmos A 241 NULL NULL BTREE
unique_index 3 la_biblica A 241 NULL NULL BTREE
unique_index 5 la_benedictus A 241 NULL NULL BTREE
unique_index 6 la_preces A 241 NULL NULL BTREE
unique_index 7 la_oracion A 241 NULL NULL BTREE
id_liturgia 1 id_liturgia A 241 NULL NULL BTREE
- the
id_laudes
column is the primary, auto-incremental key. - column
id_liturgia
is a unique index - the other columns are part of a multiple index
The doubt
The id_laudes
column, incremental auto that acts as the primary key, is not related to any other table. For its part, the column id_liturgia
can not be repeated more than once in the table, therefore, it could be a good candidate for primary key, but could not be incremental, since that column used to relate to another table in the database.
On the other hand, all the columns of the table, less id_laudes
could form a unique index, since in the table you can never repeat a record that has the same values in all those columns.
Also, all columns, minus id_laudes
are each related to another table in the database.
I think I could do without id_laudes
. But I doubt if:
-
The primary key (should and / or can be)
id_liturgia
, taking into account that it would not be auto incremental ?. In that case, would a single index be better combined with the other columns or an index for each one? -
Or can I have a composite primary key that combines all the columns in the table?
Actually I do not know what would be the best option, taking into account the relationships of each column with the other tables.
P. D.:
To shed more light on the problem, this would be the query of the laudes
table, in which you can see how each column of this table relates to its respective tables:
SELECT
l.id_tiempo, lc.cod_liturgia, ls.santo, lsv.vida, lha.antifona_i, lhh.himno,
GROUP_CONCAT(COALESCE(lhsg.orden, '') ORDER BY id_salmos SEPARATOR '|') AS ordenes,
GROUP_CONCAT(COALESCE(lhsa.antifonas, '') ORDER BY id_salmos SEPARATOR '|') AS antifonas,
GROUP_CONCAT(COALESCE(lhs.salmo_ref, '') ORDER BY id_salmos SEPARATOR '|') AS salmos_ref,
GROUP_CONCAT(COALESCE(lhst.tema, '') ORDER BY id_salmos SEPARATOR '|') AS temas,
GROUP_CONCAT(COALESCE(lhsi.intro, '') ORDER BY id_salmos SEPARATOR '|') AS intros,
GROUP_CONCAT(COALESCE(lhsg.parte, '') ORDER BY id_salmos SEPARATOR '|') AS partes,
GROUP_CONCAT(COALESCE(lhs.salmo, '') ORDER BY id_salmos SEPARATOR '|') AS salmos,
lhlb.ref, lhlb.biblica, biblica_resp, id_forma, antifona_ce, preces_intro, preces, lo.oracion,lh.la_salmos
FROM liturgia_calendario lc
JOIN liturgia l ON lc.id_liturgia=l.id_celebracion
LEFT JOIN liturgia_horas_2 lh ON l.id_celebracion=lh.id_liturgia
LEFT JOIN liturgia_horas_1 lh1 ON lc.id_liturgia=lh1.id_liturgia
LEFT OUTER JOIN liturgia_santos ls ON lc.id_liturgia=ls.id_liturgia
LEFT OUTER JOIN liturgia_horas_santos_vidas lsv ON lsv.id_santo=ls.id_santo
LEFT JOIN liturgia_horas_antifonas_join lhaj ON lh1.ol_antifona=lhaj.id_liturgia
LEFT JOIN liturgia_horas_antifonas lha ON lhaj.id_antifona=lha.id_antifona
LEFT JOIN liturgia_horas_himnos_join lhhj ON lh.la_himno=lhhj.id_liturgia
LEFT JOIN liturgia_horas_himnos lhh ON lhhj.id_himno=lhh.id_himno
LEFT JOIN liturgia_horas_salmos_grupos lhsg ON lh.la_salmos=lhsg.id_liturgia
LEFT JOIN liturgia_horas_salmos_antifonas lhsa ON lhsg.id_antifonas=lhsa.id_antifonas
LEFT JOIN liturgia_horas_salmos_temas lhst ON lhsg.id_tema=lhst.id_tema
LEFT JOIN liturgia_horas_salmos_intros lhsi ON lhsg.id_intro=lhsi.id_intro
LEFT JOIN liturgia_horas_salmos lhs ON lhsg.id_salmo=lhs.id_salmo
LEFT JOIN liturgia_horas_lbiblicas_join lhlbg ON lh.la_biblica=lhlbg.id_liturgia
LEFT JOIN liturgia_horas_lbiblicas_breves lhlb ON lhlbg.id_biblica=lhlb.id_biblica
LEFT JOIN liturgia_horas_lbiblicas_responsorios lhlbr ON lhlbg.id_responsorio=lhlbr.id_responsorio
LEFT JOIN liturgia_horas_ce_join lhcej ON lh.la_benedictus=lhcej.id_liturgia
LEFT JOIN liturgia_horas_ce lhce ON lhcej.id_antifonace=lhce.id_antifonace
LEFT JOIN liturgia_horas_preces_join lhpj ON lh.la_preces=lhpj.id_liturgia
LEFT JOIN liturgia_horas_preces lhp ON lhpj.id_preces=lhp.id_preces
LEFT JOIN liturgia_horas_oraciones_join lhoj ON lh.la_oracion=lhoj.id_liturgia
LEFT JOIN liturgia_oraciones lo ON lhoj.id_oracion=lo.id_oracion
WHERE lc.f_yy=:fyy AND lc.f_mm=:fmm AND lc.f_dd=:fdd