Skip to content

Commit 40dc36c

Browse files
authored
Merge pull request #180 from yuanyl630/master
case-conversion featue document
2 parents b83f91d + 9358c35 commit 40dc36c

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

CN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
**** xref:master/6.3.6.adoc[函数与存储过程]
3030
**** xref:master/6.3.7.adoc[嵌套子函数]
3131
**** xref:master/6.3.8.adoc[Force View]
32+
**** xref:master/6.3.9.adoc[大小写转换]
33+
*** xref:master/6.4.adoc[国标GB18030]
3234
*** 内置函数
3335
**** xref:master/6.4.1.adoc[sys_context]
3436
**** xref:master/6.4.2.adoc[userenv]

CN/modules/ROOT/pages/master/5.2.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export PG_CONFIG=/usr/local/ivorysql/ivorysql-4/bin/pg_config
3535

3636
** 拉取pg_vector源码
3737
```
38-
git clone --branch v0.6.2 https://github.com/pgvector/pgvector.git
38+
git clone --branch v0.8.1 https://github.com/pgvector/pgvector.git
3939
```
4040

4141
** 安装 pgvector
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= 引用标识符大小写转换
7+
8+
== 目的
9+
10+
为了满足Oracle的引用标识符大小写兼容,ivorysql设计了三种引用标识符的大小写转换模式。
11+
12+
== 实现说明
13+
14+
如果在数据库初始化时附加了参数 `-C`,值可以为 `normal/interchange/lowercase`,则代码中 `Intidb.c->main()` 函数会处理该参数,根据参数值设置全局变量 `caseswitchmode`。然后 `initdb` 命令会以 `-boot` 模式启动一个 `psotgres` 进程用于设置 `template1` 模板数据库,同时赋予参数 `-C ivorysql.identifier_case_switch=caseswitchmode` 给新进程。
15+
16+
这个新启动的后端进程会通过下面的代码将 `identifier_case_switch` 信息写入 `pg_control` 文件:
17+
18+
```
19+
BootstrapModeMain() -> BootStrapXLOG();
20+
/* save database compatible level value */
21+
ControlFile->dbmode = bootstrap_database_mode;
22+
ControlFile->casemode = identifier_case_switch;
23+
24+
/* some additional ControlFile fields are set in WriteControlFile() */
25+
WriteControlFile();
26+
```
27+
28+
当用户使用 `pg_ctl` 命令启动数据库时,`postmaster` 进程会读取 `pg_control` 文件的内容,代码调用路径为:
29+
30+
```
31+
PostmasterMain()-->SetCaseGucOption()-->GetCaseSwitchModeFromControl()
32+
```
33+
34+
读取到参数值后调用 `SetConfigOption()` 函数进行赋值。
35+
36+
在每个新的后端进程开始的时候,由于是从 `postmaster` 进程 `fork` 而来,会自动拥有相同的 `ivorysql.identifier_case_switch` 参数值。首先处理 `startup` 包,其中如果包含 `database` 或者 `user` 这两个参数,则根据 `identifier_case_switch` 对参数值做相应的处理。
37+
38+
源代码为:
39+
40+
```
41+
BackendMain()->BackendInitialize()-->ProcessStartupPacket()
42+
```
43+
44+
另外,在处理用户的 SQL 语句时,如果包含标识符,也会进行同样的处理,代码分布在:
45+
SplitIdentifierString(),quoteOneName() 和 SplitGUCList() 这几个函数中。
46+
47+

EN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*** xref:master/6.3.6.adoc[Function and stored procedure]
2929
*** xref:master/6.3.7.adoc[Nested Subfunctions]
3030
*** xref:master/6.3.8.adoc[Force View]
31+
*** xref:master/6.3.9.adoc[Case Conversion]
32+
** xref:master/6.4.adoc[GB18030 Character Set]
3133
** Built-in Functions
3234
*** xref:master/6.4.1.adoc[sys_context]
3335
*** xref:master/6.4.2.adoc[userenv]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= Quoted Identifier Case Conversion
7+
8+
== Purpose
9+
10+
To meet Oracle's quoted identifier case compatibility requirements, IvorySQL has designed three case conversion modes for quoted identifiers.
11+
12+
== Implementation Details
13+
14+
If the parameter `-C` is appended during database initialization, with values of `normal/interchange/lowercase`, the `Intidb.c->main()` function in the code will process this parameter and set the global variable `caseswitchmode` according to the parameter value. Then the `initdb` command will start a `postgres` process in `-boot` mode to set up the `template1` template database, while passing the parameter `-C ivorysql.identifier_case_switch=caseswitchmode` to the new process.
15+
16+
This newly started backend process will write the `identifier_case_switch` information to the `pg_control` file through the following code:
17+
18+
```
19+
BootstrapModeMain() -> BootStrapXLOG();
20+
/* save database compatible level value */
21+
ControlFile->dbmode = bootstrap_database_mode;
22+
ControlFile->casemode = identifier_case_switch;
23+
24+
/* some additional ControlFile fields are set in WriteControlFile() */
25+
WriteControlFile();
26+
```
27+
28+
When a user starts the database using the `pg_ctl` command, the `postmaster` process will read the contents of the `pg_control` file. The code call path is:
29+
30+
```
31+
PostmasterMain()-->SetCaseGucOption()-->GetCaseSwitchModeFromControl()
32+
```
33+
34+
After reading the parameter value, the `SetConfigOption()` function is called to assign the value.
35+
36+
When each new backend process starts, since it is forked from the `postmaster` process, it automatically has the same `ivorysql.identifier_case_switch` parameter value. First, it processes the `startup` packet, and if it contains `database` or `user` parameters, the parameter values are processed accordingly based on `identifier_case_switch`.
37+
38+
The source code is:
39+
40+
```
41+
BackendMain()->BackendInitialize()-->ProcessStartupPacket()
42+
```
43+
44+
Additionally, when processing user SQL statements, if they contain identifiers, the same processing is performed. The code is distributed in:
45+
SplitIdentifierString(), quoteOneName() and SplitGUCList() functions.
46+
47+
48+

0 commit comments

Comments
 (0)