We have a table MySql , following is the schema
CREATE TABLE campaigns (
domain varchar(50) ,
campaign_id bigint(12) ,
log_time datetime ,
log_type int,
node_id bigint(12)
)
Brief information about table
One domain can have multiple campaigns and one campaign can have multiple nodes
Table having 150 million rows. Unique domains are 40k.
I want to create a composite index on this table to get reports on both campaign level and node level
Suppose if I create composite index like following
KEY campid_domain_nodeid_logtime (`campaign_id`,`domain`,`node_id`,`log_time`)
Does is it fully satisfy following queries that means both on campaign level and node level
Campaign level reports
select count(*) from campaigns
where domain = 'aaa' and campaign_id = '1235'
and log_time between '2016-01-01 00:00:00' and '2016-02-02 00:00:00'
Node level reports
select count(*) from campaigns
where domain = 'aaa' and campaign_id = '1235'
and node_id = '2345'
and log_time between '2016-01-01 00:00:00' and '2016-02-02 00:00:00
Thanks