Jan 29 page data

page size: typically ~100 KB, extreme 256 MB

First question: row store or column store?


row store--whole records are stored contiguously --- classical method

page:
| header | rec1 | rec2 | rec3 .....
most useful for transaction processing.
Downside: when there are a large number of columns, much of the information in a row is useless if you only need to access a subset of data.

column store: ---increasingly common organization for databases.
Page:
header|||||||||| <---at I for Rec1, at I for Rec2, .....at I for RecN
Down side: records are at different pages. have to access multiple pages to get a row.
Up side: analytical process: tables are really really wide.

Useful for different circumstances.

What should be in a header?


  1. Info about table : 1. name, 2. schema (attributes)
  2. Timestamp (for Concurrency Control and Recover CCR)
  3. Info about Storage format
  4. Pointers to start of each record. (bad: complicated. Good: may reduce CPU) -- useful as there might be variable length and you cannot simply get record by offset * unit_length
  5. Number of recs
  6. Pointer to first unused slot ...

What should be included in a record header


  1. Time stamp for CCR
  2. Pointer to next record (do this to trade space for CPU, otherwise you will need to parse the next record and parsing is expensive)
  3. Pointers to attributes
  4. Valid or not? A bit or byte to tell if the record is valid or not. --- To delete, simply put a bit there. --valid or not byte

In next assignment, use provided code (page storage) to store bunch of records

"Pointers" in DBMS


C pointer is a memory address.
smart pointer is the same with a counter associated with it.
Types of pointers:

  1. Classic pointers: memory locations. --DBMS support code (Binary Tree to store the data etc.). In header, not using classical pointer ()move one page to another place and a classical pointer breaks.
  2. "Offset pointer": not absolute locations; store a distance from the specific memory location. --> assuming having the location of the header. an attribute is 28 bytes away.
  3. Off page pointer (points to DB data not on the same page). Why? Big reason: in DB structures (e.g. B tree) requires off page pointer

2)3) need to translate to the memory locations. 3) is bit difficult will be covered later.

What info do we like to include in an Off-page pointer / what data goes into an off-page pointer


  1. ID (identifier) for page
  • IP address (could be a distributed system), file, page position) (drawback: this might change)
  • Logical: file, page ID. --- you have to have some sort of server allow you to look up actual location with page ID. --- slower because you will need two searches.
  1. location of data on page. (might be an offset Ora "logical" location)

Jan 31


Swizzling - refers to process of converting logical pointers to C-style memory addresses

when to swizzle and when to "un" swizzle?

  • Fully on demand swizzling(every time we defer, we swizzle)
    pro - easy! QUIZ some one want to access a page, they call getBytes, what they have is a logical pointer, in our system, finalize with c-style pointer with a swizzling process
    Con:expensive (repeatedly go and lookup pointer)

  • Automatic swizzling: automatic means the system swizzles every pointer when loaded into RAM

    • pro: easy from application programmer's view. I just dereference things, don't need to look up (the logical 2 physical table). Also looks efficient.

    To implement:
    - need to handle eviction (swizzle ptr to null)
    - need to handle buffer cache misses (looks like on demand)
    - also need a lookup table to keep track of all the pointer in the RAM: so can handle page movements and evictions.

  • third solution: Hybrid (Once a pointer is dereferenced, its management is automatic )

Organizing records and pages into files:Big topic that going to spend a week to cover

go through several file organizing

(1) Heap (as database people, we really refers an unordered "pile" of records)
- inserts: simplest implementation: write to end of last page in file.
- Finds: iterate or scan from start to finish
- Deletes: remove rec(s) from page, periodically (Garbage Collection)
* Pros:
1. heap is simple; easy to iterate them;
2.can have good performance for large file;
3. good for adding data
* Cons:
1. Bad for "point" finds that access with a specific keys

(2) Sorted file: at records sorted according to some "search key" (one or more user supplied attributes)

  • inserts: Buffer a large batch, then periodically re-sort.
  • Question: how to sort a large (bigger than RAM) file? --answered by student (merge sort)
    TPMMS (two-phase multi-way merge sort)
    TWO phases: sort phase and merge phase
    sort phase: while some portion of file is still unsorted:
    1) Read in R pages from input file (R < B # numb buffered pages available)
    2) Sort all of the records on these pages.
    3) Write new pages (w. sorted records -- called a "run") to disk
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,383评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,522评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,852评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,621评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,741评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,929评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,076评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,803评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,265评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,582评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,716评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,395评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,039评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,027评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,488评论 2 361
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,612评论 2 350

推荐阅读更多精彩内容