Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMU SCS Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos – A. Pavlo Lecture#25: Column Stores.

Similar presentations


Presentation on theme: "CMU SCS Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos – A. Pavlo Lecture#25: Column Stores."— Presentation transcript:

1 CMU SCS Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos – A. Pavlo Lecture#25: Column Stores

2 CMU SCS Administrivia HW7 Phase 1: Wed Nov 11 th HW7 Phase 2: Mon Nov 30 th HW8: Mon Dec 7 th Final Exam: –Friday Dec 18 th @ 1:00pm –GHC 4401 Faloutsos/PavloCMU SCS 15-415/6152

3 CMU SCS Today’s Class Storage Models System Architectures Vectorization Compression Distributed Execution Faloutsos/PavloCMU SCS 15-415/6153

4 CMU SCS Wikipedia Example 4 CREATE TABLE pages ( pageID INT PRIMARY KEY, title VARCHAR UNIQUE, latest INT REFERENCES revisions (revID), ); CREATE TABLE pages ( pageID INT PRIMARY KEY, title VARCHAR UNIQUE, latest INT REFERENCES revisions (revID), ); CREATE TABLE revisions ( revID INT PRIMARY KEY, pageID INT REFERENCES pages (pageID), userID INT REFERENCES useracct (userID), content TEXT, updated DATETIME ); CREATE TABLE revisions ( revID INT PRIMARY KEY, pageID INT REFERENCES pages (pageID), userID INT REFERENCES useracct (userID), content TEXT, updated DATETIME ); CREATE TABLE useracct ( userID INT PRIMARY KEY, userName VARCHAR UNIQUE, ⋮ ); CREATE TABLE useracct ( userID INT PRIMARY KEY, userName VARCHAR UNIQUE, ⋮ );

5 CMU SCS OLTP On-line Transaction Processing: –Short-lived txns. –Small footprint. –Repetitive operations. Faloutsos/Pavlo5 UPDATE useracct SET lastLogin = NOW(), hostname = ? WHERE userID = ? UPDATE useracct SET lastLogin = NOW(), hostname = ? WHERE userID = ? INSERT INTO revisions VALUES (?,?…,?) SELECT * FROM useracct WHERE userName = ? AND userPass = ? SELECT * FROM useracct WHERE userName = ? AND userPass = ? SELECT P.*, R.* FROM pages AS P INNER JOIN revisions AS R ON P.latest = R.revID WHERE P.pageID = ? SELECT P.*, R.* FROM pages AS P INNER JOIN revisions AS R ON P.latest = R.revID WHERE P.pageID = ?

6 CMU SCS OLAP On-line Analytical Processing: –Long running queries. –Complex joins. –Exploratory queries. Faloutsos/PavloCMU SCS 15-415/6156 SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin) SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin)

7 CMU SCS Data Storage Models There are different ways to store tuples. We have been assuming the n-ary storage model this entire semester. Faloutsos/PavloCMU SCS 15-415/6157

8 CMU SCS n-ary Storage Model The DBMS stores all attributes for a single tuple contiguously in a block. Faloutsos/PavloCMU SCS 15-415/6158 userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname ----- NSM Disk Page

9 CMU SCS n-ary Storage Model Faloutsos/PavloCMU SCS 15-415/6159 userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname ----- NSM Disk Page SELECT * FROM useracct WHERE userName = ? AND userPass = ? SELECT * FROM useracct WHERE userName = ? AND userPass = ? B+Tree userIDuserNameuserPasslastLoginhostname INSERT INTO useracct VALUES (?,?,…?) INSERT INTO useracct VALUES (?,?,…?)

10 CMU SCS n-ary Storage Model Faloutsos/PavloCMU SCS 15-415/61510 userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname userIDuserNameuserPasslastLoginhostname NSM Disk Page SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin) SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin) X

11 CMU SCS n-ary Storage Model Advantages –Fast inserts, updates, and deletes. –Good for queries that need the entire tuple. Disadvantages –Not good for scanning large portions of the table and/or a subset of the attributes. Faloutsos/PavloCMU SCS 15-415/61511

12 CMU SCS Decomposition Storage Model The DBMS stores a single attribute for all tuples contiguously in a block. Faloutsos/PavloCMU SCS 15-415/61512 DSM Disk Page hostname userID userName userPass lastLogin

13 CMU SCS Decomposition Storage Model Faloutsos/PavloCMU SCS 15-415/61513 DSM Disk Page hostname SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin) SELECT COUNT(U.lastLogin), EXTRACT(month FROM U.lastLogin) AS month FROM useracct AS U WHERE U.hostname LIKE ‘%.gov’ GROUP BY EXTRACT(month FROM U.lastLogin)

