1

I am currently developing a web application, where the front-end and the application logic is entirely based in Javascript and I use PHP only for the transactions with the backend (MySQL).

Since I create complicated and interconnected objects in Javascript that will later be translated into multiple database records I need to have a unique identity for them (Id) that is generated in Javascript. I cannot overcome this and send requests to the database in order to ask for the next unique key in a table and commit it, cause as I said the object creation is rather complicated and I would have to have multiple nested AJAX requests.

Anyway if I change the Primary Key of some tables from INT to VARCHAR(32) is it going to have an impact in the performance?

Note the keys are in the form of: timestamp-zeroes_userid-zeroes_incremetedid ex. (1373222220000000001000000014)

Thanks!

4

1 回答 1

2

是的。增加的键大小会增加索引和用于存储数据的页面的大小。这导致每个数据页的记录更少,而将数据读入内存的读取次数更多。

对于单个表中的单个键,从 4 字节增加到 32 字节可能不会对性能产生重大影响。但是,如果您为每个外键引用增加了 28 个字节的成本——并且在数据库中甚至有数十个外键引用——那么较大的数据大小将开始影响性能。

在这种情况下,您应该将原始键存储在原始数据中,但还要创建一个自动递增的整数主键。

于 2013-07-07T18:58:31.463 回答