梧桐DB新执行器函数支持情况统计

109 阅读28分钟

新执行器函数支持情况

1. 类型转换函数

1.1 anything to text

Function NameInput TypeOutput TypeOIDStatusDescription
charoutcharcstring33Implemented but unsupported将单个字符转换为 C 风格的字符串。
byteaoutboolcstring31Implemented but unsupported应该是将布尔值转换为字符串,但这里的输入类型与输出类型不匹配。
int2outint2cstring39Implemented but unsupported将 16 位整数转换为字符串。
int4outint4cstring43Implemented but unsupported将 32 位整数转换为字符串。
int8outint8cstring461Implemented but unsupported将 64 位整数转换为字符串。
float4outfloat4cstring201Implemented but unsupported将 32 位浮点数转换为字符串。
float8outfloat8cstring215Implemented but unsupported将 64 位浮点数转换为字符串。
numeric_outnumericcstring1702Implemented but unsupported将任意精度数值转换为字符串。
date_outdatecstring1085Implemented but unsupported将日期转换为字符串。
booloutboolcstring1243Implemented but unsupported将布尔值转换为字符串。
timeouttimecstring1144Implemented but unsupported将时间值转换为字符串。
timestamp_outtimestampcstring1313Implemented but unsupported将时间戳转换为字符串。
interval_outintervalcstring1161Implemented but unsupported将间隔值转换为字符串。
TimestamptztimestamptzcstringN/AImplemented but implementation function error将带时区的时间戳转换为字符串,但实现函数存在问题。

有实现但是不支持的原因是:在6.x版本,这种转换的类型是CoerceViaIO 类型,用来表示两种类型之间的类型强制转换。CoerceViaIO 是一种类型转换机制,它利用了类型输出(typoutput)和类型输入(typinput)函数来从一种数据类型转换到另一种数据类型。这种转换是基于文本格式的,也就是说,它首先将源数据类型转换为文本形式,然后再将该文本解析为目标数据类型。

例如,当你尝试将一个整数转换为日期,或者将一个日期转换为时间戳时,PostgreSQL 可能会使用 CoerceViaIO 路径。在这个过程中,整数首先被转换为文本,然后文本再被解析为日期或时间戳。

相关测试用例见下:

set new_executor = auto;
CREATE TABLE data_types (
    char_column char(1),
    smallint_column smallint,
    int_column int,
    bigint_column bigint,
    float_column float4,
    double_column float8,
    decimal_column decimal(10,2),
    date_column date,
    time_column time,
    timestamptz_column timestamptz,
    timestamp_column timestamp,
    interval_column interval,
    boolean_column boolean
);

INSERT INTO data_types (
    char_column,
    smallint_column,
    int_column,
    bigint_column,
    float_column,
    double_column,
    decimal_column,
    date_column,
    time_column,
    timestamptz_column,
    timestamp_column,
    interval_column,
    boolean_column
)
SELECT 
    substring('abcdefghijklmnopqrstuvwxyz' FROM (floor(random() * 26) + 1)::integer FOR 1),
    floor(random()*32767)::smallint,
    floor(random()*2147483647)::integer,
    floor(random()*9223372036854775807)::bigint,
    random()::real,
    random(),
    floor(random()*10000)::numeric(10,2),
    '2024-01-01'::date + floor(random()*365)::bigint * interval '1 day',
    '00:00:00'::time + floor(random()*86400)::bigint * interval '1 second',
    ('2024-01-01 00:00:00'::timestamp + floor(random()*31536000)::bigint * interval '1 second') AT TIME ZONE 'UTC',
    '2024-01-01 00:00:00'::timestamp + floor(random()*31536000)::bigint * interval '1 second',
    interval '1 day' * floor(random()*30)::bigint +
    interval '1 hour' * floor(random()*24)::bigint +
    interval '1 minute' * floor(random()*60)::bigint +
    interval '1 second' * floor(random()*60)::bigint,
    true
FROM generate_series(1,1000);

explain analyze select text(char_column) from data_types;
explain analyze select text(smallint_column) from data_types;
explain analyze select text(int_column) from data_types;
explain analyze select text(bigint_column) from data_types;
explain analyze select text(float_column) from data_types;
explain analyze select text(double_column)from data_types;
explain analyze select text(decimal_column) from data_types;
explain analyze select text(date_column) from data_types;
explain analyze select text(boolean_column) from data_types;
explain analyze select text(time_column) from data_types;
explain analyze select text(timestamptz_column) from data_types;
explain analyze select text(interval_column) from data_types;
explain analyze select text(timestamp_column) from data_types;

1.2 to timestamptz

Function NameInput Type(s)Output TypeOIDStatusDescription
to_timestampfloat8timestamptz1158Not supported, no oid [1158] corresponds将浮点数转换为带时区的时间戳,但该函数未被支持。
to_timestamptext, texttimestamptz1778Not supported, text_to_timestamp()has incorrect parameters将文本字符串和格式字符串转换为带时区的时间戳,但函数参数不正确导致不支持。

