既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
/\* Run parse analysis ... \*/
if (u_sess->attr.attr_sql.enable_parallel_ddl) // 先解析parse\_tree获取stmt
stmts = transformCreateStmt((CreateStmt\*)parse_tree, query_string, NIL, true, &namespace_id, is_first_node);
else
stmts = transformCreateStmt((CreateStmt\*)parse_tree, query_string, NIL, false, &namespace_id);
/\*
* If stmts is NULL, then the table is exists.
* we need record that for searching the group of table.
*/
if (stmts == NIL) { // 如果stmt为空则表明表已经存在
table_is_exist = true;
……
/* … and do it */
foreach (l, stmts) { // 遍历stmts
Node* stmt = (Node*)lfirst(l);
if (IsA(stmt, CreateStmt)) { // 如果是 CreateStmt就调用DefineRelation
Datum toast_options;
static const char\* const validnsps[] = HEAP_RELOPT_NAMESPACES;
/\* forbid user to set or change inner options \*/
ForbidOutUsersToSetInnerOptions(((CreateStmt\*)stmt)->options);
/\* Create the table itself \*/
rel_oid = DefineRelation((CreateStmt\*)stmt,
((CreateStmt\*)stmt)->relkind == RELKIND_MATVIEW ?
RELKIND_MATVIEW : RELKIND_RELATION,
InvalidOid, isCTAS);
……
AlterTableCreateToastTable(rel_oid, toast_options, AccessShareLock);
AlterCStoreCreateTables(rel_oid, toast_options, (CreateStmt*)stmt);
AlterDfsCreateTables(rel_oid, toast_options, (CreateStmt*)stmt);
AlterCreateChainTables(rel_oid, toast_options, (CreateStmt *)stmt);
……
DefineRelation函数获取到表名relname、名字空间relnamespace、表空间reltablespace、表类型relkind和relpersistence等信息后调用heap\_create\_with\_catalog创建relation。
(gdb) f 0
#0 heap_create_with_catalog (relname=0x7fb4fa872140 “t100”, relnamespace=2200, reltablespace=0, relid=0, reltypeid=0,
reloftypeid=0, ownerid=10, tupdesc=0x7fb4ff2e2e50, cooked_constraints=0x0, relkind=114 ‘r’, relpersistence=112 ‘p’,
shared_relation=false, mapped_relation=false, oidislocal=false, oidinhcount=0, oncommit=ONCOMMIT_NOOP,
reloptions=140415352057720, use_user_acl=true, allow_system_table_mods=false, partTableState=0x0, row_compress=1 ‘\001’,
bucketinfo=0x0, record_dependce=true, ceLst=0x0, storage_type=HEAP_DISK, partLockMode=1) at heap.cpp:2521
heap\_create\_with\_catalog主要完成表物理文件的创建和表元信息注册到系统表中,涉及系统包包括pg\_class,pg\_attribute,pg\_depend,pg\_object,pg\_type,pg\_index和pg\_partition。
![在这里插入图片描述](https://img-blog.csdnimg.cn/ded6a25bd4ad43f1840b4a9d2a0d91b0.png)
其中heap\_create内部首先调用了RelationBuildLocalRelation创建RelationData,并加入到relCache,RelationData表示一个表的元信息,这些信息都可以由系统表元组中的信息构造得到。然后根据这些信息通过调用RelalionCreateStorage函数创建物理文件。
附:创建表create table的函数调用栈
#0 RelationCreateStorage
#1 heap\_create
#2 heap\_create\_with\_catalog
#3 DefineRelation
#4 CreateCommand
#5 standard\_ProcessUtility
#6 gsaudit\_ProcessUtility\_hook
#7 pgaudit\_ProcessUtility
#8 hypo\_utility\_hook
#9 ProcessUtility
#10 PortalRunUtility
#11 PortalRunMulti
#12 PortalRun
#13 exec\_simple\_query
#14 PostgresMain
[openGauss: 一款高性能、高安全、高可靠的企业级开源关系型数据库。](https://bbs.csdn.net/topics/618545628)
🍒如果您觉得博主的文章还不错或者有帮助的话,请关注一下博主,如果三连点赞评论收藏就更好啦!谢谢各位大佬给予的支持!
![img](https://img-blog.csdnimg.cn/img_convert/e39965ec5794ebf7358353f75c771b7b.png)
![img](https://img-blog.csdnimg.cn/img_convert/c7ea16556da6fe22b7a2010c4c2c5c79.png)
![img](https://img-blog.csdnimg.cn/img_convert/2f0f74b1585faa6247df3e2ef68837b7.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**