複雜性是規模擴展的大敵
你知道的,程式碼越簡單越好
如果真的無法消除複雜性,那就把它隔離開來
一個簡單的範例
譬如說要計算 sin 的時候,我們只要直接去呼叫 sin 函數就好而不用去管內部的實作
實際上計算 sin 的實作非常的複雜,但是因為他的介面簡單,所以我們用起來也不會很複雜
隱藏內部的細節
v1
11.1 將兩個查詢結果聯集的 UNION
使用UNION 關鍵字可以將兩個查詢的結果做聯集,只要兩者的欄位資料型別、欄位數與欄位排列順序相同即可。
用 UNION 聯集只保留不重複的列資料
聯集的意思就是將兩個集合中的所有元素放在一起,並將重複的元素只保留一個。
我們用兩個SELECT 語句分別查出市集年份是2019與2020年的首次市集日期,然後將這兩個查詢的輸出結果合併起來。因為第一個查詢與第二個查詢的輸出不重複,都會被放進聯集的輸出中:
SELECT market_year, MIN(market_date) AS first_market_date
FROM farmers_market.market_date_info
利用窗口函數 ROW_NUMBER 取得每個供應商最高價的產品
依據前面所學,我們可以利用 MAX() + GROPU BY 取得每個供應商最高價的產品的價格
SELECT
vendor_id,
MAX(original_price) AS highest_price
FROM vendor_inventory
GROUP BY vendor_id
ORDER BY vendor_id
image
LEFT JOIN
CleanShot 2024-01-24 at 16.16.24@2x
LEFT JOIN 是以左表格作爲主表格,右表格則是從表格
product_category 1->* product_category
SELECT *
FROM product
LEFT JOIN product_category
MySQL Workbench Community Edition
https://dev.mysql.com/downloads/workbench/
MySQL Workbench Community Edition 8.0.34
在 MacOS 14.2.1 一直當掉,不推薦使用
推薦使用 https://github.com/Sequel-Ace/Sequel-Ace
雖然功能比較少,但還滿穩定的
關聯式資料庫
一對多
Hash functions
hash table = hash function + array
there are some requirements for a hash function:
It needs to be consistent. For example, suppose you put in “apple” and
get back “4”. Every time you put in “apple”, you should get “4” back.
It should map different words to different numbers. For example, a
hash function is no good if it always returns “1” for any word you put
in. In the best case, every different word should map to a different
Binary search
Binary search is an algorithm; its input is a sorted list of elements
example
Algorithm running times grow at different rates
Big O establishes a worst-case run time
Q: Suppose you’re using simple search to look for a person in the phone book. In this case, you’re looking for Adit. This guy is the first entry in your phone book. So you didn’t have to look at every entry—you found it on the first try. Did this algorithm take O(n) time? Or did it take O(1) time because you found the person on the first try?
There’s a bug! (after optimization)
Identify actions: Step 1
Draw each action: Step 2
Simplify the diagram: Step 3
JavaScript threading model simplification steps
All actions on a single timeline go into a single box.
Consolidate timelines that end by creating one new timeline.
The customer communications team continues
Requirement:
Filter for only good customers (three or more purchases).
Map those to their biggest purchases.
version 1
version 2
recap
Pattern 1: Straightforward implementation
Pattern 2: Abstraction barrier
Abstraction barriers hide implementations
Ignoring details is symmetrical
marketing team => don't care the details of the implementation
dev team => don't care how marketing team uses the functions