34
Postgres Stories PostgreSQL 数据库及相关设计讨论 ——刘鑫<[email protected]>

Postgre sql intro 0

Embed Size (px)

DESCRIPTION

a slide for psotgresql

Citation preview

Page 1: Postgre sql intro 0

Postgres Stories

PostgreSQL 数据库及相关设计讨论

——刘鑫<[email protected]>

Page 2: Postgre sql intro 0

Postgres WWH

PostgreSQL ?What?

RDBMSOpenSourceRich Power

Why?How?

Page 3: Postgre sql intro 0

What is Postgres?

PostgreSQL 是一款开放源码的关系型数据库

BSD授权有广泛的平台实现

一款久经考验的数据库产品美国军方医疗行业地理信息系统

…… 具有实用面向对象特征的ORDB

 强大的服务器端编程能力完备的数据库功能

Page 4: Postgre sql intro 0

Why Postgres?

PostgreSQL 有力的支持各种数据库设计丰富实用的数据模型自然优雅的程序逻辑丰富强大的服务器端编程支持适用各种架构需求

丰富便利的运维技术支持冷备热备负载匀衡统计分析工具

 ……

Page 5: Postgre sql intro 0

Why Postgres?

强大的并发性能

http://www.blowfisher.net/gallery/v/pg-vs-mysql/丰富的安全模型

buildintrustedby addrby ldapssl...

Page 6: Postgre sql intro 0

Postgres 丰富的数据类型

强大的文本处理能力 独特的无限文本类型 Text正则表达式!完备的 XML 功能支持

Numeric 满足严谨的商务应用需求满足各种特殊应用需求的数据类型

久负盛誉的几何类型

 ltree字典类型 hstore

bits全文索引...

Page 7: Postgre sql intro 0

Postgres 实用的ORDB模型

不仅是RDB完备的RDB模型支持 继承行集<=>向量集

 自然的OO概念智能的静态类型推导函数支持Table类型

 完备的约束定义能力主键与唯一约束自增字段与UUIDDefault and check触发器

Page 8: Postgre sql intro 0

Postgres 强大的编程能力

SQLWindow语法及数据挖掘

Iimit ... offset ......

PLPGSQL完备的过程控制语法参数化SQL命令自然的存储访问集成(游标)

return next 和 return query

 PLPerl/PLPython/PLTCL/PLJAVA/PLxxx...无限可能的语言扩展!

Page 9: Postgre sql intro 0

How Postgres? -- Just Do It!

安装Linux

 cluster on debian/ubuntuBSD Port Windows Binary

Make It Yourself?基于标准c有详细的编译指导对“新”手,可能比安装更好用……囧……

Page 10: Postgre sql intro 0

How Postgres? -- Just Do It!

The First Daysudo su postgresinitdbcreate superuser

理解存储结构

Linux Cluster数据区与实例

理解安全体系用户认证方式网络监听企业级认证方式

Page 11: Postgre sql intro 0

How Postgres? -- Just Do It!

实操

psql postgres命令行客户端

丰富的命令和功能支持工具命令

GUI界面

PGAdminIIIPHPPgAdmin Emacs!

客户端驱动

JDBC/ADO.netpsycopg2/DBD::Pgruby/php...

Page 12: Postgre sql intro 0

Postgres Story -- 树状结构访问

程序逻辑实现

return nextreturn query

数据结构实现

ltree

Page 13: Postgre sql intro 0

Postgres Story -- 位映射

问题背景布隆过滤器基因工程及生物科学研究其它数据压缩与加密场景...

实现两个字段?

两个字段!简单的基本运算演示

统计覆盖

bits 介绍技术特色运算支持

Page 14: Postgre sql intro 0

Postgres Story -- 最近访问用户

问题背景背景介绍与 memcache 实现的比较

实现经典的触发器应用性能与性价比分析维护建议

Page 15: Postgre sql intro 0

Postgres Story --不规则数据集

问题背景背景介绍与继承实现的比较与Domino实现的比较 与 couchDB 实现的比较与KV数据库实现的比较

Page 16: Postgre sql intro 0

Postgres Story --不规则数据集

实现经典的 XML 应用(pgxml)

函数(xpath_xxx)函数索引实践性能与性价比分析维护建议

语义模型化列为行以空间换功能需要应用层组件支持

Page 17: Postgre sql intro 0

Postgres Story --全文搜索引擎

问题背景背景介绍与 Lucene 实现的比较与 Xapian 实现的比较

实现

Tsearch2引引擎基本运算 方便的扩展接口

中文语言分析引擎nlpbamboo中文分词技术的引入待发挥的潜能

实践

Page 18: Postgre sql intro 0

