Hacking PostgreSQL Internals to Solve Data Access Problems

Similar documents
Apache HAWQ (incubating)

BigInsights and Cognos Stefan Hubertus, Principal Solution Specialist Cognos Wilfried Hoge, IT Architect Big Data IBM Corporation

April Copyright 2013 Cloudera Inc. All rights reserved.

Big Data Technology Ecosystem. Mark Burnette Pentaho Director Sales Engineering, Hitachi Vantara

How Apache Hadoop Complements Existing BI Systems. Dr. Amr Awadallah Founder, CTO Cloudera,

SQL in the Hybrid World

Big Data com Hadoop. VIII Sessão - SQL Bahia. Impala, Hive e Spark. Diógenes Pires 03/03/2018

Lecture 7 (03/12, 03/14): Hive and Impala Decisions, Operations & Information Technologies Robert H. Smith School of Business Spring, 2018

WHITEPAPER. MemSQL Enterprise Feature List

Shen PingCAP 2017

Big Data with Hadoop Ecosystem

Apache Hive for Oracle DBAs. Luís Marques

Managing PostgreSQL on Windows

Hadoop 2.x Core: YARN, Tez, and Spark. Hortonworks Inc All Rights Reserved

Microsoft Big Data and Hadoop

Evolution of Big Data Facebook. Architecture Summit, Shenzhen, August 2012 Ashish Thusoo

VOLTDB + HP VERTICA. page

Accelerate MySQL for Demanding OLAP and OLTP Use Cases with Apache Ignite. Peter Zaitsev, Denis Magda Santa Clara, California April 25th, 2017

We are ready to serve Latest Testing Trends, Are you ready to learn?? New Batches Info

Asanka Padmakumara. ETL 2.0: Data Engineering with Azure Databricks

DATA SCIENCE USING SPARK: AN INTRODUCTION

How do we build TiDB. a Distributed, Consistent, Scalable, SQL Database

MODERN BIG DATA DESIGN PATTERNS CASE DRIVEN DESINGS

Hadoop Beyond Batch: Real-time Workloads, SQL-on- Hadoop, and thevirtual EDW Headline Goes Here

Overview. Prerequisites. Course Outline. Course Outline :: Apache Spark Development::

Big Data. Big Data Analyst. Big Data Engineer. Big Data Architect

Hive and Shark. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

BIS Database Management Systems.

Big Data Analytics using Apache Hadoop and Spark with Scala

Tungsten Replicator for Kafka, Elasticsearch, Cassandra

Big Data Infrastructure at Spotify

Apache Ignite TM - In- Memory Data Fabric Fast Data Meets Open Source

This is a brief tutorial that explains how to make use of Sqoop in Hadoop ecosystem.

CERTIFICATE IN SOFTWARE DEVELOPMENT LIFE CYCLE IN BIG DATA AND BUSINESS INTELLIGENCE (SDLC-BD & BI)

Bring Context To Your Machine Data With Hadoop, RDBMS & Splunk

Unifying Big Data Workloads in Apache Spark

Progress DataDirect For Business Intelligence And Analytics Vendors

Data pipelines with PostgreSQL & Kafka

Shark: SQL and Rich Analytics at Scale. Michael Xueyuan Han Ronny Hajoon Ko

Top 7 Data API Headaches (and How to Handle Them) Jeff Reser Data Connectivity & Integration Progress Software

MIS Database Systems.

Gain Insights From Unstructured Data Using Pivotal HD. Copyright 2013 EMC Corporation. All rights reserved.

Importing and Exporting Data Between Hadoop and MySQL

Data Lake Based Systems that Work

HAWQ: A Massively Parallel Processing SQL Engine in Hadoop

Big Data Hadoop Course Content

Blended Learning Outline: Developer Training for Apache Spark and Hadoop (180404a)

The Future of Postgres Sharding

Impala. A Modern, Open Source SQL Engine for Hadoop. Yogesh Chockalingam

Data Storage Infrastructure at Facebook

Major Features: Postgres 10

1 Big Data Hadoop. 1. Introduction About this Course About Big Data Course Logistics Introductions

SQL Azure. Abhay Parekh Microsoft Corporation

Jargons, Concepts, Scope and Systems. Key Value Stores, Document Stores, Extensible Record Stores. Overview of different scalable relational systems

Introduction. Performance

Topics. Big Data Analytics What is and Why Hadoop? Comparison to other technologies Hadoop architecture Hadoop ecosystem Hadoop usage examples

Apache Ignite and Apache Spark Where Fast Data Meets the IoT

Security and Performance advances with Oracle Big Data SQL

Stages of Data Processing

PostgreSQL Built-in Sharding:

Columnstore Technology Improvements in SQL Server Presented by Niko Neugebauer Moderated by Nagaraj Venkatesan

