返回顶部
首页 > 资讯 > 数据库 >PostgreSQL源码学习(2)插入数据#0
  • 885
分享到

PostgreSQL源码学习(2)插入数据#0

PostgreSQL源码学习(2)插入数据#0 2019-10-17 14:10:28 885人浏览 猪猪侠
摘要

插入数据主要的实现在bufpage.c中,主要的函数是PageAddItemExtended。查看调用栈: #0 PageAddItemExtended (page=0x7fddcac3cd00 "", item=0x

PostgreSQL源码学习(2)插入数据#0

插入数据主要的实现在bufpage.c中,主要的函数是PageAddItemExtended。查看调用栈:

#0  PageAddItemExtended (page=0x7fddcac3cd00 "", item=0x141f540 "34701", 
    size=32, offsetNumber=0, flags=2) at bufpage.c:199
#1  0x00000000004d9e70 in RelationPutHeapTuple (relation=0x7fDDDa866178, 
    buffer=158, tuple=0x141f528, token=false) at hio.c:53
#2  0x00000000004c76d2 in heap_insert (relation=0x7fddda866178, tup=0x141f528, 
    cid=0, options=0, bistate=0x0) at heapam.c:1913
#3  0x00000000004d3ead in heapam_tuple_insert (relation=0x7fddda866178, 
    slot=0x141f3c8, cid=0, options=0, bistate=0x0) at heapam_handler.c:257
#4  0x00000000006dae8a in table_tuple_insert (rel=0x7fddda866178, 
    slot=0x141f3c8, cid=0, options=0, bistate=0x0)
    at ../../../src/include/access/tableam.h:1140
#5  0x00000000006dbf87 in ExecInsert (mtstate=0x141e8d0, slot=0x141f3c8, 
    planSlot=0x141f3c8, estate=0x141e540, canSetTag=true)
    at nodeModifyTable.c:586
#6  0x00000000006de2fa in ExecModifyTable (pstate=0x141e8d0)
    at nodeModifyTable.c:2215
#7  0x00000000006b2af7 in ExecProcNodeFirst (node=0x141e8d0)
    at execProcnode.c:445
#8  0x00000000006a8cd7 in ExecProcNode (node=0x141e8d0)
    at ../../../src/include/executor/executor.h:239
#9  0x00000000006ab053 in ExecutePlan (estate=0x141e540, planstate=0x141e8d0, 
    use_parallel_mode=false, operation=CMD_INSERT, sendTuples=false, 
    numberTuples=0, direction=ForwardScanDirection, dest=0x1419ff8, 
---Type  to continue, or q  to quit---
    execute_once=true) at execMain.c:1646
#10 0x00000000006a91b4 in standard_ExecutorRun (queryDesc=0x141d910, 
    direction=ForwardScanDirection, count=0, execute_once=true)
    at execMain.c:364
#11 0x00000000006a9059 in ExecutorRun (queryDesc=0x141d910, 
    direction=ForwardScanDirection, count=0, execute_once=true)
    at execMain.c:308
#12 0x000000000088016a in ProcessQuery (plan=0x1419f18, 
    sourceText=0x13606f0 "insert into test values(123,"abc");", params=0x0, 
    queryEnv=0x0, dest=0x1419ff8, completionTag=0x7ffd63e18570 "")
    at pquery.c:161
#13 0x00000000008818b1 in PortalRunMulti (portal=0x13c6490, isTopLevel=true, 
    setHoldSnapshot=false, dest=0x1419ff8, altdest=0x1419ff8, 
    completionTag=0x7ffd63e18570 "") at pquery.c:1283
#14 0x0000000000880eeb in PortalRun (portal=0x13c6490, 
    count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x1419ff8, 
    altdest=0x1419ff8, completionTag=0x7ffd63e18570 "") at pquery.c:796
#15 0x000000000087b27f in exec_simple_query (
    query_string=0x13606f0 "insert into test values(123,"abc");")
    at postgres.c:1215
#16 0x000000000087f2ff in PostgresMain (arGC=1, argv=0x138a5c8, 
    dbname=0x138a490 "postgres", username=0x138a478 "nail") at postgres.c:4247
#17 0x00000000007e6a8e in BackendRun (port=0x1382470) at postmaster.c:4437
#18 0x00000000007e628d in BackendStartup (port=0x1382470) at postmaster.c:4128
#19 0x00000000007e292d in ServerLoop () at postmaster.c:1704
#20 0x00000000007e21ed in PostmasterMain (argc=3, argv=0x135b1b0)
    at postmaster.c:1377
#21 0x000000000070f75d in main (argc=3, argv=0x135b1b0) at main.c:228

相关数据结构

代码流程涉及的PageHeader结构体已在之前了解过。postgresql源码学习(1)Page页

OffsetNumber
PageAddItemExtended(Page page,
					Item item,
					Size size,
					OffsetNumber offsetNumber,
					int flags);

PageAddItemExtended函数

// src/backend/storage/page/bufpage.c


limit = OffsetNumberNext(PageGetMaxOffsetNumber(page));


if (OffsetNumberIsValid(offsetNumber))
{
	if ((flags & PAI_OVERWRITE) != 0)
		
	else
		
}
else
{
	
}

if ((flags & PAI_IS_HEAP) != 0 && offsetNumber > MaxHeapTuplesPerPage)
	;



if (needshuffle)
	
	memmove(itemId + 1, itemId,
				(limit - offsetNumber) * sizeof(ItemIdData));


ItemIdSetNORMal(itemId, upper, size);


memcpy((char *) page + upper, item, size);




return offsetNumber;
您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL源码学习(2)插入数据#0

本文链接: https://lsjlt.com/news/5418.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作