dongya2030
2014-04-25 14:48
浏览 55
已采纳

Codeigniter会话表结构

I would like to understand why CI's session table structure has these three primary keys: session_id, ip_address and user_agent.

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
        session_id varchar(40) DEFAULT '0' NOT NULL,
        ip_address varchar(45) DEFAULT '0' NOT NULL,
        user_agent varchar(120) NOT NULL,
        last_activity int(10) unsigned DEFAULT 0 NOT NULL,
        user_data text NOT NULL,
        PRIMARY KEY (session_id, ip_address, user_agent),
        KEY `last_activity_idx` (`last_activity`)
);

Please explain the most you can, also, I would like to hear suggestions to improve this structure. Why are ip_address and user_agent primary_keys, not just indexes? What's the difference?

Another info, this table adds a row to every user's access to the system, so, it is very bloated.

Edit: Another question that come to mind. Why would I care about user agent match?

图片转代码服务由CSDN问答提供 功能建议

我想了解为什么CI的会话表结构有以下三个主键: session_id < / code> </ em>, ip_address </ code> </ em>和 user_agent </ code> </ em>。</ p>

  CREATE TABLE IF NOT NOT EXISTS`ci_sessions`(
 session_id varchar(40)DEFAULT'0'NOT NULL,
 ip_address varchar(45)DEFAULT'0'NOT NULL,
 user_agent varchar(120)NOT NULL  ,
 last_activity int(10)unsigned DEFAULT 0 NOT NULL,
 user_data text NOT NULL,
 PRIMARY KEY(session_id,ip_address,user_agent),
 KEY`last_activity_idx`(`last_activity`)
); 
  </ code> </ pre> 
 
 

请尽量解释,我也想听听改善这种结构的建议。 为什么 ip_address </ code>和 user_agent </ code> primary_keys,而不仅仅是索引? 有什么区别?</ p>

另一个信息是,这个表为每个用户对系统的访问添加了一行,因此,它非常臃肿。</ p>

编辑 :想到的另一个问题。 我为什么要关心用户代理匹配?</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题