Cloud Computing & Visualization

Stream Processing Platforms Storm, Spark,.. Batch Processing Platforms MapReduce, SparkSQL, BigQuery, Hive, Cypher,...

Stream Processing Platforms Storm, Spark,.. Batch Processing Platforms MapReduce, SparkSQL, BigQuery, Hive, Cypher,...

WHY AND HOW TO LEVERAGE THE POWER AND SIMPLICITY OF SQL ON APACHE FLINK - FABIAN HUESKE, SOFTWARE ENGINEER

Migrating Oracle Databases To Cassandra

Cloud Computing 3. CSCI 4850/5850 High-Performance Computing Spring 2018

MariaDB MaxScale 2.0 and ColumnStore 1.0 for the Boston MySQL Meetup Group Jon Day, Solution Architect - MariaDB

Part 1: Indexes for Big Data

sqoop Easy, parallel database import/export Aaron Kimball Cloudera Inc. June 8, 2010

Trafodion Enterprise-Class Transactional SQL-on-HBase

Postgres-XC PG session #3. Michael PAQUIER Paris, 2012/02/02

Apache Spark 2.0. Matei

CSE 444: Database Internals. Lecture 23 Spark

The Hadoop Ecosystem. EECS 4415 Big Data Systems. Tilemachos Pechlivanoglou

Oracle NoSQL Database Enterprise Edition, Version 18.1

Towards a Real- time Processing Pipeline: Running Apache Flink on AWS

Best Practices and Performance Tuning on Amazon Elastic MapReduce

Cloudera Impala Headline Goes Here

Big Data Facebook

Lambda Architecture for Batch and Real- Time Processing on AWS with Spark Streaming and Spark SQL. May 2015

HadoopDB: An Architectural Hybrid of MapReduce and DBMS Technologies for Analytical Workloads

Turning Relational Database Tables into Spark Data Sources

Databricks, an Introduction

Interactive SQL-on-Hadoop from Impala to Hive/Tez to Spark SQL to JethroData

Accessing other data fdw, dblink, pglogical, plproxy,...

Oracle Big Data SQL. Release 3.2. Rich SQL Processing on All Data

Introduction to Hadoop. High Availability Scaling Advantages and Challenges. Introduction to Big Data

Big Data Architect.

The Gearman Cookbook OSCON Eric Day Senior Software Rackspace

Apache Hive 3: A new horizon

Integration of Apache Hive

Data Analytics at Logitech Snowflake + Tableau = #Winning

Innovatus Technologies

Database Assessment for PDMS

Tableau Server - 101

HDInsight > Hadoop. October 12, 2017

CISC 7610 Lecture 2b The beginnings of NoSQL

From Single Purpose to Multi Purpose Data Lakes. Thomas Niewel Technical Sales Director DACH Denodo Technologies March, 2019

The Future of Real-Time in Spark

Transcription:

Hacking PostgreSQL Internals to Solve Data Access Problems Sadayuki Furuhashi Treasure Data, Inc. Founder & Software Architect

A little about me... > Sadayuki Furuhashi > github/twitter: @frsyuki > Treasure Data, Inc. > Founder & Software Architect > Open source hacker

Open source Fluentd - Unifid log collection infrastracture Embulk - Plugin-based parallel ETL MessagePack - Schemaless serialization format

End-to-end data analytics pipeline on the cloud.

Motivation of Prestogres > I want to build an open-source ODBC connectivity directly to a big data analytics infrastracture. HDFS Daily/Hourly Batch Interactive query PostgreSQL, etc. Hive Dashboard

HDFS Daily/Hourly Batch Interactive query PostgreSQL, etc. Hive Dashboard Commercial BI Tools Batch analysis platform Visualization platform

HDFS Daily/Hourly Batch Interactive query PostgreSQL, etc. Hive Dashboard Scalable to PBs of data But too slow for interactive queries Can t query against live data directly Commercial BI Tools Batch analysis platform Visualization platform Extra work to manage 2 systems

HDFS Daily/Hourly Batch Interactive query PostgreSQL, etc. Hive Dashboard HDFS Daily/Hourly Batch Hive Presto Direct interactive query!! Dashboard Unified data analysis platform

HDFS Daily/Hourly Batch Interactive query Hive Presto Dashboard SQL on any data sets Cassandra PostgreSQL Kafka, etc. Unified data analysis platform

HDFS Daily/Hourly Batch Interactive query Hive Presto Dashboard SQL on any data sets ODBC Commercial BI Tools IBM Cognos Tableau... Cassandra PostgreSQL Kafka, etc. Unified data analysis platform

HDFS Daily/Hourly Batch Interactive query Hive Presto Dashboard SQL on any data sets Prestogres Commercial BI Tools IBM Cognos Tableau... Cassandra PostgreSQL Kafka, etc. Unified data analysis platform