Postgres Story --全文搜索引擎

TSearch2vector

to_tsvectorquery 

to_tsquery@@

vector @@ querysetweight(tsvector, char)rank

get and setrank_cd

cover density rankinggin index

Page 19: Postgre sql intro 0

Postgres Story --全文搜索引擎

nlpbamboo符合 TSearch2 接口chinesecfgto_tsvector('chinesecfg', text)plainto_tsquery('chinesecfg', text)

Page 20: Postgre sql intro 0

Postgres Story --全文搜索引擎

create table pageuuid/idcontent full text index

create table tmplateuuid/iduritemplate

Page 21: Postgre sql intro 0

Postgres Story --全文搜索引擎

content 使用 XML 方案可以方便的使用XPATH支持进行查询可以使用XSLT定制输出允许对多种不同格式兼容存储,以利于未来的数据挖掘需要固定的格式:

/*/@source/*/@tmpl/*/@type/*/content

template 保存XSLTtemplate 表以 uri 为键

Page 22: Postgre sql intro 0

Postgres Story --语义模型

问题背景背景介绍传统关系模型的优缺点三元语义模型

实现三元语义关系表——subject/predicate/object值存储与查询关联查询问题

ORM——SQLAlchemy

Page 23: Postgre sql intro 0

Postgres Story --语义模型

问题分析动态数据类型问题

多表串联

 动态类型的应用层支持

DSL支持思路

SQLAlchemysubject = (subject predicate object) : subjects semantic query languageDynamic Type Object Model

Page 24: Postgre sql intro 0

Postgres Story --语义模型

架构subject is subjectpredicate is subjectpredicate has objTypepredicate has name (name just it's word)is is predicateis objType subjectobjType is subjectobjType name objTypehas is predicatehas objType predicatename is predicate

Page 25: Postgre sql intro 0

Postgres Story --语义模型

架构name objType texttext is typeset is predicateset objType subjectlist is predicatelist objType subject……

Page 26: Postgre sql intro 0

Postgres Story --语义模型

数据库层

create table subjectid serialsubject integer foreign key references subject(id)predicate integer foreign key references subject(id)object integer foreign key references subject(id)

create table text id serialsubject integer foreign key references subject(id) predicate integer foreign key references subject(id)object text

other type table ...

Page 27: Postgre sql intro 0

Postgres Story --语义模型

查询:

subs : select * from subject where ...select * from text where subject in subs.subjectselect * from "other regist type" where ...

分析与数据相比,基础类型总是有限的整数据列索引后性能很好需要动态类型的应用层查询工具支持

Page 28: Postgre sql intro 0

Postgres Story --语义模型

QL设计:

subject predicate objectobject = subject predicate

object predicate subjectobject `predicate ` subject

get subject filter predicate match some conditionget subject (p0,  p1, ...) filter ...

put/insert/update (subject predicate object)update subject (predicate object)s filter ..."no DML!"

Page 29: Postgre sql intro 0

Postgres Story --语义模型

查询语言的设计分析:需要感知注册的存储类型表 自省类型能力一些基础谓词需要应用层解释

objType/typeis...

应该定义一些内置容器类型

setlistdict...

应该支持惰性计算

Page 30: Postgre sql intro 0

Postgres Story --语义模型

查询语言的设计分析:

subject is a set of (predicate, object)subject maybe anonymous

subject_idpredicate_id (predicate 一定有 name)

objectprocess(predicate -> object)  could concurrent

object -> message -> argumentobject -> method -> parameter

every thing is triple(subject predicate object)

Page 31: Postgre sql intro 0

Postgres Story --语义模型

语义模型的存储无关性不需要深度的服务器编程能力基本内核只需要整型和字符串支持应用层可以使用多种编程语言

可以是动态类型,有自省能力的语言可以是有反射能力的静态语言(C#/Java)可以是有类型推导能力的静态语言(haskell)可以是支持“void *”的语言(C)

应该可以支持 sqlite 级别的数据库引擎应支持具体平台的扩展定制(主要是类型增进)

Page 32: Postgre sql intro 0

Postgres Story --语义模型

目前需要增进的方面部分元语义定义不清

type and collectionspredicate how do...

subject 提取方式

Query LanguageparserAPI

Page 33: Postgre sql intro 0

Postgres Story --总结

 PostgreSQL First Day 特色功能

 服务器编程能力——最近访问用户/树状表递归

 特殊数据类型——位映射

 全文检索支持——tsearch2与nlpbamboo的组合

 基于XML的动态数据结构

 语义模型

Page 34: Postgre sql intro 0

Postgres Story 

by : 刘鑫(March Liu)

site : http://zerolab.co.ccemail : [email protected] : 珠海金山软件