1.3 to date

date date(timestamptz) 不支持

Function NameInput TypeOutput TypeOIDStatusDescription
datetimestampdate2029Supported从时间戳中提取日期部分。
explain analyze select cast(timestamp_column as date) from data_types;
explain analyze select timestamp_column::date from data_types;

1.4 to timestamp

timestamp (date time), timestamp(timestamptz), timestamp(timestamp,int4)没有实现

Function NameInput TypeOutput TypeOIDStatusDescription
timestampdatetimestamp2024Supported从日期中构建时间戳,默认时间为午夜(00:00:00)。
explain analyze select cast(date_column as timestamp) from data_types;
explain analyze select date_column::timestamp from data_types;

1.5 in-out函数

OidFunction NameInput TypeOutput TypeStatusDescription
38int2incstringint2Implemented but unsupported将 C 风格的字符串转换为 16 位整数。
42int4incstringint4Implemented but unsupported将 C 风格的字符串转换为 32 位整数。
460int8incstringint8Implemented but unsupported将 C 风格的字符串转换为 64 位整数。
200float4incstringfloat4Implemented but unsupported将 C 风格的字符串转换为 32 位浮点数。
214float8incstringfloat8Implemented but unsupported将 C 风格的字符串转换为 64 位浮点数。
1777to_numbertextnumericNot specified将文本字符串转换为任意精度数值。

2. 处理函数

2.1 时间处理函数

Function NameInput Type(s)Output TypeStatusDescription
1389isfinitetimestamptzboolSupported检查时间戳是否有限(适用于日期、间隔和时间戳)。
2021date_parttext, timestampfloatSupported从时间戳中提取指定的部分(适用于时间戳、带时区的时间戳、间隔、带时区的时间和日期)。
2020date_trunctext, timestamptimestampSupported从时间戳中截取指定的部分(适用于时间戳、带时区的时间戳、间隔)。
1690time_mi_timetime, timeintervalNot supported两个时间相减得到间隔(不支持,因为没有注册 TIMEOID,但现在已支持)。
1141date_plidate, int4dateSupported日期加上整数天。
1142date_miidate, int4dateSupported日期减去整数天。
1188timestamptz_mitimestamptz, timestamptzintervalSupported两个带时区的时间戳相减得到间隔。
timestamp_mitimestamp, timestampintervalSupported两个时间戳相减得到间隔。
2071date_pl_intervaldate, intervaltimestampPartially supported日期加上间隔(部分支持,原因未知)。
2072date_mi_intervaldate, intervaltimestampPartially supported日期减去间隔(部分支持,原因disable INTERVAL type in scan)。
1747time_pl_intervaltime, intervaltimeNot supported时间加上间隔(不支持,原因disable INTERVAL type in scan)。
1748time_mi_intervaltime, intervaltimeNot supported时间减去间隔(不支持,原因disable INTERVAL type in scan)。
2032timestamp_pl_intervaltimestamp, intervaltimestampPartially supported时间戳加上间隔(部分支持,原因未知disable INTERVAL type in scan)。
2033timestamp_mi_intervaltimestamp, intervaltimestampPartially supported时间戳减去间隔(部分支持,原因未知disable INTERVAL type in scan)。
1168interval_umintervalintervalPartially supported间隔的负值(部分支持,原因disable INTERVAL type in scan)。
1598randomNonefloat8Not supported生成随机数(不支持,原因case T_FuncExpr 明确拦截)。
1599setseedfloat8voidNot supported设置随机数种子(不支持,原因case T_FuncExpr 明确拦截)。
-- bool isfinite(timestamptz) [oid:1389]
explain analyze select isfinite(date_column) from data_types;         -- no
explain analyze select isfinite(interval_column) from data_types;     -- no
explain analyze select isfinite(timestamp_column) from data_types;    -- no
explain analyze select isfinite(timestamptz_column) from data_types;  -- yes

-- float date_part(text timestamp) [oid:2021]
explain analyze select date_part('day', timestamp_column) from data_types; -- yes
explain analyze select date_part('day', timestamptz_column) from data_types; -- no
explain analyze select date_part('day', interval_column) from data_types;  -- no
explain analyze select date_part('day', date_column) from data_types;  -- yes ?
explain analyze select date_part('second', time_column) from data_types; -- no
explain analyze select date_part('second', timetz_column) from data_types;  -- no
-- timestamp date_trunc(text timestamp)
explain analyze select date_trunc('day', timestamp_column) from data_types;  -- yes
explain analyze select date_trunc('day', timestamptz_column) from data_types;  -- no
explain analyze select date_trunc('day', timestamptz_column, 'America/New_York') from data_types;  -- no
explain analyze select date_trunc('day', interval_column) from data_types;  -- no

-- time_mi_time
explain analyze select time_mi_time(time_column, time_column) from data_types;  -- no