14 CMU SCS Decomposition Storage Model Advantages –Reduces the amount wasted I/O because the DBMS only reads the data that it needs. –Better compression (more on this later). Disadvantages –Slow for point queries, inserts, updates, and deletes because of tuple splitting/stitching. Faloutsos/PavloCMU SCS 15-415/61514

15 CMU SCS History 1970s: Cantor DBMS 1980s: DSM Proposal 1990s: SybaseIQ (in-memory only) 2000s: Vertica, Vectorwise, MonetDB 2010s: Cloudera Impala, Amazon Redshift, “The Big Three” Faloutsos/PavloCMU SCS 15-415/61515

16 CMU SCS System Architectures Fractured Mirrors Partition Attributes Across (PAX) Pure Columnar Storage Faloutsos/PavloCMU SCS 15-415/61516

17 CMU SCS Fractured Mirrors Store a second copy of the database in a DSM layout that is automatically updated. –Examples: Oracle, IBM DB2 BLU Faloutsos/PavloCMU SCS 15-415/61517 NSMDSM

18 CMU SCS PAX Data is still stored in NSM blocks, but each block is organized as mini columns. Faloutsos/PavloCMU SCS 15-415/61518 PAX Disk Page hostnamelastLogin userPass hostname userName userPass userID userName

19 CMU SCS Column Stores Entire system is designed for columnar data. –Query Processing, Storage, Operator Algorithms, Indexing, etc. –Examples: Vertica, VectorWise, Paraccel, Cloudera Impala, Amazon Redshift Faloutsos/PavloCMU SCS 15-415/61519

20 CMU SCS Virtual IDs vs. Offsets Need a way to stitch tuples back together. Two approaches: –Fixed length offsets –Virtual ids embedded in columns 20 userIDuserNameuserPasshostnamelastLogin 0 1 2 3 4 5 6 7 userIDuserNameuserPasshostnamelastLogin 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 OffsetsVirtual Ids

21 CMU SCS Modifying a Column Store INSERT: –Split tuple into attributes, append to columns. DELETE: –Mark the tuple as deleted in a separate bit- vector. Check visibility at runtime. UPDATE: –Implement as DELETE+INSERT Faloutsos/PavloCMU SCS 15-415/61521

22 CMU SCS Bifurcated Architecture All txns are executed on OLTP database. Periodically migrate changes to OLAP database. Faloutsos/PavloCMU SCS 15-415/61522 OLAP Data Warehouse OLTP Extract Transform Load

23 CMU SCS Today’s Class Storage Models System Architectures Vectorization Compression Distributed Execution Faloutsos/PavloCMU SCS 15-415/61523

24 CMU SCS Query Processing Strategies The DBMS needs to process queries differently when using columnar data. We have already discussed the Iterator Model for processing tuples in the DBMS query operators. Faloutsos/PavloCMU SCS 15-415/61524

25 CMU SCS Materialization Model Each operator consumes its entire input and generates the full output all at once. Faloutsos/PavloCMU SCS 15-415/61525 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 CUSTOMERACCOUNT   acctno=acctno amt>1000 cname, amt

26 CMU SCS Iterator Model Each operator calls next() on their child operator to process tuples one at a time. Faloutsos/PavloCMU SCS 15-415/61526 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 CUSTOMERACCOUNT   acctno=acctno amt>1000 cname, amt next

27 CMU SCS Observations The Materialization Model is a bad because the intermediate results may be larger than the amount of memory in the system. The Iterator Model is bad with a DSM because it requires the DBMS to stitch tuples back together each time. Faloutsos/PavloCMU SCS 15-415/61527

28 CMU SCS Vectorized Model Like the Iterator Model but each next() invocation returns a vector of tuples instead of a single tuple. This vector does not have to contain the entire tuple, just the attributes that are needed for query processing. Faloutsos/PavloCMU SCS 15-415/61528

29 CMU SCS Vectorized Model Each operator calls next() on their child operator to process vectors. Faloutsos/PavloCMU SCS 15-415/61529 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 SELECT cname, amt FROM customer, account WHERE customer.acctno = account.acctno AND account.amt > 1000 CUSTOMERACCOUNT   acctno=acctno amt>1000 cname, amt acctno amt  acctno, amt next

30 CMU SCS Vectorized Model Reduced interpretation overhead. Better cache locality. Compiler optimization opportunities. Faloutsos/PavloCMU SCS 15-415/61530

31 CMU SCS Today’s Class Storage Models System Architectures Vectorization Compression Distributed Execution Faloutsos/PavloCMU SCS 15-415/61531

32 CMU SCS Compression Overview Compress the database to reduce the amount of I/O needed to process queries. DSM databases compress much better than NSM databases. –Storing similar data together is ideal for compression algorithms. Faloutsos/PavloCMU SCS 15-415/61532

