返回首页

gbase数据、南大通用产品文档:GBase8sifx_int8add() 函数

更新日期:2024年09月11日

ifx_int8add() 函数将两个 int8 类型值相加。
语法
mint ifx_int8add(n1, n2, sum)
ifx_int8_t *n1;
ifx_int8_t *n2;
ifx_int8_t *sum;
n1
指向包含第一个操作对象的 int8 结构的指针。
n2
指向包含第二个操作对象的 int8 结构的指针。
sum
指向包含 n1 + n2 的和的 int8 结构的指针。

用法
sum 可与 n1 或 n2 相同。


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 714 -
返回代码
0
运算成功。
-1284
运算导致溢出或下溢。

示例
demo 目录中的文件 int8add.ec 包含下列示例程序。
*int8add.ec *

The following program obtains the sum of two INT8 type values.
*/

#include

EXEC SQL include "int8.h";

char string1[] = "6";
char string2[] = "9,223,372,036,854,775";
char string3[] = "999,999,999,999,999,9995";
char result[41];

main()
{
mint x;
ifx_int8_t num1, num2, num3, sum;

printf("INT8 Sample ESQL Program running.\n\n");

if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 715 -
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num1, &num2, ∑)) /* adding the first two INT8s */
{
printf("Error %d in adding INT8s\n", x);
exit(1);
}
if (x = ifx_int8soasc(∑, result, sizeof(result)))
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string1, string2, result); /* display result */

/* attempt to convert to INT8 value that is too large*/

if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}
if (x = ifx_int8add(&num2, &num3, ∑))
{
printf("Error %d in adding INT8s\n", x);
exit (1);
}
if (x = ifx_int8soasc(∑, result, sizeof(result)))

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 716 -
{
printf("Error %d in converting INT8 result to string\n", x);
exit(1);
}
result[40] = '\0';
printf("\t%s + %s = %s\n", string2, string3, result); /* display result */

printf("\nINT8 Sample Program over.\n\n");
exit(0);
}
输出
INT8 Sample ESQL Program running.

6 + 9,223,372,036,854,775 = 9223372036854781
Error -1284 in converting string3 to INT8
INT8 Sample Program over.

功能描述
定义一个新的外部服务器。
语法格式
CREATE SERVER server_name
FOREIGN DATA WRAPPER fdw_name
OPTIONS ( { option_name ' value ' } [, ...] ) ;
参数说明

server_name
server 的名称。
取值范围:长度必须小于等于63。

fdw_name

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
949
指定外部数据封装器的名称。
取值范围:dist_fdw,hdfs_fdw,log_fdw,file_fdw,mot_fdw。

OPTIONS ( { option_name ' value ' } [, …] )
这个子句为服务器指定选项。
这些选项通常定义该服务器的连接细节,
但是实际的名称
和值取决于该服务器的外部数据包装器。
oracle_fdw 支持的options 包括:

dbserver
远端Oracle 数据库的连接字符串。

isolation_level (默认值为serializable)
oracle 数据库的事务隔离级别。
取值范围:serializable、read_committed 、read_only
mysql_fdw 支持的options 包括:

host (默认值为127.0.0.1)
MySQL Server/MariaDB 的地址。

port (默认值为3306)
MySQL Server/MariaDB 侦听的端口号。
postgres_fdw 支持的options 同libpq 支持的连接参数一致,可参考链接字符。需要
注意的是,以下几个options 不支持设置:

user 和password
用户名和密码将在创建user mapping 时指定。

client_encoding
将自动获取本地server 的编码方式并设置该值。

application_name

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
950
总是设置成postgres_fdw。
用于指定外部服务器的各类参数,详细的参数说明如下所示。

encrypt
是否对数据进行加密,该参数仅支持type 为OBS 时设置。默认值为on。
取值范围:
on 表示对数据进行加密,使用HTTPS 协议通信。
off 表示不对数据进行加密,使用HTTP 协议通信。

access_key
OBS 访问协议对应的AK 值(OBS 云服务界面由用户获取)
,创建外表时AK 值会加密
保存到数据库的元数据表中。该参数仅支持type 为OBS 时设置。

secret_access_key
OBS 访问协议对应的SK 值(OBS 云服务界面由用户获取)
,创建外表时SK 值会加密
保存到数据库的元数据表中。该参数仅支持type 为OBS 时设置。
除了libpq 支持的连接参数外,还额外提供3 个options:

use_remote_estimate
控制postgres_fdw 是否发出EXPLAIN 命令以获取运行消耗估算。默认值为false。

fdw_startup_cost
执行一个外表扫描时的启动耗时估算。
这个值通常包含建立连接、
远端对请求的分析和
生成计划的耗时。默认值为100。

fdw_typle_cost
在远端服务器上对每一个元组进行扫描时的额外消耗。这个值通常表示数据在server
间传输的额外消耗。默认值为0.01。
示例

GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
951
创建server。
gbase=# create server my_server foreign data wrapper log_fdw;
CREATE SERVER
相关命令
ALTER SERVER,DROP SERVER

OCC 与2PL 的区别举例
下面是会话同时更新同一个表时,两种用户体验的区别:悲观(针对基于磁盘的表)和
乐观(针对MOT 表)。
本例中,使用如下表测试命令:
table “TEST” – create table test (x int, y int, z int, primary key(x));
本示例描述同一测试的两个方面:用户体验(本示例中的操作)和重试要求。
悲观方法示例——用于基于磁盘的表
下面是一个悲观方法例子(非MOT)。任何隔离级别都可能适用。
以下两个会话执行尝试更新单个表的事务。
WAIT LOCK 操作发生,客户端体验是:会话2 卡住,直到会话1 完成COMMIT,会
话2 才能进行。
但是,使用这种方法时,两个会话都成功,并且不会发生异常中止(除非应用了
SERIALIZABLE 或REPEATABLE-READ 隔离级别),这会导致整个事务需要重试。
表13- 5 悲观方法代码示例
时间
会话1
会话2
t0
Begin
Begin
t1
update test set y=200 where x=1;
t2
y=200
Update test set y=300 where x=1; – Wait
on lock
t4
Commit
Unlock
Commit
(in
READ-COMMITTED
this
will
succeed, in SERIALIZABLE it will fail)
y = 300

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
487
乐观方法示例——用于MOT
下面是一个乐观方法的例子。
它描述了创建一个MOT 表,然后有两个并发会话同时更新同一个MOT 表的情况。
create foreign table test (x int, y int, z int, primary key(x));

OCC 的优点是,在COMMIT 之前没有锁。

OCC 的缺点是,如果另一个会话更新了相同的记录,则更新可能会失败。如果更新失
败(在所有支持的隔离级别中),则必须重试整个会话#2 事务。

更新冲突由内核在提交时通过版本检查机制检测。

会话2 将不会等待其更新操作,并且由于在提交阶段检测到冲突而中止。
表13- 6 乐观方法代码示例——用于MOT
时间
会话1
会话2
t0
Begin
Begin
t1
update test set y=200 where
x=1;
t2
y=200
Update test set y=300 where
x=1;
t4
Commit
y = 300
Commit
ABORT
y = 200