關於資料庫的資料表主鍵

資料表主鍵,用來唯一識別資料表中的資料,可以有單一主鍵或複合主鍵

以單一主鍵來說,常用的有三種,自動遞增序列號、UUID、隨機不重複碼

 

主鍵的選擇,主要有幾種考量,唯一、效能、安全性、擴充

網路上搜尋 資料庫 uuid 會有不少討論,以下列出一些整理

 

自動遞增序列號 (server side)

優點

  • 效能
    • 欄位型別為 int 或 big int,作為 DB 索引值,速度較快

缺點

  • 效能
    • 在插入一筆資料時,若其它資料表也需要知道該主鍵做為 foreign key 或欄位資料,需要多一次 DB query
    • 自動遞增會需要 lock,在 concurrency 情形下,多少會影響效率
  • 安全性
    • 作為 URI 的存取 ID 時,會透露系統資訊 (其它資源的 ID,資源總量等)
  • 擴充
    • 非全域唯一,需要多資料庫整併時,會發生資料衝突

 

UUID (server side / client side)

優點

  • 全域唯一
    • 在分散式系統上,個別產生也不會衝突
  • 效能
    • 在插入一筆資料時,若其它資料表也需要知道該主鍵做為 foreign key 或欄位資料,不需要多一次 DB query (client side)
  • 安全性
    • 因為 UUID 沒有順序性及透露其它欄位資訊,在作為 URI 的存取 ID 時,較為安全
  • 擴充
    • 資料庫整合時,也不會發生衝突

缺點

  • 效能
    • 比起 int 或 big int 較占空間,且索引效率較差 (可能在有幾十萬筆資料之後會有較明顯差異)

 

 

隨機不重複碼 (snowflake - client side)

優點

  • 全域唯一 (幾乎)
    • 以時間戳 (timestamp) 構成一部分 ID 識別碼,要衝突除非產生在同一毫秒 (ms)
    • 只要系統時間不回調,單一機器上不會衝突
    • 不同機器上,則要仰賴機器識別碼
  • 效能
    • 在插入一筆資料時,若其它資料表也需要知道該主鍵做為 foreign key 或欄位資料,不需要多一次 DB query (client side)
    • 欄位型別為 big int (20 bytes),作為 DB 索引值,速度較快
  • 安全性
    • 因為其沒有透露其它欄位資訊,在作為 URI 的存取 ID 時,較為安全
  • 擴充
    • 資料庫整合時,也不會發生衝突

缺點

  • 非全域唯一 (低機率)
    • 如上說明,除非同一台機器的時間回調,才有可能衝突

刺客 - 暴擊 - 毒 (Assassin - Critical Strike - Poison)

事隔有點久,這次的角色也是在獸獵聯盟玩的,想說來試試不曾玩過的毒和刺客的新昇華。

 

概念很簡單,就只是發揮刺客的天賦,高暴擊機率和高毒傷加成。

 

而最後結果比想像中好非常多,估計是可以穩穩打T18的角色,可惜我的電腦負荷不了啊!

 

Read more

暴徒 - 盛怒 - 擊暈 (Berserker - Rage - Stun)

這個build是暴徒 + 盛怒 + 暈眩 + 核星 + 暴擊 + 充能球!

This build is an assembly of Berserker, Rage, Stun, Starforge, Critical Strike and Charges

 

為什麼會是這種組合呢?其實只是把一些想玩,跟想到可以玩的東西,全部湊在一起。

Why are they put together? It is just a combination of what I want to play with and what I thought that could be put together.

 

首先是新改版的暴徒,其盛怒能力給予的加成很合我的胃口,增加傷害 、攻速還有移動速度,三個願望一次滿足,所以想要玩玩看。

Rage, Berserker's new skill, gives damage, attack speed and movement speed modifiers at the same time, like Frenzy Charge, which is my favorite. So, let's try it.

 

加上事前誤會費爾羅獵靴能夠觸發暴徒戰爭使者能力,能夠消除不少盛怒的負作用,結果只是誤會一場,就此忘了他吧。(對,我試過了,失望…)

And I considered that the triggered Intimidating Cry from Farrul's Chase could offset the negative effect of Rage partially. But it was just a misunderstanding, forget it. (Yes, I had tried...)

 

擊暈則是很早之前就想試試看。手持核星則是我想拿而已。硬要說個理由,是因為它的傷害極高,攻速又比錘子快。雖然它不比錘子能減少暈眩門檻,但是有較快的攻速以及較高的傷害,我想差異應該不大。雖然擊暈的重點是單下傷害要高,暈眩門檻越低越好,但是過慢的攻速玩起來也很難過。

Stun is what I want to try earlier and Starforge is what I want to use due to its powerful damage. To give more reasons to hold Starforge but not a two hand mace, it's because Starforge gives higher damage and faster attack speed than a two hand mace. Although, there is no additional stun threshold reduction for Starforge or on the passive point for swords, higher damage and faster attack speed make them even as I though.

 

Read more

元素使 - 野性打擊 (Elementalist - Wild Strike)

原本最早是想玩元素使+元素打擊+驟雨之弦的,但是玩到章節結束後,就決定轉型了。

As what I thought at the first, I want to make a build of Elementalist with Elemental Hit and Quill Rain.

But I made a decision to discard this build temporarily after ACT10 was completed, because of its low damage.

 

覺得這個build必須到了後期,技能寶石等級足夠,加上裝備完全,才有辦法順利的玩。

I think that it will be gamed smoothly in late stage of the build with high level of gems and the full equipments.

 

否則傷害不夠,實在痛苦。章節boss都要一直繞圈圈被追,一場五分鐘以上,真的累...

Each battle with Act Boss took me 5 mins up to run around (in order not to be killed) and then to kill the boss...My Goodness!

 

想說以後再拿回小雨弓+元素打擊,就以原本的天賦,換成之前很想玩的野性打擊來試試看

I also thought that I will take back my Quill Rain with Elemental Hit skill, so I kept my passives tree and just choosed a different skill, Wild Strike, which is what I want to try before.

 

於是就玩到了現在,還是把它記下來吧... 

And I play it up to now, so record it...

 

Read more