๐Ÿš€ YugabyteDB ์ง€์—ญ ๋ถ„ํ•  ํ…Œ์ด๋ธ”์—์„œ๋งŒ ๋กœ์ปฌ ํŒŒํ‹ฐ์…˜์— ์•ก์„ธ์Šค

24540 ๋‹จ์–ด distributedyugabyteddatabasesql
์ด ๊ฒŒ์‹œ๋ฌผ์€ ํŒŒํ‹ฐ์…˜ ํ‚ค ์—†์ด ๋กœ์ปฌ ํŒŒํ‹ฐ์…˜์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ–ˆ๋˜ ์ด์ „ ๊ฒŒ์‹œ๋ฌผ์˜ ์—ฐ์†์ž…๋‹ˆ๋‹ค. ์ €๋Š” ํ™”์„ฑ์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์—ˆ๊ณ  ๊ณ ๊ฐ85338353-162a-4a62-bcb9-78fd58a6b500์€ ๊ทธ๊ณณ์— ์žˆ์—ˆ์ง€๋งŒ 1c888089-c4f2-4da4-ba61-59957b965bf8๋Š” ์ง€๊ตฌ์—์„œ ์™”์Šต๋‹ˆ๋‹ค.

yugabyte=# select planet,id from customers 
where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500');

 planet |                  id
--------+--------------------------------------
 earth  | 1c888089-c4f2-4da4-ba61-59957b965bf8
 mars   | 85338353-162a-4a62-bcb9-78fd58a6b500
(2 rows)


์ค‘๋ณต ์ปค๋ฒ„๋ง ์ธ๋ฑ์Šค ๋•๋ถ„์— ์ด ์ฟผ๋ฆฌ๋Š” ๋กœ์ปฌ ์ฝ๊ธฐ๋กœ๋งŒ ๋‹ฌ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

yugabyte=# explain analyze select planet,id from customers 
where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500');




๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ์ƒ‰์ธ์„ ์‚ญ์ œํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

drop index customers_moon_id_planet_earth;
drop index customers_mars_id_planet_earth;
drop index customers_earth_id_planet_moon;
drop index customers_mars_id_planet_moon;
drop index customers_earth_id_planet_mars;
drop index customers_moon_id_planet_mars;


์ด์ œ ๋™์ผํ•œ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋ชจ๋“  ์ง€์—ญ์—์„œ ํŒŒํ‹ฐ์…˜์„ ์ฝ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

yugabyte=# explain analyze select planet,id from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500');
                                                                          yugabyte=# explain analyze select planet,id from customers
yugabyte-#            where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500');
                                                                   QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..46.65 rows=300 width=48) (actual time=1.798..5.347 rows=2 loops=1)
   ->  Index Scan using customers_earth_pkey on customers_earth  (cost=0.00..14.65 rows=100 width=48) (actual time=1.798..1.800 rows=1 loops=1)
         Index Cond: (id = ANY ('{1c888089-c4f2-4da4-ba61-59957b965bf8,85338353-162a-4a62-bcb9-78fd58a6b500}'::uuid[]))
   ->  Index Scan using customers_mars_pkey on customers_mars  (cost=0.00..15.25 rows=100 width=48) (actual time=1.073..1.075 rows=1 loops=1)
         Index Cond: (id = ANY ('{1c888089-c4f2-4da4-ba61-59957b965bf8,85338353-162a-4a62-bcb9-78fd58a6b500}'::uuid[]))
   ->  Index Scan using customers_moon_pkey on customers_moon  (cost=0.00..15.25 rows=100 width=48) (actual time=2.469..2.469 rows=0 loops=1)
         Index Cond: (id = ANY ('{1c888089-c4f2-4da4-ba61-59957b965bf8,85338353-162a-4a62-bcb9-78fd58a6b500}'::uuid[]))
 Planning Time: 19.236 ms
 Execution Time: 5.876 ms
 Peak Memory Usage: 64 kB
(10 rows)
)




์ด์ œ ์ด์ „ ๊ฒŒ์‹œ๋ฌผ์—์„œ ์ง€์—ญ์„ ์•Œ๋ฉด ๋ชจ๋“  SQL ์ฒ˜๋ฆฌ๊ฐ€ ๋กœ์ปฌ์ด ๋˜๋„๋ก ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ๋‚ด ๋Œ€์•ˆ์€ ๊ณ ๊ฐ์ด ๋กœ์ปฌ ํŒŒํ‹ฐ์…˜์— ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ ์›๊ฒฉ ์ฝ๊ธฐ๋ฅผ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์ง€๋งŒ ๋‹ค๋ฅธ ์ง€์—ญ์— ์—ฐ๊ฒฐํ•˜์—ฌ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