33 CMU SCS Naïve Compression Use a general purpose algorithm to compress pages when they are stored on disk. –Example: 10KB page in memory, 4KB compressed page on disk. Do we have to decompress the page when it is brought into memory? Why or why not? Faloutsos/PavloCMU SCS 15-415/61533

34 CMU SCS Fixed-width Compression Sacrifice some compression in exchange for having uniform-length values per tuple. Faloutsos/PavloCMU SCS 15-415/61534 userIDuserNameuserPasshostnamelastLogin 0 1 2 3 4 5 6 7 Original Data userIDuserNameuserPasshostnamelastLogin 0 1 2 3 4 5 6 7 Variable-Length Compression Tuples are no longer aligned at offsets Fixed-Length Compression userIDuserNameuserPasshostnamelastLogin 0 1 2 3 4 5 6 7

35 CMU SCS Run-length Encoding Compress runs of the same value into a compact triplet: –(value, startPosition, runLength) Faloutsos/PavloCMU SCS 15-415/61535 userIDsex M M M F F M M M 0 1 2 3 4 5 6 7 Original Data userIDsex (M,0,3) (F,3,2) (M,5,3) 0 1 2 3 4 5 6 7 Unsorted RLE userIDsex (M,0,6) (F,6,2) 0 1 2 5 6 7 3 4 Sorted RLE userIDsex M M M M M M F F 0 1 2 5 6 7 3 4 Sorted Data

36 CMU SCS Bit-Vector Encoding Store a separate bit-vector for each unique value for a particular attribute where an offset in the vector corresponds to a tuple. Faloutsos/PavloCMU SCS 15-415/61536 userIDsex M M M F F M M M 0 1 2 3 4 5 6 7 Original Data userIDsex M → 1 1 1 0 0 1 1 1 0 1 2 3 4 5 6 7 Bit-Vector Compression F → 0 0 0 1 1 0 0 0 A ‘1’ means that the tuple at that offset has the bit-vector’s value

37 CMU SCS Dictionary Compression Construct a separate table of the unique values for an attribute sorted by frequency. For each tuple, store the position of its value in the dictionary instead of the real value. 37 userIDcity New York San Francisco New York Pittsburgh San Francisco New York 0 1 2 3 4 5 6 7 Original Data userIDcity 0 1 0 0 2 1 0 0 0 1 2 3 4 5 6 7 Dictionary Encoded 0→(New York,5) 1→(San Francisco,2) 2→(Pittsburgh,1) Dictionary

38 CMU SCS Processing Compressed Data Some operator algorithms can operate directly on compressed data –Saves I/O without having to decompress! Difficult to implement when the DBMS uses multiple compression schemes. It’s generally good to wait as long as possible to materialize/decompress data when processing queries… Faloutsos/PavloCMU SCS 15-415/61538

39 CMU SCS Today’s Class Storage Models System Architectures Vectorization Compression Distributed Execution Faloutsos/PavloCMU SCS 15-415/61539

40 CMU SCS Distributed OLAP Execute analytical queries that examine large portions of the database. Used for back-end data warehouses: –Example: Data mining Key Challenges: –Data movement. –Query planning. Faloutsos/PavloCMU SCS 15-415/61540

41 CMU SCS Distributed OLAP Faloutsos/PavloCMU SCS 15-415/61541 P2P4P5P3P1 Partitions Application Server Single OLAP Query

42 CMU SCS Distributed Joins Are Hard Assume tables are horizontally partitioned: –Table1 Partition Key → table1.key –Table2 Partition Key → table2.key Q: How to execute? Naïve solution is to send all partitions to a single node and compute join. Faloutsos/PavloCMU SCS 15-415/61542 SELECT * FROM table1, table2 WHERE table1.val = table2.val SELECT * FROM table1, table2 WHERE table1.val = table2.val

43 CMU SCS Broadcast Join Main Idea: Send the smaller table to all nodes where the join is then computed in parallel. –Only works if the table is small. Faloutsos/PavloCMU SCS 15-415/61543

44 CMU SCS Semi Join Main Idea: First distribute the join attributes between nodes and then recreate the full tuples in the final output. –Send just enough data from each table to compute which rows to include in output. Lots of choices make this problem hard: –What to materialize? –Which table to send? Faloutsos/PavloCMU SCS 15-415/61544

45 CMU SCS Rest of the Semester Wed Dec 2 nd – Data Warehousing + Mining Mon Dec 7 th – Guest Speaker from MemSQL Wed Dec 9 th – Final Review + Systems Faloutsos/PavloCMU SCS 15-415/61545 http://cmudb.io/f15-systems


Download ppt "CMU SCS Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos – A. Pavlo Lecture#25: Column Stores."

Similar presentations


Ads by Google