Interactive query HDFS Dashboard Presto Prestogres Commercial BI Tools IBM Cognos Tableau... Today s topic

Q. Why do you choose Presto over other databases?

1. Why Presto? - Presto s architecture

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin Worker

Discovery Service 1. find servers in a cluster Worker Storage / Metadata Client Coordinator Worker Connector Plugin Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin 2. Client sends a query using HTTP Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin 3. Coordinator builds a query plan Connector plugin provides metadata (table schema, etc.) Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin 4. Coordinator sends tasks to workers Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin Worker 5. Workers read data through connector plugin

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin 6. Workers run tasks in memory Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin 7. Client gets the result from a worker Worker

Discovery Service Worker Storage / Metadata Client Coordinator Worker Connector Plugin Worker

What s Connectors? > Connectors are plugins of Presto > Connectors provide metadata and data to Presto > provide table schema to coordinators > provide table rows to workers > Implementations: > Hive connector > Cassandra connector > JDBC connector (scans from RDBMS) > Kafka connector, etc.

Multiple connectors in a query find servers in a cluster Discovery Service HDFS / Metastore Worker Hive Connector Client Coordinator Worker JDBC Connector PostgreSQL Worker other connectors... Other data sources...

Postgres-XL vs. Presto Postgres-XL Presto coordinator worker coordinator worker worker Doesn't support transactions worker worker worker worker worker Transaction Manager Data is stored on workers Supports ACID with MVCC worker storage worker storage Data is stored on separated storage systems

Q. Why do you choose Presto over other databases? > A. Because Presto is elastic. > Computation performance is isolated from storage management. Adding a server improves performance instantly. (No data re-distribution when we add a server) Removing server is also done instantly. > That's good for cloud-based infrastracture. Scale performance when we need. JOIN across multiple data sources (RDB, S3, etc.) without moving big data. Distributed IO on distributed storage aggr join scan aggr aggr join scan

Hadoop MapReduce vs. Presto MapReduce Presto reduce reduce task All stages are pipe-lined No wait time No fault-tolerance map disk map Wait between stages task task reduce map disk disk reduce map Write data to disk task task task task memory-to-memory data transfer No disk IO Data chunk must fit in memory

Today s talk 0. Overview of Presto & data analytics platform 1. Why Presto? - Presto's architecture 2. Prestogres design 3. Prestogres implementation 4. Prestogres hacks 5. Presto internals

2. Prestogres design PostgreSQL protocol gateway

The problems to solve > BI tools need ODBC or JDBC connectivity. > Tableau, IBM Cognos, QlickView, Chart.IO,... > JasperSoft, Pentaho, MotionBoard,... > ODBC/JDBC is VERY COMPLICATED. psqlodbc: 58,000 lines postgresql-jdbc: 62,000 lines mysql-connctor-odbc: 27,000 lines mysql-connector-j: 101,000 lines > Open-source implementation will take long time.

A solution > Creates a PostgreSQL protocol gateway server > Reuses PostgreSQL s stable ODBC / JDBC driver

dashboard on chart.io: https://chartio.com/

Other possible designs were a) MySQL protocol + libdrizzle: > Drizzle includes a well-designed library to implement MySQL protocol server. > Proof-of-concept worked well: trd-gateway - MySQL protocol gateway server for "Hive" > Difficulties: clients assumes the server is MySQL but, syntax is not ANSI standard: MySQL uses ` `, while Presto uses function mismatches: DAYOFMONTH( ) vs EXTRACT(day )

Other possible designs were b) PostgreSQL + Foreign Data Wrapper (FDW): > JOIN and aggregation pushdown is not available (yet?)

Difficulties to implement PG protocol > Emulating system catalogs > pg_class, pg_namespace, pg_proc, > Rewriting transactions (BEGIN, COMMIT) > Presto doesn t support transactions

Prestogres design pgpool-ii + PostgreSQL + PL/Python > pgpool-ii is a PostgreSQL protocol middleware for replication, failover, load-balancing, etc. > pgpool-ii already implements useful utility functions (parsing SQL, rewriting SQL, hacking system catalogs, ) > Basic idea: Rewrite queries at pgpool-ii and run Presto queries using PL/Python select count(*) from access rewrite! select * from python_func( select count(*) from access )

3. Prestogres implementation

Overview 1. Authentication psql odbc pgpool-ii Patched! PostgreSQL Presto jdbc 2. 3. Rewriting queries Executing queries using PL/Python

Overview Prestogres 1. Authentication psql odbc pgpool-ii Patched! PostgreSQL Presto jdbc 2. 3. Rewriting queries Executing queries using PL/Python

Connection $ psql -U me mydb psql pgpool-ii PostgreSQL Presto StartupPacket { } database = mydb, user = me,

