cs162 discussion notes march 31, 2011 jorge ortiz
Post on 21-Dec-2015
215 views
TRANSCRIPT
![Page 1: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/1.jpg)
CS162 Discussion Notes
March 31, 2011Jorge Ortiz
![Page 2: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/2.jpg)
ACKNOWLEDGEMENTSPaul A. Strassmann, George Mason UniversityRightscale.comKirk Anne, SUNY GeneseoRandy Katz, UC Berkeley
![Page 3: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/3.jpg)
Outline
• Cloud computing– What is it?
• Virtualization– Hypervisor configurations
• Amazon EC2• Relational databases
– Entity relationship diagrams• Data models
– Imperative versus declarative• SQL
![Page 4: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/4.jpg)
What is cloud computing?
• Cloud computing is Internet-based computing, whereby shared resources, software and information are provided to computers and other devices on-demand, like electricity– Wikipedia
![Page 5: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/5.jpg)
![Page 6: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/6.jpg)
Data Centers
6
Google’sContainerizedDatacenter
MicrosoftChicagoDatacenter
![Page 7: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/7.jpg)
What runs on these machines?
• All types of applications!• How can we make best
use of the resources?
![Page 8: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/8.jpg)
Virtualization (2)
![Page 9: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/9.jpg)
Virtualization (3)
![Page 10: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/10.jpg)
Amazon EC2 Architecture
![Page 11: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/11.jpg)
Applications
• Web applications• Databases• Compute-intensive jobs• Client-Server applications
– Project 3!• Chat Server will be in the cloud• Clients will be outside the cloud• Application state stored in database
![Page 12: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/12.jpg)
Parts of a database
Record
Attribute/Field
Tables
• Records become “rows”• Attributes/fields become “columns”• Rules determine the relationship between the tables and tie the data together to form a database
![Page 13: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/13.jpg)
Basic SQL Commands
• Creating tables with CREATE• Adding data with INSERT• Viewing data with SELECT• Removing data with DELETE• Modifying data with UPDATE• Destroying tables with DROP
![Page 14: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/14.jpg)
Creating tables with CREATE
• Generic form
CREATE TABLE tablename (column_name data_type attributes…,column_name data_type attributes…,…
)
• Table and column names can’t have spaces or be “reserved words” like TABLE, CREATE, etc.
![Page 15: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/15.jpg)
Phone Book/Contact TableCREATE TABLE contacts (
Name VARCHAR(40),Address VARCHAR(60),Company VARCHAR(60),Phone VARCHAR(11),URL VARCHAR(80),Age INT,Height FLOAT,Birthday DATE,WhenEntered TIMESTAMP
);Plan your tables very carefully!
Once created, they are difficult to change!
![Page 16: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/16.jpg)
Data Types
• Binary– Database specific binary objects (BLOB)
• Boolean– True/False values (BOOLEAN)
• Character– Fixed width (CHAR) or variable size (VARCHAR)
• Numeric– Integer (INT), Real (FLOAT), Money (MONEY)
• Temporal– Time (TIME), Date (DATE), Timestamp (TIMESTAMP)
![Page 17: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/17.jpg)
Adding data with INSERT
• Generic Form
INSERT INTO tablename (column_name,…)VALUES (value,…)
![Page 18: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/18.jpg)
Inserting a record into ‘contacts’
INSERT INTO contacts (contactid,name,address,company,phone,url,age,height,birthday,whenentered)
VALUES(1,‘Joe’,’123 Any St.’,’ABC’,’800-555-1212’,‘http://abc.com’,30,1.9,’6/14/1972’,now());
![Page 19: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/19.jpg)
Inserting a partial record
INSERT INTO contacts (contactid,name,phone)VALUES (2,’Jane’,’212-555-1212’);
![Page 20: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/20.jpg)
Automatic key generation
• CREATE SEQUENCE contactidseq;• Change the ContactID line in the
CREATE TABLE to:ContactIDINT DEFAULT nextval(‘contactidseq’) PRIMARY KEY
• Or when inserting into a tableINSERT contacts (contactid,name,phone)VALUES (nextval(‘contactidseq’),’Jack’,
‘716-555-1212’);
![Page 21: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/21.jpg)
Viewing data with SELECT
• Generic FormSELECT column,… FROM table,…
WHERE condition GROUP BY group_by_expressionHAVING condition ORDER BY order_expression
• The most used command• Probably the most complicated also• If used improperly, can cause very long waits because
complex computations
![Page 22: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/22.jpg)
A few simple SELECTs
• SELECT * FROM contacts;– Display all records in the ‘contacts’ table
• SELECT contactid,name FROM contacts;– Display only the record number and names
• SELECT DISTINCT url FROM contacts;– Display only one entry for every value of URL.
![Page 23: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/23.jpg)
Refining selections with WHERE
• The WHERE “subclause” allows you to select records based on a condition.
• SELECT * FROM contactsWHERE age<10;
– Display records from contacts where age<10• SELECT * FROM contacts
WHERE age BETWEEN 18 AND 35;– Display records where age is 18-35
![Page 24: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/24.jpg)
Additional selections
• The “LIKE” condition– Allows you to look at strings that are alike
• SELECT * FROM contactsWHERE name LIKE ‘J%’;
– Display records where the name starts with ‘J’• SELECT * FROM contacts
WHERE url LIKE ‘%.com’;– Display records where url ends in “.com”
![Page 25: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/25.jpg)
Removing data with DELETE
• Generic Form
DELETE FROM table WHERE condition;
DELETE FROM contacts WHERE age<13;
![Page 26: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/26.jpg)
Modifying data with UPDATE
• Generic Form
UPDATE table SET column=expression WHERE condition;
UPDATE contacts SET company=‘AOL’
WHERE company=‘Time Warner’;
![Page 27: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/27.jpg)
Destroying tables with DROP
• Generic Form
DROP TABLE tablename;
DROP TABLE contacts;
![Page 28: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/28.jpg)
Joining together tables• SELECT name,phone,zip FROM people,
phonenumbers, address WHERE people.addressid=address.addressid AND people.id=phonenumbers.id;
People
Id Name AddressID
1 Joe 1
2 Jane 2
3 Chris 3
Address
AddressID Company Address Zip
1 ABC 123 12345
2 XYZ 456 14454
3 PDQ 789 14423
PhoneNumbers
PhoneID Id Phone
1 1 5532
2 1 2234
3 1 3211
4 2 3421
5 3 2341
6 3 6655
![Page 29: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/29.jpg)
GROUP BY/HAVING
• The “GROUP BY” clause allows you to group results together with “aggregate functions”– AVG(), COUNT(), MAX(), MIN(), SUM()– COUNT DISTINCT
• HAVING allows you to search the GROUP BY results
![Page 30: CS162 Discussion Notes March 31, 2011 Jorge Ortiz](https://reader035.vdocuments.site/reader035/viewer/2022062714/56649d635503460f94a46315/html5/thumbnails/30.jpg)
Important links
• http://aws.amazon.com/documentation/ec2/• http://www.mysql.com/