59. lo ¶
59.1. 插件lo简介 ¶
在使用大对象(BLOB)数据时,JDBC/ODBC等标准接口假设BLOB数据直接存储在对应表中,所以在数据被修改或删除时旧的BLOB数据也会被删除。 而在KingbaseES中,使用lo方式存储的大对象数据是独立的对象,有独立的存储。表中的数据行通过OID引用lo数据,并且支持多行数据引用同一个lo数据,所以在行数据删除时系统并不会自动删除lo数据。所以在使用标准JDBC/ODBC接口时lo数据并不会被自动删除,导致遗留了没有引用的“孤儿”lo数据。
lo插件提供了触发器在引用了lo数据的行被修改或删除时自动调用lo_unlink,同时提供了包装oid domain的lo数据类型。注意lo触发器不一定要在用lo数据类型的情况下才可以使用,lo数据类型只是用来方便跟踪系统中使用lo触发器管理的lo数据。
-
插件名为 lo
-
插件版本 V1.1
59.2. 插件lo加载方式 ¶
CREATE EXTENSION lo;
59.3. 插件lo的参数配置 ¶
无需配置任何参数。
59.4. 插件lo的使用方法 ¶
CREATE TABLE image (title text, raster lo); CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE on image FOR EACH ROW EXECUTE FUNCTION lo_manage(raster);
lo触发器在DROP TABLE或TRUNCATE TABLE时不会生效;有些应用会自动创建和管理表,这种情况下触发器也不会被创建。在以上这些情况下还是可能产生“孤儿”lo。定期运行vacuumlo可以帮助处理这些lo对象。
59.5. 插件lo卸载方法 ¶
DROP EXTENSION lo;
59.6. 插件lo升级方法 ¶
通过 ALTER EXTENSION升级插件。
示例,升级到 1.1:
ALTER EXTENSION lo UPDATE TO '1.1';
60. ltree ¶
60.1. 插件ltree简介: ¶
插件ltree是包含ltree和lquery类型的实现,为树状结构组织的数据提供索引和查询。
-
插件名为 ltree
-
插件版本 v1.1
60.2. 插件ltree加载方式 ¶
使用时需要在命令行执行create extension ltree;
示例:
create extension ltree;
60.3. 插件ltree的参数配置 ¶
无需配置任何参数。
60.4. 插件ltree的使用方法 ¶
加载插件ltree后,按照如下方式使用相应功能
60.4.1. ltree类型 ¶
支持ltree类型
示例:
select ''::ltree; ltree ------- (1 row) select '1'::ltree; ltree ------- 1 (1 row) select '1.2'::ltree; ltree ------- 1.2 (1 row) select '1.2._3'::ltree; ltree -------- 1.2._3 (1 row)
60.4.2. lquery类型 ¶
支持lquery类型,用于匹配ltree值的类似正则表达式的模式。
示例:
select '1'::lquery; lquery -------- 1 (1 row) select '4|3|2'::lquery; lquery -------- 4|3|2 (1 row) select '1.2'::lquery; lquery -------- 1.2 (1 row) select '1.4|3|2'::lquery; lquery --------- 1.4|3|2 (1 row) select '1.0'::lquery; lquery -------- 1.0 (1 row) select '4|3|2.0'::lquery; lquery --------- 4|3|2.0 (1 row) select '1.2.0'::lquery; lquery -------- 1.2.0 (1 row) select '1.4|3|2.0'::lquery; lquery ----------- 1.4|3|2.0 (1 row) select '1.*'::lquery; lquery -------- 1.* (1 row) select '4|3|2.*'::lquery; lquery --------- 4|3|2.* (1 row) select '1.2.*'::lquery; lquery -------- 1.2.* (1 row) select '1.4|3|2.*'::lquery; lquery ----------- 1.4|3|2.* (1 row) select '*.1.*'::lquery; lquery -------- *.1.* (1 row) select '*.4|3|2.*'::lquery; lquery ----------- *.4|3|2.* (1 row) select '*.1.2.*'::lquery; lquery --------- *.1.2.* (1 row) select '*.1.4|3|2.*'::lquery; lquery ------------- *.1.4|3|2.* (1 row) select '1.*.4|3|2'::lquery; lquery ----------- 1.*.4|3|2 (1 row) select '1.*.4|3|2.0'::lquery; lquery ------------- 1.*.4|3|2.0 (1 row) select '1.*.4|3|2.*{1,4}'::lquery; lquery ------------------ 1.*.4|3|2.*{1,4} (1 row) select '1.*.4|3|2.*{,4}'::lquery; lquery ----------------- 1.*.4|3|2.*{,4} (1 row) select '1.*.4|3|2.*{1,}'::lquery; lquery ----------------- 1.*.4|3|2.*{1,} (1 row) select '1.*.4|3|2.*{1}'::lquery; lquery ---------------- 1.*.4|3|2.*{1} (1 row) select 'qwerty%@*.tu'::lquery; lquery -------------- qwerty%@*.tu (1 row)
60.4.3. ltree2text(ltree) ¶
ltree类型转换为text类型。
示例:
select ltree2text('1.2.3.34.sdf'); ltree2text -------------- 1.2.3.34.sdf (1 row)
60.4.4. text2ltree(text) ¶
text类型转换为ltree类型。
示例:
select text2ltree('1.2.3.34.sdf'); text2ltree -------------- 1.2.3.34.sdf (1 row)
60.4.5. subltree(ltree,int start,int end) ¶
ltree寻找子路径,下标从start到end(从0开始计数),下标越界会出错。
示例:
select subltree('top.child1.child2',1,2); subltree ---------- child1 (1 row)
60.4.6. subpath(ltree,int offset,int len) ¶
ltree根据偏移量offset和len寻找子路径,如果offset为负则从路径末端开始。如果len为负数则将许多标签留在路径的末尾。
示例:
select subpath('top.child1.child2',1,2); subpath --------------- child1.child2 (1 row) select subpath('top.child1.child2',-1,1); subpath --------- child2 (1 row) select subpath('top.child1.child2',0,-2); subpath --------- top (1 row) select subpath('top.child1.child2',0,-1); subpath ------------ top.child1 (1 row) select subpath('top.child1.child2',0,0); subpath --------- (1 row) select subpath('top.child1.child2',1,0); subpath --------- (1 row)
60.4.7. subpath(ltree,int offset) ¶
ltree根据偏移量offset寻找子路径,延伸到路径末尾。如果offset为负数则子路径从路径末端开始。
示例:
select subpath('top.child1.child2',0); subpath ------------------- top.child1.child2 (1 row) select subpath('top.child1.child2',1); subpath --------------- child1.child2 (1 row) select subpath('top.child1.child2',-2); subpath --------------- child1.child2 (1 行记录)
60.4.8. index(ltree a,ltree b) ¶
计算第一次在a中出现b的位置,没找到返回-1。
示例:
select index('1.2.3.4.5.6','1.2'); index ------- 0 (1 row) select index('a.1.2.3.4.5.6','1.2'); index ------- 1 (1 row) select index('a.1.2.3.4.5.6','1.2.3'); index ------- 1 (1 row) select index('a.1.2.3.4.5.6','1.2.3.j'); index ------- -1 (1 row) select index('a.1.2.3.4.5.6','1.2.3.j.4.5.5.5.5.5.5'); index ------- -1 (1 row) select index('a.1.2.3.4.5.6','1.2.3'); index ------- 1 (1 row) select index('a.1.2.3.4.5.6','6'); index ------- 6 (1 row) select index('a.1.2.3.4.5.6','6.1'); index ------- -1 (1 row) select index('a.1.2.3.4.5.6','5.6'); index ------- 5 (1 row) select index('0.1.2.3.5.4.5.6','5.6'); index ------- 6 (1 row)
60.4.9. index(ltree a,ltree b,int offset) ¶
计算第一次在a中出现b的位置,从偏移处开始搜索,负偏移量从路径末尾开始搜索,没找到返回-1。
示例:
select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',6); index ------- 6 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',7); index ------- 9 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',-7); index ------- 6 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',-4); index ------- 9 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',-3); index ------- 9 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',-2); index ------- -1 (1 row) select index('0.1.2.3.5.4.5.6.8.5.6.8','5.6',-20000); index ------- 6 (1 row)
60.4.10. lca(ltree,ltree,...) ¶
路径最长的公共前缀部分(最多支持8个ltree参数)。
示例:
select lca('{la.2.3,1.2.3.4.5.6,""}') is null; ?column? ---------- t (1 row) select lca('{la.2.3,1.2.3.4.5.6}') is null; ?column? ---------- f (1 row) select lca('{1.la.2.3,1.2.3.4.5.6}'); lca ----- 1 (1 row) select lca('{1.2.3,1.2.3.4.5.6}'); lca ----- 1.2 (1 row) select lca('{1.2.3}'); lca ----- 1.2 (1 row) select lca('{1}'), lca('{1}') is null; lca | ?column? -----+---------- | f (1 row) select lca('{}') is null; ?column? ---------- t (1 row) select lca('1.la.2.3','1.2.3.4.5.6'); lca ----- 1 (1 row) select lca('1.2.3','1.2.3.4.5.6'); lca ----- 1.2 (1 row) select lca('1.2.2.3','1.2.3.4.5.6'); lca ----- 1.2 (1 row) select lca('1.2.2.3','1.2.3.4.5.6',''); lca ----- (1 row) select lca('1.2.2.3','1.2.3.4.5.6','2'); lca ----- (1 row) select lca('1.2.2.3','1.2.3.4.5.6','1'); lca ----- (1 row)
60.4.11. nlevel(ltree) ¶
计算路径中标签数量。
示例:
select nlevel('1.2.3.4'); nlevel -------- 4 (1 row)
60.5. 插件ltree卸载方法 ¶
卸载时drop extension ltree即可。
示例:
drop extension ltree;
60.6. 插件ltree升级方法 ¶
ltree扩展插件通常随着KingbaseES安装包一并升级。通常情况下用户无须单独升级些插件。