-- date date_pli(date int4)
explain analyze select date_pli(date_column, int_column) from data_types; -- yes

-- date date_mii(date int4)
explain analyze select date_mii(date_column, int_column) from data_types; -- yes

-- timestamptz_mi
explain analyze select timestamptz_mi(timestamptz_column, timestamptz_column) from data_types;  -- yes

-- Interval timestamp_mi(timestamp timestamp)
explain analyze select timestamp_mi(timestamp_column, timestamp_column) from data_types;  -- yes

-- timestamp date_pl_interval(date interval)
explain analyze select date_pl_interval(date_column, interval_column) from data_types;  -- no
explain analyze select date_column + interval_column from data_types; -- no
explain analyze select date_column + '1 day'::interval from data_types -- yes

-- timestamp date_mi_interval(date interval) 原因同上

-- time time_pl_interval(time interval) 
explain analyze select time_pl_interval(time_column, interval_column) from data_types; -- no
explain analyze select time_column + interval_column from data_types; -- no
explain analyze select time_column + '1 second'::interval from data_types -- no

-- time time_mi_interval(time interval) 原因同上

-- timestamp timestamp_pl_interval(timestamp interval)
explain analyze select timestamp_pl_interval(timestamp_column, interval_column) from data_types; -- no
explain analyze select timestamp_column + interval_column from data_types; -- no
explain analyze select timestamp_column + '1 second'::interval from data_types; -- yes

-- timestamp timestamp_mi_interval(timestamp interval) 原因同上

-- interval interval_um(interval)
explain analyze select interval_um(interval_column) from data_types; -- no

2.2 字符串处理函数

Function NameInput Type(s)Output TypeOIDStatusDescription
octet_lengthtextInt41374Supported计算文本的字节长度。
octet_lengthbpcharInt41375Supported计算定长字符的字节长度。
lengthbyteaInt42010Supported计算字节数组的长度。
textlentextInt41257Supported计算文本的长度。
lengthbpcharInt41318Supported计算定长字符的长度。
textliketext, textbool850Supported检查文本是否符合模式。
bpcharlikebpchar, textbool1631Supported检查定长字符是否符合模式。
textnliketext, textbool851Supported检查文本是否不符合模式。
bpcharnlikebpchar, textbool1632Supported检查定长字符是否不符合模式。
substrtext, int4, int4text877Supported提取文本的子串。
substrtext, int4text883Supported提取文本的子串。
substringtext, int4, int4text936Supported提取文本的子串。
substringtext, int4text937Supported提取文本的子串。
lowertexttext870Supported将文本转换为小写。
uppertexttext871Supported将文本转换为大写。
textcattext, texttext1258Supported连接两个文本字符串。
positiontext, textint4849Supported查找一个文本在另一个文本中的位置。
strpostext, textint4868Supported查找一个文本在另一个文本中的位置。
initcaptexttext872Supported将每个单词首字母大写。
asciitextint41620Supported获取文本第一个字符的 ASCII 值。
varcharvarchar, int4, boolvarchar669Supported转换并调整文本的长度。
ltrimtexttext881Supported删除文本开头的空白字符。
ltrimtext, texttext875Supported删除文本开头特定字符。
rtrimtexttext882Supported删除文本末尾的空白字符。
rtrimtext, texttext876Supported删除文本末尾特定字符。
btrimtexttext885Supported删除文本两端的空白字符。
btrimtext, texttext884Supported删除文本两端特定字符。
repeattext, int4text1622Not supported重复文本指定次数。
chrint4text1621Supported返回给定 ASCII 值的字符。
bpcharbpchar, int4, boolbpchar668Supported调整定长字符的长度。
lpadtext, int4, texttext873Supported左侧填充文本。
rpadtext, int4, texttext874Supported右侧填充文本。
lpadtext, int4text879Supported左侧填充文本至指定长度。
rpadtext, int4text880Supported右侧填充文本至指定长度。
bpchareqbpchar, bpcharbool1053Supported比较两个定长字符是否相等。
bpcharlebpchar, bpcharbool1048Supported检查一个定长字符是否小于等于另一个。
bpcharltbpchar, bpcharbool1049Supported检查一个定长字符是否小于另一个。
bpcharlebpchar, bpcharbool1050Supported检查一个定长字符是否小于等于另一个。
bpchargtbpchar, bpcharbool1051Supported检查一个定长字符是否大于另一个。
bpchargebpchar, bpcharbool1052Supported检查一个定长字符是否大于等于另一个。
translatetext, text, texttext878Supported替换文本中的字符。
split_parttext, text, int4text2088Supported分割文本并返回指定部分。
text_pattern_lttext, textbool2160Supported检查文本是否小于模式。
text_pattern_letext, textbool2161Supported检查文本是否小于等于模式。
text_pattern_getext, textbool2163Supported检查文本是否大于等于模式。
text_pattern_gttext, textbool2164Supported检查文本是否大于模式。
textregexeqtext, textbool1254Supported使用正则表达式比较文本。
texticregexeqtext, textbool1238Supported使用正则表达式比较文本(忽略大小写)。
textregexnetext, textbool1256Supported使用正则表达式比较文本是否不匹配。
texticregexnetext, textbool1239Supported使用正则表达式比较文本是否不匹配(忽略大小写)。
bpcharregexeqbpchar, textbool1658Supported使用正则表达式比较定长字符。
bpcharicregexeqbpchar, textbool1656Supported使用正则表达式比较定长字符(忽略大小写)。
bpcharregexnebpchar, textbool1659Supported使用正则表达式比较定长字符是否不匹配。
bpcharicregexnebpchar, textbool1657Supported使用正则表达式比较定长字符是否不匹配(忽略大小写)。
regexp_replacetext, text, texttext2284Supported使用正则表达式替换文本中的模式
CREATE TABLE char_types (
    char_column char(1),
    varchar_column varchar(100),
    text_column text,
    bpchar bpchar(255)
);

