Optimize index structure of counter_log table for quick querying when a new visitor arrives

This commit is contained in:
Kijin Sung 2025-09-04 01:14:43 +09:00
parent 9b18c48256
commit 4a84f52edb
2 changed files with 33 additions and 3 deletions

View file

@ -31,6 +31,20 @@ class counter extends ModuleObject
return true; return true;
} }
// Index optimization
if (!$oDB->isIndexExists('counter_log', 'idx_regdate_ipaddress'))
{
return true;
}
if ($oDB->isIndexExists('counter_log', 'idx_site_counter_log'))
{
return true;
}
if ($oDB->isIndexExists('counter_log', 'idx_counter_log'))
{
return true;
}
return false; return false;
} }
@ -46,6 +60,20 @@ class counter extends ModuleObject
{ {
$oDB->dropTable('counter_site_status'); $oDB->dropTable('counter_site_status');
} }
// Index optimization
if (!$oDB->isIndexExists('counter_log', 'idx_regdate_ipaddress'))
{
$oDB->addIndex('counter_log', 'idx_regdate_ipaddress', ['regdate(8)', 'ipaddress']);
}
if ($oDB->isIndexExists('counter_log', 'idx_site_counter_log'))
{
$oDB->dropIndex('counter_log', 'idx_site_counter_log');
}
if ($oDB->isIndexExists('counter_log', 'idx_counter_log'))
{
$oDB->dropIndex('counter_log', 'idx_counter_log');
}
} }
/** /**

View file

@ -1,6 +1,8 @@
<table name="counter_log"> <table name="counter_log">
<column name="site_srl" type="bigint" notnull="notnull" default="0" index="idx_site_counter_log" /> <column name="id" type="bigint" notnull="notnull" primary_key="primary_key" auto_increment="auto_increment" />
<column name="ipaddress" type="varchar" size="60" notnull="notnull" index="idx_site_counter_log" /> <column name="site_srl" type="bigint" notnull="notnull" default="0" />
<column name="regdate" type="date" notnull="notnull" index="idx_counter_log" /> <column name="regdate" type="date" notnull="notnull" />
<column name="ipaddress" type="varchar" size="60" notnull="notnull" />
<column name="user_agent" type="varchar" size="250" /> <column name="user_agent" type="varchar" size="250" />
<index name="idx_regdate_ipaddress" columns="regdate(8),ipaddress" />
</table> </table>