【PostgreSQL在线创建索引(CIC)功能的锁分析以及使用注意】

前一篇文章提到了普通创建索引会阻塞DML操作

PostgreSQL创建索引的锁分析和使用注意

而PostgreSQL里可以使用create index concurrently 在线创建索引(CIC)功能,降低创建索引在表上申请的锁的级别,ShareUpdateExclusiveLock级别的锁和RowExclusiveLock不冲突,不会阻塞表上的DML操作。

1.1 在线创建索引(CIC)的原理

并发创建索引需要分多个步骤完成,首先在一个事务中将相关索引信息记录到系统表中,但是将索引信息标记为非法状态,然后需要进行两次扫描,并且在最后需要等待第二次扫描之前产生的所有具有快照信息的事务结束,最后修改索引的状态信息为可用。

1.插入元数据
|在系统表中插入索引的元数据,包括pg_class、pg_index,索引信息标记为非法状态(INVALID),然后开启两个事务,进行两次扫描2.第一次扫描|开启事务1,拿到当前snapshot1|扫描test_tab1表前,等待所有修改过test1表(写入、删除、更新)的事务结束|扫描test_tab1表,并建立中间状态的索引(INVALID)|结束事务12.第二次扫描|开启事务2,拿到当前snapshot2|再次扫描test_tab1表前,等待所有修改过test_tab1表(写入、删除、更新)的事务结束|在snapshot2之后启动的事务对test_tab1表执行的DML,会修改这个idx_1的索引|再次扫描test_tab1表,更新索引。(从tuple中可以拿到版本号,在snapshot1到snapshot2之间变更的记录,将其合并到索引)|上一步更新索引结束后,等待事务2之前开启的持有snapshot的事务结束|结束索引创建,索引可见

可以看到CREATE INDEX CONCURRENTLY在线创建索引(CIC)是需要借助snapshot去完成操作的,所以其实如果有长事务占用了快照,让它获取不到锁,那么创建的时间就会很长。

1.2 在线创建索引(CIC)操作在表上获取的锁(ShareUpdateExclusiveLock)

如之前测试的现象,在一张表上创建普通B-tree索引的时候,会阻塞这张表上进行的DML操作。PostgreSQL支持在线创建索引(CREATE INDEX CONCURRENTLY),不堵塞其他会话对被创建索引表的DML(INSERT,UPDATE,DELETE)操作。

postgres=# begin;
BEGIN
postgres=*# create index concurrently idx_111 on t1(id);
ERROR:  CREATE INDEX CONCURRENTLY cannot run inside a transaction block
postgres=!# 

而create index concurrently操作不能在一个显式开启的事务里执行,并且我自己的环境也比较有限,就不造数据模拟了,而是使用gdb在对应函数打上Breakpoint,进行分析。

(gdb) b LockAcquireExtended
Breakpoint 1 at 0xaaaab094d094: file lock.c, line 765.
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000aaaab094d094 in LockAcquireExtended at lock.c:765

image20240104175113090.png

