No More ANALYZE After CREATE INDEX in YugabyteDB 2025.2

TL;DR
Starting in 2025.2.0.0 (and backported to 2025.1.3.0), YugabyteDB automatically updates pg_class.reltuples for both the base table and newly created index after CREATE INDEX.
No more mandatory ANALYZE just to fix index row counts.

📉 Behavior in Older Versions (Example: 2024.2.7.1)

Check version:

				
					SELECT split_part(version(), '-', 3) AS "YB Version";
				
			

Result:

				
					2024.2.7.1
				
			

Create table and insert rows:

				
					CREATE TABLE xxx (k1 INT PRIMARY KEY, v INT);

INSERT INTO xxx VALUES (1,2);
INSERT INTO xxx VALUES (3,4);
				
			

Check pg_class:

				
					SELECT relname, relkind, reltuples
FROM pg_class
WHERE relkind IN ('r','p','m','i')
AND relname LIKE '%xxx%';
				
			

Result:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         0
 xxx_pkey | i       |         0
				
			
Run ANALYZE:
				
					ANALYZE xxx;
				
			

Now:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         2
 xxx_pkey | i       |         2
				
			

Create a secondary index:

				
					CREATE INDEX i_xxx_v ON xxx (v);
				
			

Check again:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         2
 xxx_pkey | i       |         2
 i_xxx_v  | i       |         0 <--Incorrect
				
			

Only after:

				
					ANALYZE xxx;
				
			

Do we finally get:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         2
 xxx_pkey | i       |         2
 i_xxx_v  | i       |         2 <--Correct
				
			

🚀 New Behavior in 2025.2.0.0+

Check version:

				
					SELECT split_part(version(), '-', 3) AS "YB Version";
				
			

Result:

				
					2025.2.0.0
				
			

Check the new GUC

				
					SELECT setting, short_desc
FROM pg_settings
WHERE name = 'yb_enable_update_reltuples_after_create_index';
				
			

Result:

				
					 .setting |                                                                                                                     short_desc
---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 on      | Enables update of reltuples in pg_class for the base table and index after creating the index. When disabled, reltuples are not updated during concurrent index creation and only index reltuples are updated during non-concurrent index creation.

				
			
🧪 Same Demo – New Result

Create table and insert rows:

				
					CREATE TABLE xxx (k1 INT PRIMARY KEY, v INT);

INSERT INTO xxx VALUES (1,2);
INSERT INTO xxx VALUES (3,4);
				
			

Before ANALYZE:

				
					SELECT relname, relkind, reltuples
FROM pg_class
WHERE relkind IN ('r','p','m','i')
AND relname LIKE '%xxx%';
				
			

Result:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |        -1
 xxx_pkey | i       |         0
				
			

Run:

				
					ANALYZE xxx;
				
			

Now:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         2
 xxx_pkey | i       |         2
				
			

Create index:

				
					CREATE INDEX i_xxx_v ON xxx (v);
				
			

Immediately check:

				
					SELECT relname, relkind, reltuples
FROM pg_class
WHERE relkind IN ('r','p','m','i')
AND relname LIKE '%xxx%';
				
			

Result:

				
					.relname  | relkind | reltuples
----------+---------+-----------
 xxx      | r       |         2
 xxx_pkey | i       |         2
 i_xxx_v  | i       |         2 <-- Automatically updated
				
			
What Changed?
  • ● Base table reltuples is updated automatically
  • ● New index reltuples is updated immediately
  • ● No extra ANALYZE required
  • ● System catalog statistics stay accurate after CREATE INDEX

🏁 Conclusion

Sometimes the most impactful improvements aren’t flashy new features… they’re the ones that quietly remove friction.

For years, creating an index in YugabyteDB meant remembering to run an extra ANALYZE if you wanted pg_class.reltuples to reflect reality. It wasn’t a bug. It wasn’t broken. But it was one more operational step DBAs had to account for.

With 2025.2.0.0 (and 2025.1.3.0), that extra step is gone.

CREATE INDEX now leaves the catalog in a correct and consistent state immediately.

It’s a small tweak, but it makes YugabyteDB feel just a little more intuitive… and those kinds of refinements add up over time.

Have Fun!

As part of our big move, my wife asked me to go through old photos and toss the ones we don’t need anymore. I almost threw this one out... little me and all. But I couldn’t come up with a good caption… so naturally, I asked AI to analyze the photo instead. 😄