yb_is_local_table



YugabyteDB์—๋Š” ๋กœ์ปฌ ํŒŒํ‹ฐ์…˜์œผ๋กœ๋งŒ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ๋Š” ํŠน์ˆ˜ ๊ธฐ๋Šฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

yugabyte=# select * from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500')
           and yb_is_local_table(tableoid);

                  id                  | planet | info
--------------------------------------+--------+------
 85338353-162a-4a62-bcb9-78fd58a6b500 | mars   | 42
(1 row)


์ด๊ฒƒ์€ ํ˜„์ง€ ๊ณ ๊ฐ ๋งŒ ๋ฐ˜ํ™˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

yugabyte=# explain analyze select * from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500')
           and yb_is_local_table(tableoid);
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..15.65 rows=100 width=80) (actual time=1.715..1.719 rows=1 loops=1)
   ->  Index Scan using customers_mars_pkey on customers_mars  (cost=0.00..15.15 rows=100 width=80) (actual time=1.715..1.718 rows=1 loops=1)
         Index Cond: (id = ANY ('{1c888089-c4f2-4da4-ba61-59957b965bf8,85338353-162a-4a62-bcb9-78fd58a6b500}'::uuid[]))
         Filter: yb_is_local_table(tableoid)
 Planning Time: 0.338 ms
 Execution Time: 1.792 ms
 Peak Memory Usage: 32 kB
(7 rows)




์ด ๊ณ ๊ฐ์„ ์ฒ˜๋ฆฌํ•œ ๋‹ค์Œ ์ •ํ™•ํžˆ ๋™์ผํ•œ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด์„œ ๋‹ค๋ฅธ ๊ณณ์— ์—ฐ๊ฒฐํ•˜์—ฌ ๋‹ค๋ฅธ ๊ณ ๊ฐ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์€ ์˜ˆ์ž…๋‹ˆ๋‹ค.

yugabyte=# \c yugabyte yugabyte yb-tserver-2
You are now connected to database "yugabyte" as user "yugabyte".
yugabyte=# select * from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500')
           and yb_is_local_table(tableoid);
                  id                  | planet | info
--------------------------------------+--------+------
 85338353-162a-4a62-bcb9-78fd58a6b500 | mars   | 42
(1 row)

yugabyte=# \c yugabyte yugabyte yb-tserver-1
You are now connected to database "yugabyte" as user "yugabyte" on host "yb-tserver-1" at port "5433".
yugabyte=# select * from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500')
           and yb_is_local_table(tableoid);
 id | planet | info
----+--------+------
(0 rows)

yugabyte=# \c yugabyte yugabyte yb-tserver-0
You are now connected to database "yugabyte" as user "yugabyte" on host "yb-tserver-0" at port "5433".
yugabyte=# select * from customers
           where id in ('1c888089-c4f2-4da4-ba61-59957b965bf8','85338353-162a-4a62-bcb9-78fd58a6b500')
           and yb_is_local_table(tableoid);
                  id                  | planet | info
--------------------------------------+--------+------
 1c888089-c4f2-4da4-ba61-59957b965bf8 | earth  | 42
(1 row)




๊ทธ๋ž˜์„œ ์ด๊ฒƒ์€ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ง€๋ฆฌ์ ์œผ๋กœ ๋ถ„ํ• ๋œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ๋Š” ํ•œ ์ง€์—ญ์— ์—ฐ๊ฒฐํ•˜๊ณ  ์ž‘์—…ํ•ฉ๋‹ˆ๋‹ค. ์ง€์—ญ์„ ๋ชจ๋ฅธ๋‹ค๋ฉด ์ด์ „ ๊ฒŒ์‹œ๋ฌผ์—์„œ ์ธ๋ฑ์Šค๋กœ ์ง€๋„๋ฅผ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ต์ฐจ ์ง€์—ญ ์ž‘์—… ๋˜๋Š” ๋ณด๊ณ ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ๊ฐ ์ง€์—ญ์œผ๋กœ ์ด๋™ํ•˜์—ฌ ์ง€์—ญ์„ ์ฒ˜๋ฆฌ/๋ณด๊ณ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์ง€๋งŒ yb_is_local_table(tableoid) ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