A learning Chorme design data
When the work was found, Chrome history stored in the file:
%AppData%\Local\Google\Chrome\User Data\Profile 1\History
it is a SQLite database file.
visits
Tables, records the history of each, as follows:
urls
Table, each url is not repeated, and only the primary key, and its visit_count
field records all visits each url.
Give me inspiration:
- Try to write directly to each Chrome history, but it did not do it, but to each url as a unique primary key, effectively reducing wasted storage space caused by excessive url.
- By
urls
andvisits
different coupling mechanisms to achieve faster query.
How do is guess Chrome
Case A: When you add a history:
- Update
urls
the table, if the primary key already exists, simply update visit_count field and last_visit_time field. If the primary key does not exist, a new record is created - Update
visti
table, a new record, url field populatedurls
table's primary key.
Case B: When a user queries the entire history:
visits
Left link urls
:
SELECT u.url, u.title, v.visit_time, u.visit_count
FROM visits v LEFT JOIN urls u on v.url=u.id
Case C: When a user queries a specific history, such as title contains 'you know' this string:
SELECT u.url, u.title, v.visit_time, u.visit_count
FROM visits v LEFT JOIN urls u on v.url=u.id
WHERE u.title LIKE '%你就知道%'
There is a problem, this situation should use the sub-query faster? Case for more data, such as start urls
table to obtain the corresponding id, then based on the id to query the visits
table should avoid too many strings match.