INSERT INTO char_types (char_column, varchar_column, text_column)
SELECT
    chr(floor(random() * 26 + 65)::int),
    md5(random()::text),
    (
        SELECT string_agg(chr(floor(random() * 26 + 65)::int), '')
        FROM generate_series(1, (ceiling(random() * 10) + 1)::int)  -- 注意这里使用了 ceiling()
    )
FROM generate_series(1, 1000);

CREATE TABLE my_table1 (
    id serial PRIMARY KEY,
    my_column bpchar(255)
);

-- 插入一些数据
INSERT INTO my_table1 (my_column) VALUES ('Hello, World!');
INSERT INTO my_table1 (my_column) VALUES ('你好,世界!');  -- 这里的每个汉字在UTF-8中占3个字节



-- Int4 octet_length(text) 
explain analyze select octet_length(text_column) from char_types; -- yes

-- Int4 octet_length(bpchar)
explain analyze SELECT  octet_length(my_column) AS byte_length FROM my_table;  -- yes

-- Int4 textlen(text)
explain analyze select octet_length(text_column) from char_types; -- yes

-- Int4 length(bpchar)
explain analyze SELECT  length(my_column) AS byte_length FROM my_table; -- yes

-- bool textlike(text, text)
explain select textlike(text_column, 'N%A') AS is_match from char_types limit 1; --yes
explain select text_column like 'N%A' from char_types; -- yes
explain analyze  select * from char_types where text_column like 'N%A'; -- yes

-- bool bpcharlike(bpchar text)
explain analyze SELECT  bpcharlike(my_column, 'H%d%') AS byte_length FROM my_table; -- yes
explain select my_column like 'H%d%' from my_table; -- yes
explain analyze  select * from my_table where my_column like'H%d%'; -- yes

-- bool textnlike(text text)
explain select textnlike(text_column, 'N%A') AS is_match from char_types limit 1; --yes
explain select text_column not like 'N%A' from char_types; -- yes
explain analyze  select * from char_types where text_column not like 'N%A'; -- yes

-- bool bpcharnlike(bpchar text)
explain analyze SELECT  bpcharnlike(my_column, 'H%d%') AS byte_length FROM my_table; -- yes
explain select my_column not like 'H%d%' from my_table; -- yes
explain analyze  select * from my_table where my_column not like'H%d%'; -- yes

-- text substr(text int4 int4)
explain select substr(text_column, 1, 3) AS is_match from char_types limit 1; --yes

-- text substr(text int4)
explain select substr(text_column, 3) AS is_match from char_types limit 1; --yes

-- text lower(text)
explain select lower(text_column) AS is_match from char_types limit 1; --yes

-- text upper(text)
explain select upper(text_column) AS is_match from char_types limit 1; --yes

-- text textcat(text text)
explain select textcat(text_column, text_column) AS is_match from char_types limit 1; --yes

-- int4 position(text text)
explain  select position(text_column in text_column) from char_types;

-- int4 strpos(text text)
explain  select strpos(text_column , text_column) from char_types;

-- text initcap(text)
explain  select initcap(text_column) from char_types;

-- int4 ascii(text)
explain  select ascii(text_column) from char_types;

-- varchar varchar(varchar int4 bool)
explain select "varchar"(varchar_column, 10::int4, false) from char_types;

-- 
explain  select ltrim(text_column) from char_types;
explain  select ltrim(text_column, text_column) from char_types;
explain  select rtrim(text_column) from char_types;
explain  select rtrim(text_column, text_column) from char_types;
explain  select btrim(text_column) from char_types;
explain  select btrim(text_column, text_column) from char_types;

-- text repeat(text int4)
explain select repeat(text_column, 12) from char_types;

-- text chr(int4)
explain select chr(int_column) from data_types;

