I have a table in my database (hosted on MariaDB) that looks like this (I have given the definition in SQLAlchemy),
class Address(Base):
__tablename__ = 'address'
__table_args__ = {'schema': DB_NAME}
referenceID = sqlalchemy.Column(sqlalchemy.String(length=25), primary_key=True)
referenceTable = sqlalchemy.Column(sqlalchemy.String(length=25), primary_key=True)
sourceReferenceID = sqlalchemy.Column(sqlalchemy.String(length=25), primary_key=True)
addressType = sqlalchemy.Column(sqlalchemy.String(length=25), primary_key=True)
zip = sqlalchemy.Column(sqlalchemy.String(length=10))
streetAddress = sqlalchemy.Column(sqlalchemy.String(length=50))
city = sqlalchemy.Column(sqlalchemy.String(length=25))
fullAddress = sqlalchemy.Column(sqlalchemy.String(length=200))
country = sqlalchemy.Column(sqlalchemy.String(length=25))
validFrom = sqlalchemy.Column(sqlalchemy.Date)
validTo = sqlalchemy.Column(sqlalchemy.Date)
Now, it can be seen that my table has a composite key which includes several attributes.
As far as I know, a clustered index will be created out of the primary key of a table. I am not completely aware of how this works when the table consists of a composite key. An explanation on this would be appreciated.
Further, I am going to want to perform several JOINs on this table, particularly using the referenceID
and sourceReferenceID
attributes of the table. To do this efficiently, do I need to create indexes (non-clustered) on these attributes separately using index=True
?