MySQL InnoDB 與 PostgreSQL 的 Partial Index(es) 是不一樣的東西...

MySQL InnoDB 指的 Partial Index 是:

An index that represents only part of a column value, typically the first N characters (the prefix) of a long VARCHAR value.

PostgreSQL 指的 Partial Indexes 是:

A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries only for those table rows that satisfy the predicate. Partial indexes are a specialized feature, but there are several situations in which they are useful.

先講結論,PostgreSQL 可以做掉 MySQL InnoDB 的 Partial Index 想做的事情,而且還更多。

MySQL InnoDB 的 Partial Index 是設定對 prefix index (對字串前面的 n bytes),可能的情況是 CHAR(32) 只對前面 16 bytes 索引。

PostgreSQL 的 Partial Indexes 受益於許多方面而更強大。因為有 Indexes on Expressions,所以除了可以像 MySQL 對 prefix 索引外,也可以索引 suffix,甚至是索引透過 string function 得出來的值。

像是 PostgreSQL 可以設定「我只要索引一月一日出生的人的 username」:

CREATE INDEX test_index ON test_table (username) WHERE birth_month = 1 AND birth_day = 1;

在 MySQL 裡需要反正規化後下 index,或是拆出另外一個表格再下 index 的問題,在善用 PostgreSQL 這些功能就可以省下不少功夫...

用 Zerigo 的 GeoDNS 混合不同家的 CDN 服務...

兩年前就用過 Zerigo (在「用 Zerigo 的 GeoDNS 服務」這篇有提到),最近剛好有需求要用,又拿出來複習了。

在「Support - Zerigo DNS」頁面上可以看出支援哪些功能,以及設定的方法。GeoDNS 的部份可以支援幾個不同層級:

  • 美國可以再切成四個區域。
  • 依照國家與地區切割。
  • 依照洲別切割。
  • 最後,當然可以設預設值。

GeoDNS 需要 DNS Pro 的版本才能用,DNS Pro 4 的版本是 USD$20/month,包含了 4m DNS query,平均每天可以接受約 13 萬次的查詢。超額費用是 USD$4.9 (每 1m DNS query),如果你仔細算,如果只是為了 DNS query 而升級,更高階的方案反而比較貴 XDDD 所以,如果用不到那麼多 domain 以及 hosts 時,就乖乖用 DNS Pro 4,DNS query 超額部份再付費買...

這樣就可以混 domain 使用,像是把 AkamaiCDNetworks 以及 CloudFront 以及自家的 cache server 混在一起用。

因為在台灣有 server,所以台灣的使用者就導到自家 cache server 上,然後美西在 EGIHosting 有租 server 當 cache,所以就把美西導到 EGIHosting 的 server 上,然後非洲與南美上 Akamai,其他地區上 CDNetworks。