-- bpchar bpchar(bpchar int4 bool)
explain select "bpchar"(my_column, 12, false) from my_table;

-- text lpad(text int4 text)
explain select lpad(text_column, 12, text_column) from char_types;

-- text rpad(text int4 text)
explain select rpad(text_column, 12, text_column) from char_types;

-- text lpad(text int4)
explain select lpad(text_column, 12) from char_types;

-- text rpad(text int)
explain select rpad(text_column, 12) from char_types;

-- bool bpchareq(bpchar bpchar)
explain select bpchareq(my_column, my_column) from my_table;
explain select bpcharlt(my_column, my_column) from my_table;
explain select bpcharle(my_column, my_column) from my_table;
explain select bpchargt(my_column, my_column) from my_table;
explain select bpcharge(my_column, my_column) from my_table;
explain select bpcharne(my_column, my_column) from my_table;

-- text translate(text text text)
explain select translate(text_column, 'A', 'AAAA') from char_types;

-- text split_part(text text int4)
explain select split_part(text_column, 'A', '1') from char_types;

-- bool text_pattern_lt(text text)
explain select text_pattern_lt(text_column, text_column) from char_types;
explain select text_pattern_le(text_column, text_column) from char_types;
explain select text_pattern_ge(text_column, text_column) from char_types;
explain select text_pattern_gt(text_column, text_column) from char_types;


explain analyze select regexp_replace(text_column, 'a', '12') from char_types;
explain analyze select textregexeq(text_column, '[a-zA-Z]') from char_types;
explain analyze select texticregexeq(text_column, '[a-zA-Z]') from char_types;
explain analyze select textregexne(text_column, '[a-zA-Z]') from char_types;
explain analyze select texticregexne(text_column, '[a-zA-Z]') from char_types;

explain analyze select regexp_replace(my_column, 'a', '12') from my_table1;
explain analyze select textregexeq(my_column, '[a-zA-Z]') from my_table1;
explain analyze select texticregexeq(my_column, '[a-zA-Z]') from my_table1;
explain analyze select textregexne(my_column, '[a-zA-Z]') from my_table1;
explain analyze select texticregexne(my_column, '[a-zA-Z]') from my_table1;

2.3 数组处理函数

