Primary Key options for Partitioned Tables

  Рет қаралды 1,520

SQL and Database explained!

SQL and Database explained!

Күн бұрын

Пікірлер: 36
@ricardooberdanpereira793
@ricardooberdanpereira793 2 ай бұрын
How one person can know so much about? Thanks again Connor.
@fransc2086
@fransc2086 2 ай бұрын
Great explanation! Thanks!
@DatabaseDude
@DatabaseDude 2 ай бұрын
Glad it was helpful!
@marcinbadtke
@marcinbadtke 2 ай бұрын
Thank you. Fantastic idea.
@DatabaseDude
@DatabaseDude 2 ай бұрын
Glad you liked it!
@ErickTruter
@ErickTruter 2 ай бұрын
Great video! Partitions is great but I find often people don't understand the costs involved in using them and often don't use them correctly causing all partition scans.
@DatabaseDude
@DatabaseDude 2 ай бұрын
Very true!
@gleytonr
@gleytonr 2 ай бұрын
Thanks so much
@DatabaseDude
@DatabaseDude 2 ай бұрын
You're welcome!
@dhirajtagadapallewar8475
@dhirajtagadapallewar8475 2 ай бұрын
Very nicely explained. Please provide commands to try in test environment
@vikram4755
@vikram4755 2 ай бұрын
Wow !
@ilpaolotopleggend6663
@ilpaolotopleggend6663 2 ай бұрын
Thanks !super video super issue super explanation
@DatabaseDude
@DatabaseDude 2 ай бұрын
Welcome 😊
@zhekappp
@zhekappp Ай бұрын
There is another possibly better approach besides creating additional table which requires some extra maintenance. If the ID column contents will be always inserted like number YYYYDDDnnnnnnnnnnnnnnnnnnnnnnnnnn where YYYYDDD is date for pr_date and nnnn part is just regular sequence we can partition the table based on ID column instead and enable local PK. This will require application logic to adjust queries to use 'parametrized view' which will transform pr_date to the value looking same way as PK for the where condition for partition pruning when fetching not by PK.
@DatabaseDude
@DatabaseDude Ай бұрын
True, but the data modellers of the world will be up an arms about embedding information within a column :-)
@zhekappp
@zhekappp Ай бұрын
​@@DatabaseDude well, denormalization by propagating the date value to all the child tables seems worse to me.
@AnujSingh-vo7pf
@AnujSingh-vo7pf Ай бұрын
Hi Connor 08:15:40 SQL> select ORPHANED_ENTRIES ,status from dba_indexes where index_name='T_PAR_PK'; ORP STATUS --- -------- NO VALID Elapsed: 00:00:00.00 08:14:09 SQL> alter table t_par drop partition p3 update indexes; Table altered. Elapsed: 00:00:19.57 08:15:40 SQL> select ORPHANED_ENTRIES ,status from dba_indexes where index_name='T_PAR_PK'; ORP STATUS --- -------- NO VALID Elapsed: 00:00:00.00 Why aren't there any ORPHANED_ENTRIES in the index ?
@DatabaseDude
@DatabaseDude Ай бұрын
because you said "update indexes".
@AnujSingh-vo7pf
@AnujSingh-vo7pf Ай бұрын
@@DatabaseDude please check video again at 5:46 alter table t_par drop partition p3 update indexes; at 5:59 YES
@QueryTuner
@QueryTuner Ай бұрын
@@AnujSingh-vo7pf Did you populate the table partitions with some data ? If there is no data in them, then there will also no orphaned entries in the index.
@AnujSingh-vo7pf
@AnujSingh-vo7pf Ай бұрын
@@QueryTuner create table t_par partition by range (par_date) interval ( numtodsinterval(14,'DAY')) ( partition p1 values less than ( date '2024-05-01' ), partition p2 values less than ( date '2024-05-15' ), partition p3 values less than ( date '2024-05-31' ), partition p4 values less than ( date '2024-06-15' ), partition p5 values less than ( date '2024-06-30' ), partition p6 values less than ( date '2024-07-15' ), partition p7 values less than ( date '2024-07-31' ) ) as select rownum pk,date '2024-04-20' +trunc(rownum/370000) par_date, d.* from dba_objects d, (select 1 from dual connect by level exec dbms_stats.gather_table_stats('','T_PAR'); SQL> exec dbms_stats.gather_table_stats('','T_PAR'); PL/SQL procedure successfully completed. SQL> select num_rows from dba_tables where table_name='T_PAR' ; NUM_ROWS ---------- 28455200 SQL> select count(*) from T_PAR ; COUNT(*) ---------- 28455200 SQL> set linesize 500 pagesize 300 col TABLE_NAME for a20 col PARTITION_NAME for a20 col HIGH_VALUE for a80 SELECT table_name, partition_name, num_rows,high_value FROM dba_tab_partitions WHERE table_name='T_PAR' ORDER BY 1,2; SQL> create unique index t_par_pk on t_par(pk) parallel 8; Index created. SQL> SQL> alter index t_par_pk noparallel ; Index altered. SQL> alter table t_par add constraint t_par_pk primary key ( pk ) using index ; Table altered. SQL> select partitioned from dba_indexes where index_name='T_PAR_PK'; PAR --- NO
@AnujSingh-vo7pf
@AnujSingh-vo7pf Ай бұрын
@DatabaseDude
@ppaolucc
@ppaolucc 2 ай бұрын
Hi Connor, maybe I'm a bit wrong, however: if we would create a global partitioned index (I've seen here a creation of a Global non-partitioned one) we would be able to do partition pruning, even though an maintenance action on partitions (MOVE, DROP, SPLIT, TRUNCATE) would affect the validity of the entire index as well, correct? Thank you
@DatabaseDude
@DatabaseDude 2 ай бұрын
With older versions yes - no we have the ability to mark "parts" of the index not usable
@Xavier-jf3zf
@Xavier-jf3zf 10 күн бұрын
And what about this approach: partition the table by range(pk), and use zone maps (for pruning by par_date). And optionally subpartition by par_date ?
@DatabaseDude
@DatabaseDude 9 күн бұрын
defintely an option, but zone maps are limited to engineered systems
@steveandreassend8620
@steveandreassend8620 Ай бұрын
Surely there is a case to make option 3 native to the product so it is all transparent? It seems to be the only elegant solution for this problem.
@steveandreassend8620
@steveandreassend8620 Ай бұрын
ALTER TABLE x TRACK PRIMARY KEY PARTITION; and do some sort of background predicate appending like RLS / VPD does.
@DatabaseDude
@DatabaseDude Ай бұрын
I certainly like the concept of that being a declarative part of the database
How Wait Events work in the Multi-tenant world
4:46
SQL and Database explained!
Рет қаралды 1,3 М.
Simple steps to Faster Database Code
15:46
SQL and Database explained!
Рет қаралды 2,8 М.
Andro, ELMAN, TONI, MONA - Зари (Official Audio)
2:53
RAAVA MUSIC
Рет қаралды 8 МЛН
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
SQL Tutorial for Beginners
44:57
Kevin Stratvert
Рет қаралды 2,3 МЛН
Which rows are locked in my database?
7:15
SQL and Database explained!
Рет қаралды 1,4 М.
How would you design a database on Object Storage?
1:08:27
The Geek Narrator
Рет қаралды 3,1 М.
Advent of Code 2024 Day 13 Python (Mathematical Approach)
21:24
Software Dev James
Рет қаралды 30
Table size EXPLODES after partitioning!
56:23
Oracle Developers
Рет қаралды 686
Postgres Table Partitioning, Ryan Booz @ Redgate presenting
43:49
United States PostgreSQL Association
Рет қаралды 162
you need to learn SQL RIGHT NOW!! (SQL Tutorial for Beginners)
24:25
NetworkChuck
Рет қаралды 1,6 МЛН
Blasting past the 1000-item limit for IN-LIST
8:09
SQL and Database explained!
Рет қаралды 1,1 М.
The Correct Way to Run Database Migrations in EF Core
19:51
Nick Chapsas
Рет қаралды 36 М.
Andro, ELMAN, TONI, MONA - Зари (Official Audio)
2:53
RAAVA MUSIC
Рет қаралды 8 МЛН