(gdb) c
Continuing.Breakpoint 1, LockAcquireExtended (locktag=locktag@entry=0xffffc42c3f08, lockmode=lockmode@entry=1, sessionLock=sessionLock@entry=false, dontWait=dontWait@entry=false, reportMemoryError=reportMemoryError@entry=true, locallockp=locallockp@entry=0xffffc42c3f00) at lock.c:765
765     {
(gdb) bt
#0  LockAcquireExtended (locktag=locktag@entry=0xffffc42c3f08, lockmode=lockmode@entry=1, sessionLock=sessionLock@entry=false,dontWait=dontWait@entry=false, reportMemoryError=reportMemoryError@entry=true, locallockp=locallockp@entry=0xffffc42c3f00) at lock.c:765
#1  0x0000aaaab0949ffc in LockRelationOid (relid=3466, lockmode=1) at lmgr.c:117
#2  0x0000aaaab058c1a8 in relation_open (relationId=relationId@entry=3466, lockmode=lockmode@entry=1) at relation.c:56
#3  0x0000aaaab0aa3fb4 in BuildEventTriggerCache () at evtcache.c:130
#4  EventCacheLookup (event=<optimized out>, event@entry=EVT_SQLDrop) at evtcache.c:69
#5  0x0000aaaab07018c0 in trackDroppedObjectsNeeded () at event_trigger.c:1147
#6  EventTriggerBeginCompleteQuery () at event_trigger.c:1089
#7  0x0000aaaab096cd48 in ProcessUtilitySlow (pstate=pstate@entry=0xaaaac6004f58, pstmt=pstmt@entry=0xaaaac60827d0,queryString=queryString@entry=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);", context=context@entry=PROCESS_UTILITY_TOPLEVEL,params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, qc=qc@entry=0xffffc42c4ab8, dest=<optimized out>) at utility.c:1118
#8  0x0000aaaab096c0d4 in standard_ProcessUtility (pstmt=0xaaaac60827d0, queryString=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);",readOnlyTree=<optimized out>, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xaaaac6083000, qc=0xffffc42c4ab8) at utility.c:1078
#9  0x0000ffff90026270 in pgss_ProcessUtility (pstmt=0xaaaac60827d0, queryString=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);",readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xaaaac6083000, qc=0xffffc42c4ab8) at pg_stat_statements.c:1145
#10 0x0000aaaab096a6cc in PortalRunUtility (portal=portal@entry=0xaaaac6104e88, pstmt=pstmt@entry=0xaaaac60827d0, isTopLevel=isTopLevel@entry=true,setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8) at pquery.c:1158
#11 0x0000aaaab096a874 in PortalRunMulti (portal=portal@entry=0xaaaac6104e88, isTopLevel=isTopLevel@entry=true,setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xaaaac6083000, altdest=altdest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8)at pquery.c:1315
#12 0x0000aaaab096ae00 in PortalRun (portal=portal@entry=0xaaaac6104e88, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,run_once=run_once@entry=true, dest=dest@entry=0xaaaac6083000, altdest=altdest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8) at pquery.c:791
#13 0x0000aaaab0966768 in exec_simple_query (query_string=query_string@entry=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);")at postgres.c:1274
#14 0x0000aaaab0967648 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4637
#15 0x0000aaaab08c0514 in BackendRun (port=0xaaaac60b6c40, port=0xaaaac60b6c40) at postmaster.c:4464
#16 BackendStartup (port=0xaaaac60b6c40) at postmaster.c:4192
#17 ServerLoop () at postmaster.c:1782
#18 0x0000aaaab08c165c in PostmasterMain (argc=argc@entry=1, argv=argv@entry=0xaaaac5fe9d40) at postmaster.c:1466
#19 0x0000aaaab0578464 in main (argc=1, argv=0xaaaac5fe9d40) at main.c:198

image20240104175201418.png


上面停掉的第一个Breakpoint,其可以看一下调用到LockAcquireExtended的堆栈,relation_open (relationId=relationId@entry=3466, lockmode=lockmode@entry=1) at relation.c:56 这里oid对应是3466的并不是索引所在的表,而是系统表,因为创建索引过程也会访问系统表,开始连续几个停的断点的位置,打印的lockmode都是1,获取的都是AccessShareLock,也就是说这几个系统表都是进行了select的操作。这里我们就带着目的去看,继续让他往下跑,一直等到这个lockmode为4的时候,relation_open (relationId=relationId@entry=16725,因为我们创建索引的这张表tab_test_1,它对应的oid是16725。lockmode为4对应的就是ShareUpdateExclusiveLock。

postgres=# select oid,relname from pg_class where relname='tab_test_1';oid  |  relname
-------+------------16725 | tab_test_1
(1 row)
765     {
(gdb) c
Continuing.Breakpoint 1, LockAcquireExtended (locktag=locktag@entry=0xffffc42c3d78, lockmode=lockmode@entry=1, sessionLock=sessionLock@entry=false, dontWait=dontWait@entry=false, reportMemoryError=reportMemoryError@entry=true, locallockp=locallockp@entry=0xffffc42c3d70) at lock.c:765
765     {
(gdb) c
Continuing.Breakpoint 1, LockAcquireExtended (locktag=locktag@entry=0xffffc42c3fd8, lockmode=lockmode@entry=4, sessionLock=sessionLock@entry=false, dontWait=dontWait@entry=false, reportMemoryError=reportMemoryError@entry=true, locallockp=locallockp@entry=0xffffc42c3fd0) at lock.c:765
765     {
(gdb) bt
#0  LockAcquireExtended (locktag=locktag@entry=0xffffc42c3fd8, lockmode=lockmode@entry=4, sessionLock=sessionLock@entry=false,dontWait=dontWait@entry=false, reportMemoryError=reportMemoryError@entry=true, locallockp=locallockp@entry=0xffffc42c3fd0) at lock.c:765
#1  0x0000aaaab0949ffc in LockRelationOid (relid=relid@entry=16725, lockmode=lockmode@entry=4) at lmgr.c:117
#2  0x0000aaaab0672290 in RangeVarGetRelidExtended (relation=0xaaaac60825b8, lockmode=lockmode@entry=4, flags=flags@entry=0,callback=0xaaaab074e5d0 <RangeVarCallbackOwnsRelation>, callback_arg=callback_arg@entry=0x0) at namespace.c:390
#3  0x0000aaaab096d1f8 in ProcessUtilitySlow (pstate=pstate@entry=0xaaaac61ba098, pstmt=pstmt@entry=0xaaaac60827d0,queryString=queryString@entry=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);", context=context@entry=PROCESS_UTILITY_TOPLEVEL,params=params@entry=0x0, queryEnv=queryEnv@entry=0x0, qc=qc@entry=0xffffc42c4ab8, dest=<optimized out>) at utility.c:1486
#4  0x0000aaaab096c0d4 in standard_ProcessUtility (pstmt=0xaaaac60827d0, queryString=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);",readOnlyTree=<optimized out>, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xaaaac6083000, qc=0xffffc42c4ab8) at utility.c:1078
#5  0x0000ffff90026270 in pgss_ProcessUtility (pstmt=0xaaaac60827d0, queryString=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);",readOnlyTree=false, context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0xaaaac6083000, qc=0xffffc42c4ab8) at pg_stat_statements.c:1145
#6  0x0000aaaab096a6cc in PortalRunUtility (portal=portal@entry=0xaaaac6104e88, pstmt=pstmt@entry=0xaaaac60827d0, isTopLevel=isTopLevel@entry=true,setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8) at pquery.c:1158
#7  0x0000aaaab096a874 in PortalRunMulti (portal=portal@entry=0xaaaac6104e88, isTopLevel=isTopLevel@entry=true,setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xaaaac6083000, altdest=altdest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8)at pquery.c:1315
#8  0x0000aaaab096ae00 in PortalRun (portal=portal@entry=0xaaaac6104e88, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,run_once=run_once@entry=true, dest=dest@entry=0xaaaac6083000, altdest=altdest@entry=0xaaaac6083000, qc=qc@entry=0xffffc42c4ab8) at pquery.c:791
#9  0x0000aaaab0966768 in exec_simple_query (query_string=query_string@entry=0xaaaac6081b98 "create index concurrently idx_1 on tab_test_1(id);")at postgres.c:1274
#10 0x0000aaaab0967648 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at postgres.c:4637
#11 0x0000aaaab08c0514 in BackendRun (port=0xaaaac60b73e0, port=0xaaaac60b73e0) at postmaster.c:4464
#12 BackendStartup (port=0xaaaac60b73e0) at postmaster.c:4192
#13 ServerLoop () at postmaster.c:1782
#14 0x0000aaaab08c165c in PostmasterMain (argc=argc@entry=1, argv=argv@entry=0xaaaac5fe9d40) at postmaster.c:1466
#15 0x0000aaaab0578464 in main (argc=1, argv=0xaaaac5fe9d40) at main.c:198

image202401041820106884363613.png

s单步执行,然后p打印出变量的值

image202401041827194944364041.png

上面 *locktag里locktag_type是0,结合LockTagType的定义,第一个定义的enum值默认为0,后续的值在前一个定义值的基础上加1,可以知道是申请的LOCKTAG_RELATION,表锁。

/** The LOCKTAG struct is defined with malice aforethought to fit into 16* bytes with no padding.  Note that this would need adjustment if we were* to widen Oid, BlockNumber, or TransactionId to more than 32 bits.** We include lockmethodid in the locktag so that a single hash table in* shared memory can store locks of different lockmethods.*/
typedef struct LOCKTAG
{uint32		locktag_field1; /* a 32-bit ID field */uint32		locktag_field2; /* a 32-bit ID field */uint32		locktag_field3; /* a 32-bit ID field */uint16		locktag_field4; /* a 16-bit ID field */uint8		locktag_type;	/* see enum LockTagType */uint8		locktag_lockmethodid;	/* lockmethod indicator */
} LOCKTAG;
/** LOCKTAG is the key information needed to look up a LOCK item in the* lock hashtable.  A LOCKTAG value uniquely identifies a lockable object.** The LockTagType enum defines the different kinds of objects we can lock.* We can handle up to 256 different LockTagTypes.*/
typedef enum LockTagType
{LOCKTAG_RELATION,			/* whole relation */LOCKTAG_RELATION_EXTEND,	/* the right to extend a relation */LOCKTAG_DATABASE_FROZEN_IDS,	/* pg_database.datfrozenxid */LOCKTAG_PAGE,				/* one page of a relation */LOCKTAG_TUPLE,				/* one physical tuple */LOCKTAG_TRANSACTION,		/* transaction (for waiting for xact done) */LOCKTAG_VIRTUALTRANSACTION, /* virtual transaction (ditto) */LOCKTAG_SPECULATIVE_TOKEN,	/* speculative insertion Xid and token */LOCKTAG_OBJECT,				/* non-relation database object */LOCKTAG_USERLOCK,			/* reserved for old contrib/userlock code */LOCKTAG_ADVISORY			/* advisory user locks */
} LockTagType;

1.3 在线创建索引(CIC)被阻塞的案例(等待vxid)

//session 1:pid 557584
postgres=# begin;
BEGIN
postgres=*# select id from tab_test_2 for update;id
----1
(1 row)//session 2:pid 557784
postgres=# select id from tab_test_2 for update;
被阻塞//session 3:pid 558431
postgres=# create index concurrently idx_1 on tab_test_1(id);
被阻塞//session 4:(1)可以使用pg_blocking_pids查看被谁阻塞了
postgres=# select pg_blocking_pids('558431');pg_blocking_pids
------------------{557784}
(1 row)postgres=# select pg_blocking_pids('557784');pg_blocking_pids
------------------{557584}
(1 row)(2)也可以像下边查询锁的情况postgres=# select* from pg_lockswhere pid in('557584','557784','558431');locktype    | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid   |           mod
e           | granted | fastpath |           waitstart
---------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+--------+--------------
------------+---------+----------+-------------------------------virtualxid    |          |          |      |       | 5/309      |               |         |       |          | 5/309              | 558431 | ExclusiveLock| t       | t        |relation      |    13008 |    24929 |      |       |            |               |         |       |          | 4/46               | 557784 | RowShareLock| t       | t        |relation      |    13008 |    24929 |      |       |            |               |         |       |          | 3/202              | 557584 | RowShareLock| t       | t        |virtualxid    |          |          |      |       | 3/202      |               |         |       |          | 3/202              | 557584 | ExclusiveLock| t       | t        |transactionid |          |          |      |       |            |          1719 |         |       |          | 3/202              | 557584 | ExclusiveLock| t       | f        |virtualxid    |          |          |      |       | 4/46       |               |         |       |          | 5/309              | 558431 | ShareLock| f       | f        | 2024-01-05 13:37:45.5214+08relation      |    13008 |    24925 |      |       |            |               |         |       |          | 5/309              | 558431 | ShareUpdateEx
clusiveLock | t       | f        |tuple         |    13008 |    24929 |    0 |     1 |            |               |         |       |          | 4/46               | 557784 | AccessExclusi
veLock      | t       | f        |transactionid |          |          |      |       |            |          1719 |         |       |          | 4/46               | 557784 | ShareLock| f       | f        | 2024-01-05 13:37:42.613288+08virtualxid    |          |          |      |       | 4/46       |               |         |       |          | 4/46               | 557784 | ExclusiveLock| t       | f        |
(10 rows)

image2024010514013910044345004434501.png

"virtualxid"和"virtualtransaction"从字面上看都是虚拟事务ID的意思。它们的区别是:位于pg_locks视图的不同部分,"virtualxid"位于描述锁对象的部分, "virtualtransaction"位于描述持有锁或等待锁的部分。因此,"virtualxid"表示这个锁对象是一个虚拟事务,而"virtualtransaction"表示持有锁或等待锁的虚拟事务ID。

通过上图可以看出, 5/309是建索引本身的vxid,建索引需要等老事务结束,所以用vxid等另外一个会话结束,可以看到最后一行在请求别人的vxid 4/46。而这个vxid 4/46刚好是pid为557584的会话持有的,所以这个阻塞不是等待获取表上的锁,是在等待vxid的锁。

使用pstack 看一下现在被阻塞的这个会话的堆栈

root@ubuntu-linux-22-04-desktop:~# pstack 558431
#0  0x0000ffff8faf5ea8 in epoll_pwait () from /lib/aarch64-linux-gnu/libc.so.6
#1  0x0000aaaae03e778c in WaitEventSetWait ()
#2  0x0000aaaae03e7b30 in WaitLatch ()
#3  0x0000aaaae040b428 in ProcSleep ()
#4  0x0000aaaae03fc064 in WaitOnLock ()
#5  0x0000aaaae03fd410 in LockAcquireExtended ()
#6  0x0000aaaae0400f54 in VirtualXactLock ()
#7  0x0000aaaae01c93b4 in WaitForOlderSnapshots ()
#8  0x0000aaaae01cd930 in DefineIndex ()
#9  0x0000aaaae041d270 in ProcessUtilitySlow.constprop.0 ()
#10 0x0000aaaae041c0d4 in standard_ProcessUtility ()
#11 0x0000ffff8f426270 in pgss_ProcessUtility () from /home/postgres/soft-16/lib/pg_stat_statements.so
#12 0x0000aaaae041a6cc in PortalRunUtility ()
#13 0x0000aaaae041a874 in PortalRunMulti ()
#14 0x0000aaaae041ae00 in PortalRun ()
#15 0x0000aaaae0416768 in exec_simple_query ()
#16 0x0000aaaae0417648 in PostgresMain ()
#17 0x0000aaaae0370514 in ServerLoop ()
#18 0x0000aaaae037165c in PostmasterMain ()
#19 0x0000aaaae0028464 in main ()

DefineIndex()主要是处理索引创建的逻辑,而常规锁的申请主要在接口 LockAcquire() 和 LockAcquireExtended()中实现。可以看到堆栈的最后处于等待的状态。

image202401051427100754436032.png

可以看一下其中的变量,这个relationId=24925对应的对象就是我们要创建的索引所在的表,而对应的locktag_type = 6,结合LockTagType的定义,可以知道这个6代表的是LOCKTAG_VIRTUALTRANSACTION,对virtual transaction申请锁,锁是5级,表示ShareLock,看到是不是有疑问了,之前说CIC的锁相对于普通的建立索引降低了一个级别,变成了4级锁,但是这里是5级锁,其实是不一样的,这块获取的锁的locktag_type并不是针对relation的,而是针对virtual transaction的,源码注释里关于常规锁模式解析部分的也是针对于relation的。

image202401051433428504436424.png

postgres=# select '24925'::regclass;regclass
------------tab_test_1
(1 row)

所以真正CIC过程表上的锁,应该找到一个relation oid=24925,LockAcquireExtended()函数执行过程locktag->locktag_type为0时,再查看lockmode的值。这里再次重新用gdb打上一个breakpoint,抓到了表上申请的锁,果然是4级锁,即ShareUpdateExclusiveLock。

image202401051509166864438558.png

1.4 在线创建索引(CIC)操作的可能遇到的问题

PostgreSQL支持在线创建索引(CREATE INDEX CONCURRENTLY),不堵塞其他会话对被创建索引表的DML(INSERT,UPDATE,DELETE)操作,所以有时候为了不阻塞业务,采用CIC,而不是使用普通创建索引的方式。

问题:

1.执行速度慢

​ 从在线创建索引(CIC)的实现机制上可以看出,它需要两次扫描表。所以不考虑锁阻塞的情况下它的执行时间可能会比正常创建索引慢很多。

2.执行失败后可能存在INVALID索引

​ 因为第一次扫描并建立中间状态的索引(INVALID)后,索引实际上就对后面的DML起作用了,所以如果是在第二SCAN阶段,索引创建失败了,这个索引会一直影响DML(性能、约束)。

3.冲突,不允许同时执行

create index concurrently 在线创建索引(CIC)功能无法并发执行,因为这个操作在表上上的是ShareUpdateExclusiveLock锁,四级锁,自斥。

解决方法:

第一个问题:

​ 扫描两次表的这个问题,是其本身机制的问题,只能尽量选取在业务不忙的时候,除此之外,尽量避免阻塞情况:

  1. 尽量避免创建索引过程中,两次SCAN之前对被创建索引表实施长事务,并且长事务中包含修改被创建索引的表。
  2. 在第二次SCAN前,尽量避免开启长事务。

第二个问题:

​ 因为CIC的实现机制问题,如果索引创建失败后,可能会留下一个失效索引。失效索引不能被使用,而且在进行DML的时候,也会一并进行更改,浪费主机资源。可以查看pg_index视图的indisvalid字段。如果为真,此索引当前可以用于查询,为假表示此索引可能不完整,需要进行处理,根据需求重建或者删除掉。

第三个问题:

​ 注意不要多个session同时对一张表做create index concurrently操作,以防冲突。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/334794.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

框架技术与应用开发期末速成

spring Spring简介 Spring是个java企业级应用的开源开发框架。Spring主要用来开发web应用是一个轻量级的控制反转(IOC)和面向切面(AOP)的容器框架。 Spring体系结构 核心容器: Core模块 提供了框架的基本组成部分&#xff0c;包括TOC和依赖注入功能 Beans模块 提供 BeanFacto…

忆阻器芯片STELLAR权重更新算法(清华大学吴华强课题组)

参考文献&#xff08;清华大学吴华强课题组&#xff09; Zhang, Wenbin, et al. “Edge learning using a fully integrated neuro-inspired memristor chip.” Science 381.6663 (2023): 1205-1211. STELLAR更新算法原理 在权值更新阶段&#xff0c;只需根据输入、输出和误差…

扩展学习|数据融合助推商务智能与分析

文献来源&#xff1a;[1]李爱华,续维佳,石勇.基于数据融合的商务智能与分析架构研究[J].计算机科学,2022,49(12):185-194. 一、信息融合 &#xff08;一&#xff09;信息融合定义演变 早期信息融合的定义指出&#xff0c;其主要任务是综合分析若干传感器观测到的信息[9,…

[开源]万界星空开源MES系统,支持低代码大屏设计

一、开源系统概述&#xff1a; 万界星空科技免费MES、开源MES、商业开源MES、商业开源低代码MES、市面上最好的开源MES、MES源代码、免费MES、免费智能制造系统、免费排产系统、免费排班系统、免费质检系统、免费生产计划系统、精美的数据大屏。 二、开源协议&#xff1a; 使…

番外篇 中国古代的操 作系统

番外篇中国古代的操作系统 在古代中国&#xff0c;仿佛已经存在一套古老而神秘的操作系统机制。 这个东方国度中&#xff0c;有一位名叫小李子的忙碌人物&#xff0c;他的工作就如同是执行各种指令的“人肉CPU”。 这个国家还有一个特殊的人物&#xff0c;即皇帝&#xff0c;他…

ArrayBlockingQueue原理探究

类图结构 同样&#xff0c;为了能从全局一览ArrayBlockingQueue的内部构造&#xff0c;先来看它的类图。 ArrayBlockingQueue的内部有一个数组items,用来存放队列元素&#xff0c;putindex变量表示入队元素下标&#xff0c;takelndex是出队下标&#xff0c;count统计队列元素个…

Qt应用-实现图像截取功能类似QQ上传头像截取功能

本文演示利用Qt实现图像截取功能类似QQ上传头像截取功能。 效果如下,通过移动中间的裁剪区域可以获得一张裁剪后的图片。 目录

【uniapp】遇到的一些问题

一、小程序中textarea ios样式不生效的方法 默认有内边距&#xff0c;加个disable-default-padding"true" 二、uni-data-picker循环使用&#xff0c;一个改了全局的值 换成了uni自带的picker&#xff0c;下面括号里必须有默认值&#xff0c;为空字符串的时候&…

AI数字人虚拟现实产业的发展现状与展望

AI数字人虚拟现实产业是当今科技领域备受瞩目的发展方向之一。随着人工智能和虚拟现实技术的迅猛发展&#xff0c;人们对于数字形象的需求不断增加&#xff0c;AI数字人虚拟现实产业正应运而生。本文将从产业现状和未来展望两个方面来描绘AI数字人虚拟现实产业的发展。 首先&a…

二刷Laravel 教程(用户注册)总结Ⅳ

一、显示用户信息 1&#xff09;resource Route::resource(users, UsersController); 相当于下面这7个路由 我们先用 Artisan 命令查看目前应用的路由&#xff1a; php artisan route:list 2&#xff09; compact 方法 //我们将用户对象 $user 通过 compact 方法转化为一个关联…

2024年,前端必会的console骚操作

调试。程序员们努力地避免的东西,只为在代码中制造更多的错误。 编写无错误的代码是即使是最好的程序员也会觉得难以实现的。这就是为什么你应该总是调试代码。 而调试JavaScript代码的最好方法之一就是了不起的console.log()。除此之外,还有更好的方法。 这也正是本文的重点…

java CAS

CAS 在高并发场景&#xff0c;可以使用加锁 或者CAS来保证原子性&#xff0c;但是加锁是很重量级的操作&#xff0c;CAS类似于乐观锁CAS &#xff08; Compare and swap &#xff09;比较并交换&#xff0c;是实现并发算法时常用到的技术&#xff0c;包含三个操作数&#xff1…