Introduction to Compilers Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY.

Slides:



Advertisements
Similar presentations
Query Optimization Goal: Declarative SQL query
Advertisements

1 Relational Query Optimization Module 5, Lecture 2.
Relational Query Optimization CS186, Fall 2005 R & G Chapters 12/15.
Cs44321 CS4432: Database Systems II Query Optimizer – Cost Based Optimization.
Relational Query Optimization CS 186, Spring 2006, Lectures16&17 R & G Chapter 15 It is safer to accept any chance that offers itself, and extemporize.
Relational Query Optimization
Query Optimization: Transformations May 29 th, 2002.
Compiler Design Lexical Analysis Syntactical Analysis Semantic Analysis Optimization Code Generation.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
CS186 Final Review Query Optimization.
Overview of Query Optimization v Plan : Tree of R.A. ops, with choice of alg for each op. –Each operator typically implemented using a `pull’ interface:
Query Optimization R&G, Chapter 15 Lecture 16. Administrivia Homework 3 available today –Written exercise; will be posted on class website –Due date:
Relational Query Optimization Implementation of single Relational Operations Choices depend on indexes, memory, stats,… Joins –Blocked nested loops: simple,
1.1 CAS CS 460/660 Introduction to Database Systems Query Optimization.
Query Optimization, part 2 CS634 Lecture 13, Mar Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Introduction to Database Systems1 Relational Query Optimization Query Processing: Topic 2.
High-Level Programming Languages: C++
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Programming Languages and Design Lecture 1 Introduction to Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern University,
Chapter 1. Introduction.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query Evaluation Chapter 12: Overview.
Relational Query Optimization Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Relational Query Optimization R & G Chapter 12/15.
Database systems/COMP4910/Melikyan1 Relational Query Optimization How are SQL queries are translated into relational algebra? How does the optimizer estimates.
Advanced Databases: Lecture 8 Query Optimization (III) 1 Query Optimization Advanced Databases By Dr. Akhtar Ali.
CSC 338: Compiler design and implementation
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Query Optimization Imperative query execution plan: Declarative SQL query Ideally: Want to find best plan. Practically: Avoid worst plans! Goal: Purchase.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
1 Database Systems ( 資料庫系統 ) December 3, 2008 Lecture #10.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Programming Languages
Introduction to Query Optimization, R. Ramakrishnan and J. Gehrke 1 Introduction to Query Optimization Chapter 13.
Relational Query Optimization R & G Chapter 12/15.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Introduction to Query Optimization Chapter 13.
1.1 CAS CS 460/660 Introduction to Database Systems Query Optimization.
Programming Languages
Introduction to Language Programming Hierarchy of programming lang. Based on machine independences: 1. Machine language 2. Assembly language 3. Higher.
Implementation of Database Systems, Jarek Gryz1 Relational Query Optimization Chapters 12.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Skill Area 311 Part B. Lecture Overview Assembly Code Assembler Format of Assembly Code Advantages Assembly Code Disadvantages Assembly Code High-Level.
Database Applications (15-415) DBMS Internals- Part VIII Lecture 19, March 29, 2016 Mohammad Hammoud.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Database Applications (15-415) DBMS Internals- Part IX Lecture 20, March 31, 2016 Mohammad Hammoud.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples.
Query Optimization. overview Application Programmer (e.g., business analyst, Data architect) Sophisticated Application Programmer (e.g., SAP admin) DBA,
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
CPS120 Introduction to Computer Science High Level Language: Paradigms.
Chapter 1. Introduction.
Concepts of Programming Languages
Why study programming languages?
PROGRAMMING LANGUAGES
课程名 编译原理 Compiling Techniques
CS222P: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Introduction to Query Optimization
Overview of Query Optimization
Introduction to Database Systems
Examples of Physical Query Plan Alternatives
Database Applications (15-415) DBMS Internals- Part IX Lecture 21, April 1, 2018 Mohammad Hammoud.
Relational Query Optimization
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
CS222: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Relational Algebra Chpt 4a Xintao Wu Raghu Ramakrishnan
Presentation transcript:

Introduction to Compilers Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY

Computers run 0/1 strings (machine language program) A machine language program that adds two numbers First 4 bits for opcode Last 12 bits for operands Source: Louden and Lambert’s book: Programming Languages

Programmers write more readable character strings An assembly language program that adds two numbers, from Louden and Lambert’s book.

Even more readable character strings: high-level languages Imperative Languages: specifies HOW  Fortran  ALGOL  PASCAL  C  C++  Java Declarative Languages: specifies WHAT  SQL, ML, Prolog

Models of Computation in Languages Underlying most programming languages is a model of computation: Procedural: Fortran (1957) Functional: Lisp (1958) Object oriented: Simula (1967) Logic: Prolog (1972) Relational algebra: SQL (1974) Source: A. V. Aho. Lectures of Programming Languages and Translators

Programming Languages Evolve: Java as an Example Java 1.0, 1996  Object-oriented  The language of choice for internet applet programs. Java 8, 2014  Changing computing background: multicore and processing big data.  Java 8 streams support database-queries style of programming  Java 8 incorporates many ideas from functional programming.

What is a compiler? A Compiler is a translator  between computers and programmers More generally speaking, a Compiler is a translator between source strings and target strings.  between assembly language and Fortran  between Java and Java Bytecode  between Java and SQL

Assembly language vs Fortran Source: Stephen A. Edwards. Lectures of Programming Languages and Translators

The Structure of a Compiler 1. Lexical Analysis 2. Syntax Analysis (or Parsing) 3. Semantic Analysis 4. Intermediate Code Generation 5. Code Optimization 6. Code Generation

Translation of an assignment statement (1)

Translation of an assignment statement (2)

Translation of SQL query SELECT S.sname FROM Reserves R, Sailors S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 Reserves Sailors sid=sid bid=100 rating > 5 sname Query can be converted to relational algebra Relational Algebra converts to tree, joins form branches Each operator has implementation choices Operators can also be applied in different order!  (sname)  (bid=100  rating > 5) (Reserves  Sailors)

Cost-based Query Sub-System Query Parser Query Optimizer Plan Generator Plan Cost Estimator Query Executor Catalog Manager Usually there is a heuristics-based rewriting step before the cost-based steps. Schema Statistics Select * From Blah B Where B.blah = blah Queries

Motivating Example Cost: *1000 I/Os By no means the worst plan! Misses several opportunities:  selections could be`pushed’ down  no use made of indexes Goal of optimization: Find faster plans that compute the same answer. SELECT S.sname FROM Reserves R, Sailors S WHERE R.sid=S.sid AND R.bid=100 AND S.rating>5 Sailors Reserves sid=sid bid=100 rating > 5 sname (Page-Oriented Nested loops) (On-the-fly) Plan:

500,500 IOs Alternative Plans – Push Selects (No Indexes) Sailors Reserves sid=sid bid=100 rating > 5 sname (Page-Oriented Nested loops) (On-the-fly) Sailors Reserves sid=sid rating > 5 sname (Page-Oriented Nested loops) (On-the-fly) bid=100 (On-the-fly) 250,500 IOs

Alternative Plans – Push Selects (No Indexes) Sailors Reserves sid=sid rating > 5 sname (Page-Oriented Nested loops) (On-the-fly) bid=100 (On-the-fly) SailorsReserves sid=sid bid = 100 sname (Page-Oriented Nested loops) (On-the-fly) rating > 5 (On-the-fly) *10 250,500 IOs 4250 IOs