Function NameInput Type(s)Output TypeOIDStatusDescription
arrayoverlapanyarray, anyarraybool2747Not supported检查两个数组是否有重叠元素(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID)。
arraycontainsanyarray, anyarraybool2748Not supported检查一个数组是否包含另一个数组的所有元素(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID)。
arraycontainedanyarray, anyarraybool2749Not supported检查一个数组是否被另一个数组完全包含(不支持,因为 std::set<Oid> SupportedTypes没有注册 ANYARRAYOID

2.4 数值处理函数

Function NameInput TypeOutput TypeOIDStatusDescription
float8absfloat8float8221Supported计算浮点数的绝对值。
float4absfloat4float4207Supported计算浮点数的绝对值。
int8absint8int81230Supported计算整数的绝对值。
int4absint4int41251Supported计算整数的绝对值。
int2absint2int21253Supported计算整数的绝对值。
float8umfloat8float8220Supported计算浮点数的负值。
float4umfloat4float4206Supported计算浮点数的负值。
int8umint8int8462Supported计算整数的负值。
int4umint4int4212Supported计算整数的负值。
int2umint2int2213Supported计算整数的负值。

2.5 tid处理函数

Function NameInput Type(s)Output TypeOIDStatusDescription
tidetid, tidbool1292Not supported比较两个事务 ID 是否相等(函数声明不一致)。
tidnetid, tidbool1265Not supported比较两个事务 ID 是否不相等(函数声明不一致)。
tidlttid, tidbool2791Not supported检查一个事务 ID 是否小于另一个(函数声明不一致)。
tidletid, tidbool2793Not supported检查一个事务 ID 是否小于等于另一个(函数声明不一致)。
tidgttid, tidbool2790Not supported检查一个事务 ID 是否大于另一个(函数声明不一致)。
tidgetid, tidbool2792Not supported检查一个事务 ID 是否大于等于另一个(函数声明不一致)。

-- bool tide(tid tid)
explain select tide(bigint_column, bigint_column) from data_types;
explain select tidne(bigint_column, bigint_column) from data_types;
explain select tidlt(bigint_column, bigint_column) from data_types;
explain select tidle(bigint_column, bigint_column) from data_types;
explain select tidgt(bigint_column, bigint_column) from data_types;
explain select tidge(bigint_column, bigint_column) from data_types;

-- float8 float8abs(float8)
explain select float4abs(float_column) from data_types;
explain select float8abs(double_column) from data_types;
explain select int8abs(bigint_column) from data_types;
explain select int4abs(int_column) from data_types;
explain select int2abs(smallint_column) from data_types;

-- Float8 float8um(flaot8)
explain select float8um(double_column) from data_types;
explain select float4um(float_column) from data_types;
explain select int8um(bigint_column) from data_types;
explain select int4um(int_column) from data_types;
explain select int2um(smallint_column) from data_types;

-- int2 int2not(int2)
explain select int2not(smallint_column) from data_types;
explain select int4not(int_column) from data_types;
explain select int8not(bigint_column) from data_types;

-- int2 int2shl(int2)
explain select int2shl(smallint_column, 1) from data_types;
explain select int4shl(int_column, 1) from data_types;
explain select int8shl(bigint_column, 1) from data_types;

-- int2 int2shr(int2)
explain select int2shr(smallint_column, 1) from data_types;
explain select int4shr(int_column, 1) from data_types;
explain select int8shr(bigint_column, 1) from data_types;

-- int2and
explain select int2and(smallint_column, smallint_column) from data_types;
explain select int4and(int_column, int_column) from data_types;
explain select int8and(bigint_column, bigint_column) from data_types;

-- int2or
explain select int2or(smallint_column, smallint_column) from data_types;
explain select int4or(int_column, int_column) from data_types;
explain select int8or(bigint_column, bigint_column) from data_types;

-- int2xor
explain select int2xor(smallint_column, smallint_column) from data_types;
explain select int4xor(int_column, int_column) from data_types;
explain select int8xor(bigint_column, bigint_column) from data_types;

-- intmod
explain select int2mod(smallint_column, smallint_column) from data_types;
explain select int4mod(int_column, int_column) from data_types;
explain select int8mod(bigint_column, bigint_column) from data_types;

2.6 send函数

oid函数声明支持情况备注
2435bytea charsend(char)function charsend(character) does not exist
2405bytea int2send(int2)支持
2407bytea int4send(int4)支持
2409bytea int8send(int8)支持
2425bytea float4send(float4)支持
2427bytea float8send(float8)支持
2437bytea boolsend(bool)支持
2415bytea textsend(text)支持
2469bytea date_send(date)支持
2471bytea time_send(time)不支持
2475bytea timestamp_send(timestamp)支持
2477bytea timestamptz_send(timestamptz)支持
2479bytea interval_send(interval)不支持
2461bytea numeric_send(numeric)支持
explain analyze select int2send(smallint_column) from data_types;
explain analyze select int4send(int_column) from data_types;
explain analyze select int8send(bigint_column) from data_types;
explain analyze select float4send(float_column) from data_types;
explain analyze select float8send(double_column) from data_types;
explain analyze select boolsend(boolean_column) from data_types;
explain analyze select textsend(text_column) from char_types;
explain analyze select date_send(date_column) from data_types;
explain analyze select time_send(time_column) from data_types;  -- no
explain analyze select timestamp_send(timestamp_column) from data_types;
explain analyze select timestamptz_send(timestamptz_column) from data_types;
explain analyze select interval_send(interval_column) from data_types;  -- no
explain analyze select numeric_send(decimal_column) from data_types;

2.7 数学运算

Function NameInput Type(s)Output TypeOIDStatusDescription
dcbrtfloat8float8231Supported计算立方根。
dsqrtfloat8float8230Supported计算平方根。
int2notint2int21895Supported计算按位非。
int4notint4int41901Supported计算按位非。
int8notint8int81907Supported计算按位非。
int2shlint2, int4int21896Supported计算左移。
int4shlint2, int4int41902Supported计算左移。
int8shlint2, int4int81908Supported计算左移。
int2shrint2, int4int21897Supported计算右移。
int4shrint2, int4int41903Supported计算右移。
int8shrint2, int4int81909Supported计算右移。
int2andint2, int2int21892Supported计算按位与。
int4andint4, int4int41898Supported计算按位与。
int8andint8, int8int81904Supported计算按位与。
int2orint2, int2int21893Supported计算按位或。
int4orint4, int4int41899Supported计算按位或。
int8orint8, int8int81905Supported计算按位或。
int2xorint2, int2int21894Supported计算按位异或。
int4xorint4, int4int41900Supported计算按位异或。
int8xorint8, int8int81906Supported计算按位异或。
int2modint2, int2int2155Supported计算模数。
int4modint4, int4int4156Supported计算模数。
int8modint8, int8int8945Supported计算模数。
dpowfloat8, float8float8232Supported计算幂。
ceilfloat8float82308Supported向上取整。
floorfloat8float82309Supported向下取整。
droundfloat8float8228Supported四舍五入。
dtruncfloat8float8229Supported截断到整数。
signfloat8float82310Supported计算符号。
dexpfloat8float8233Supported计算指数。
dlog1float8float8234Supported计算自然对数。
log10float8float81194Supported计算以10为底的对数。
logfloat8float81340Core, 参数不匹配,这个机制有问题,params size不匹配竟然都会匹配到计算对数。
asinfloat8float81600Supported计算反正弦。
acosfloat8float81601Supported计算反余弦。
atanfloat8float81602Supported计算反正切。
atan2float8, float8float81603Supported计算两数的反正切。
sinfloat8float81604Supported计算正弦。
cosfloat8float81605Supported计算余弦。
tanfloat8float81606Supported计算正切。
cotfloat8float81607Supported计算余切。
degreesfloat8float81608Supported弧度转角度。
radiansfloat8float81609Supported角度转弧度。
numeric_uminusnumericnumeric1771Supported计算负值。
numeric_absnumericnumeric1704Supported计算绝对值。
roundnumericnumeric1708Supported四舍五入。
truncnumeric, int4numeric1709Supported截断到小数点后指定位数。
truncnumericnumeric1710Supported截断到整数。
numericnumeric, int4numeric1703Not supported构建数字类型。
modnumeric, numericnumeric1728Supported计算模数。
sqrtnumericnumeric1730Supported计算平方根。
expnumericnumeric1732Supported计算指数。
lnnumericnumeric1734Supported计算自然对数。
lognumeric, numericnumeric1736Supported计算对数。
numeric_facint8numeric111Supported计算阶乘。
pownumeric, numericnumeric1738Supported计算幂。
stddev_sampint2numeric2714Supported样本标准差。
stddev_sampint4numeric2713Supported样本标准差。
stddev_sampint8numeric2712Supported样本标准差。
stddev_sampfloat4float82715Supported样本标准差。
stddev_sampfloat8float82716Supported样本标准差。
stddev_sampnumericnumeric2717Supported样本标准差。
stddev_popint2numeric2726Supported总体标准差。
stddev_popint4numeric2725Supported总体标准差。
stddev_popint8numeric2724Supported总体标准差。
stddev_popfloat4float82727Supported总体标准差。
stddev_popfloat8float82728Supported总体标准差。
stddev_popnumericnumeric2729Supported总体标准差。
stddevint2numeric2156Supported标准差。
stddevint4numeric2155Supported标准差。
stddevint8numeric2154Supported标准差。
stddevfloat4float82157Supported标准差。
stddevfloat8float82158Supported标准差。
stddevnumericnumeric2159Supported标准差。
explain analyze select dcbrt(double_column) from data_types;
explain analyze select dsqrt(double_column) from data_types;

-- float8 dpow(float8 float8)
explain analyze select dpow(double_column, double_column) from data_types;

-- float8 ceil(float8)
explain analyze select ceil(double_column) from data_types;

-- float8 floor(float8)
explain analyze select floor(double_column) from data_types;

-- float8 dround(float8)
explain analyze select dround(double_column) from data_types;

-- float8 dtrunc(float8)
explain analyze select dtrunc(double_column) from data_types;

-- float8 sign(float8)
explain analyze select sign(double_column) from data_types;

explain analyze select dlog1(double_column)   from  data_types;
explain analyze select log10(double_column)   from  data_types;


explain analyze select log(double_column)     from  data_types;  -- core
explain analyze select asin(double_column)    from  data_types;
explain analyze select acos(double_column)    from  data_types;
explain analyze select atan(double_column)    from  data_types;


explain analyze select atan2(double_column, 1.1)   from  data_types;
explain analyze select sin(double_column)     from  data_types;
explain analyze select cos(double_column)     from  data_types;
explain analyze select tan(double_column)     from  data_types;
explain analyze select cot(double_column)     from  data_types;
explain analyze select degrees(double_column) from  data_types;
explain analyze select radians(double_column) from  data_types;

-- numeric numeric_uminus(numeric)
explain analyze select numeric_uminus(decimal_column) from  data_types;
explain analyze select numeric_abs(decimal_column) from  data_types;



explain analyze select round(decimal_column)        from data_types;
explain analyze select trunc(decimal_column, 4)   from data_types;
explain analyze select trunc(decimal_column)        from data_types;
explain analyze select "numeric"(decimal_column , 4) from data_types;
explain analyze select mod(decimal_column , decimal_column)  from data_types;
explain analyze select sqrt(decimal_column)         from data_types;
explain analyze select exp(decimal_column)          from data_types;
explain analyze select ln(decimal_column)           from data_types;
explain analyze select log(decimal_column, decimal_column)  from data_types  where bigint_column < 100;;
explain analyze select pow(decimal_column, decimal_column)  from data_types  where bigint_column < 100;;           
explain analyze select numeric_fac(bigint_column) from data_types where bigint_column < 100;


explain analyze select stddev_samp(smallint_column) from data_types;
explain analyze select stddev_samp(int_column) from data_types;
explain analyze select stddev_samp(bigint_column) from data_types where bigint_column  < 1000;
explain analyze select stddev_samp(float_column) from data_types;
explain analyze select stddev_samp(double_column) from data_types;
explain analyze select stddev_samp(decimal_column) from data_types;



explain analyze select stddev_pop(smallint_column) from data_types;
explain analyze select stddev_pop(int_column) from data_types;
explain analyze select stddev_pop(bigint_column) from data_types where bigint_column  < 1000;
explain analyze select stddev_pop(float_column) from data_types;
explain analyze select stddev_pop(double_column) from data_types;
explain analyze select stddev_pop(decimal_column) from data_types;


explain analyze select stddev(smallint_column) from data_types;
explain analyze select stddev(int_column) from data_types;
explain analyze select stddev(bigint_column) from data_types where bigint_column  < 1000;
explain analyze select stddev(float_column) from data_types;
explain analyze select stddev(double_column) from data_types;
explain analyze select stddev(decimal_column) from data_types;

2.8 oid运算符

716Oid oddlt(oid oid)不支持,oid类型没有注册
717Oid oidle(oid oid)不支持,oid类型没有注册
184Oid oideq(oid oid)不支持,oid类型没有注册
185Oid oidne(oid oid)不支持,oid类型没有注册
1638Oid oidgt(oid oid)不支持,oid类型没有注册
1639Oid oidge(oid oid)不支持,oid类型没有注册
1965Oid oidlarger(oid oid)不支持,oid类型没有注册
1966oid oidsmaller(oid oid)不支持,oid类型没有注册
677bool oidvectorlt(oidvector oidvector)类型错误
678bool oidvectorle(oidvector oidvector)类型错误
679bool oidvectoreq(oidvector oidvector)类型错误
619bool oidvectorne(oidvector oidvector)类型错误
681bool oidvectorgt(oidvector oidvector)类型错误
680bool oidvectorge(oidvector oidvector)类型错误

2.9 name运算符

oid函数声明支持情况备注
655bool namelt(name name)不支持
656bool namele(name name)不支持
62bool nameeq(name name)不支持
659bool namene(name name)不支持
657bool namegt(name name)不支持
658bool namege(name name)不支持
241bool namelttext(name text)不支持
242bool nameletext(name text)不支持
240bool nameeqtext(name text)不支持
245bool namenetext(name text)不支持
244bool namegttext(name text)不支持
243bool namegetext(name text)不支持
248bool textltname(text anme)不支持
249bool textlename(text name)不支持
247bool texteqname(text name)不支持
252bool textnename(text name)不支持
251bool textgtname(text name)不支持
250Bool textgename(text name)不支持
CREATE TABLE names (
    id serial PRIMARY KEY,
    name1 name,
    name2 name
);

-- 插入一些数据
INSERT INTO names (name1, name2) VALUES ('table_a', 'table_b');
INSERT INTO names (name1, name2) VALUES ('table_z', 'table_a');
INSERT INTO names (name1, name2) VALUES ('table_x', 'table_y');
INSERT INTO names (name1, name2) VALUES ('table_y', 'table_y');


explain analyze select namelt(name1, name2) from names;
explain analyze select namele(name1, name2) from names;
explain analyze select nameeq(name1, name2) from names;
explain analyze select namene(name1, name2) from names;
explain analyze select namegt(name1, name2) from names;
explain analyze select namege(name1, name2) from names;


explain analyze select namelttext(name2, '12'::text) from names;
explain analyze select nameletext(name2, '12'::text) from names;
explain analyze select nameeqtext(name2, '12'::text) from names;
explain analyze select namenetext(name2, '12'::text) from names;
explain analyze select namegttext(name2, '12'::text) from names;
explain analyze select namegetext( name2, '12'::text) from names;

explain analyze select textltname('12'::text, name1) from names;
explain analyze select textlename('12'::text, name1) from names;
explain analyze select texteqname('12'::text, name1) from names;
explain analyze select textnename('12'::text, name1) from names;
explain analyze select textgtname('12'::text, name1) from names;
explain analyze select textgename('12'::text, name1) from names;

2.10 窗口函数

oid函数声明支持情况备注
3100int8 row_number()不支持
3101int8 rank()不支持
3102int8 dense_rank()不支持
-- 创建表
CREATE TABLE orders (
    order_id serial PRIMARY KEY,
    customer_name text,
    order_date date,
    amount numeric
);

-- 插入数据
INSERT INTO orders (customer_name, order_date, amount)
VALUES ('Alice', '2023-01-01', 100.00),
       ('Bob', '2023-01-01', 200.00),
       ('Alice', '2023-01-02', 150.00),
       ('Charlie', '2023-01-02', 300.00),
       ('Bob', '2023-01-03', 250.00),
       ('Alice', '2023-01-03', 175.00);

-- 使用 row_number 函数
SELECT
    customer_name,
    order_date,
    amount,
    row_number() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;


-- 使用 rank 函数
SELECT
    customer_name,
    order_date,
    amount,
    rank() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;


-- 使用 dense_rank 函数
SELECT
    customer_name,
    order_date,
    amount,
    dense_rank() OVER (PARTITION BY customer_name ORDER BY order_date) AS row_num
FROM orders
ORDER BY customer_name, order_date;


-- 清理测试数据
DROP TABLE orders;