Connection $ psql -U me mydb prestogres_hba.conf host mydb me 0.0.0.0/0 trust presto_server presto.local:8080, presto_catalog hive, pg_database hive psql pgpool-ii PostgreSQL Presto StartupPacket { } database = mydb, user = me,

Connection $ psql -U me mydb prestogres_hba.conf host mydb me 0.0.0.0/0 trust presto_server presto.local:8080, presto_catalog hive, pg_database hive psql pgpool-ii PostgreSQL Presto StartupPacket { } database = mydb, user = me, libpq host= localhost, dbname= postgres, user= prestogres > CREATE DATABASE hive; > CREATE ROLE me; > CREATE FUNCTION setup_system_catalog; > CREATE FUNCTION start_presto_query;

Connection $ psql -U me mydb prestogres_hba.conf host mydb me 0.0.0.0/0 trust presto_server presto.local:8080, presto_catalog hive, pg_database hive psql pgpool-ii PostgreSQL Presto StartupPacket { } database = mydb, user = me, StartupPacket { } database = hive, user = me, uses the database and user which were created right now!

Meta-query "Query against a system catalog! $ psql -U me mydb psql pgpool-ii PostgreSQL Presto Q SELECT * FROM pg_class; system catalog!

Meta-query "Query against a system catalog! $ psql -U me mydb SELECT * FROM information_schema.columns psql pgpool-ii PostgreSQL Presto Q SELECT * FROM pg_class; SELECT setup_system_catalog( presto.local:8080, hive ) system catalog! PL/Python function defined at prestogres.py

Meta-query "Query against a system catalog! $ psql -U me mydb SELECT * FROM information_schema.columns psql pgpool-ii PostgreSQL Presto Q SELECT * FROM pg_class; SELECT setup_system_catalog( presto.local:8080, hive ) > CREATE TABLE access_logs; > CREATE TABLE users; > CREATE TABLE events;

Meta-query "Query against a system catalog! $ psql -U me mydb psql pgpool-ii PostgreSQL Presto Q SELECT * FROM pg_class; Q SELECT * FROM pg_class; reads the records which were generated right now!

Presto Query "Query against a regular table! $ psql -U me mydb psql pgpool-ii PostgreSQL Presto Q select count(*) from access_logs; regular table!

Presto Query "Query against a regular table! 1. start the query on Presto $ psql -U me mydb psql pgpool-ii PostgreSQL Presto libpq Q select count(*) from access_logs; SELECT start_presto_query( select count(*) from access_logs ) regular table! PL/Python function defined at prestogres.py

Presto Query "Query against a regular table! 1. start the query on Presto $ psql -U me mydb 2. define fetch_results() psql pgpool-ii PostgreSQL Presto libpq Q select count(*) from access_logs; regular table! CREATE TYPE result_type (c0_ BIGINT); CREATE FUNCTION fetch_results RETURNS SETOF result_type AS $$ return prestogres.fetch_presto_query_results() $$ language plpythonu;

Presto Query "Query against a regular table! $ psql -U me mydb 3. calls fetch_results() psql pgpool-ii PostgreSQL Presto Q select count(*) from access_logs; Q SELECT * FROM fetch_results(); defined by start_presto_query that returns SETOF result_type type of query results defined by start_presto_query

Examples > select * from pg_class > In another connection, pgpool-ii runs setup_system_catalog() > Then forwards query: select * from pg_class > select count(*) from access > In another connection, pgpool-ii runs start_presto_query( select count(*) from access, ) > Then forwards query: select * from fetch_query_result() > BEGIN > Forwards query: BEGIN (no rewrite)

Demo

4. Prestogres hacks

Multi-statement queries > BEGIN; select count(*) from access; COMMIT > Parse query in pgpool-ii > In anothe connection, call start_presto_query( select ) > Rewrite query partially: BEGIN; select * from fetch_query_result(); COMMIT > select count(*) from access; select count(*) from access > not supported :(

Supporting Cursors > DECLARE CURSOR xyz FOR select ; FETCH > Parse query in pgpool-ii > In anothe connection, call start_presto_query( select ) > Rewrite query partially: DECLARE CURSOR xyz FOR select * from fetch_query_result(); FETCH

Error handling > select xyz(*) from abc > do $$ RAISE EXCEPTION %, Function xyz is not defined USING errcode='42601' $$ end language plpgsql

Faked current_database() DELETE FROM pg_catalog.pg_proc WHERE proname= current_database ; CREATE FUNCTION pg_catalog.current_database() RETURNS name AS $$ begin return faked_name ::name; end $$ language plpgsql stable strict;

5. Future works

Future works Rewriting CAST syntax Extended query CREATE TEMP TABLE

Thank you! https://github.com/treasure-data/prestogres licensed under Apache License. Sadayuki Furuhashi Treasure Data, Inc. Founder & Software Architect