Skip to content

Commit

Permalink
sql: use IndexFetchSpec in JoinReader
Browse files Browse the repository at this point in the history
This commit changes `JoinReader` to use an `IndexFetchSpec` (plus a
list of family IDs for span splitting) instead of table and index
descriptors.

As part of making this switch, the "internal schema" of the processor
no longer contains all table columns; instead it contains the specific
`FetchedColumns` in the spec. This simplifies both planning and
execution code.

Release note: None
  • Loading branch information
RaduBerinde committed Feb 24, 2022
1 parent 29a5992 commit 170d49c
Show file tree
Hide file tree
Showing 37 changed files with 570 additions and 711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ vectorized: true
table: orders@orders_pkey
spans: [/'ap-southeast-2'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727' - /'ap-southeast-2'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727'] [/'us-east-1'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727' - /'us-east-1'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727']
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9tO20AQhu_7FKO54aCNEh8gwRKSEU1pUBpoQtVK3Sgy3glsSXbd3bWaCuWqz9b3quyFUqMGCdoLew8z_8x8v-xbtF8XmGD_0_nwaDCC7deDycXk_XAHJv1h__gCtBFkZlIwKIxe6rudzAmOJn4z-ybdtS7drE64j-6CkDbXpXLNRJ8Fb8Zn73xtC6dng5GvbuHDZDA6ge37Xjvw8W1_3P89BRzC1kFM8WUv7rZ683DeirN8r9WL5kFrPw7EPkVi3g27W8hQaUGjbEkWk88Y45RhYXRO1mpTXd3WCQOxwqTDUKqidNX1lGGuDWFyi066BWGCF9nlgsaUCTLtDjIU5DK5qMt6gtQvs-KGviPDY70ol8omDe9kTg8WIsNJkVUpbY4pxzZHzlcHMecrql6XvRPOV715-_TnD85X80BwvgqEOqwO3S2O7Q5kSkAA2l2TwemaoS7dA4J12RVhEqzZyzCD_49ZAXVehLoRL9yI90BlychsAaWqpyTRAJuu_-LDSLd00Q6bDgzlUjoINo7SeY7Tp1qqO6OjZhv_F6R-uTd6qPVNWcAXLRVolUBaicakBJkE0oBBGjFIw-rZTfc2jhg9Z8Qx2UIrS4_s2gQ_ZUjiirz1Vpcmp3Oj87qNP57VuvpCkHU-GvrDQNWh-mv9Uxz8izh8Uhw1xJ3H4uhJcfxIPF2_-hUAAP__SGy-Yw==
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9tO20wQx--_pxjNDQdtlPgACZaQjPhSGpQGmlC1UjeKjHcCW5Jdd3etpkK56rP1vSp7SUNQgwTthb2n-e_M72_PPdqvM0yw--myf9IbwO7_vdHV6H1_D0bdfvf0CrQRZCZSMCiMnuuHmcwJTkZ-Mvkm3a0u3aQOWJ3ug5A216Vym4E-Ct4ML975uy2cX_QG_nYLH0a9wRnsrnLtwce33WH3dxVwDDtHMcXXnbjd6EzDaSPO8oNGJ5oGjcM4EIcUiWk7bO8gQ6UFDbI5WUw-Y4xjhoXROVmrTbV1Xwf0xAKTFkOpitJV22OGuTaEyT066WaECV5l1zMaUibINFvIUJDL5Ky-1hOkfpgUd_QdGZ7qWTlXNtnwTua0thAZjoqsCmlyTDk2OXK-OIo5X1D1uu6ccb7oTJvnP39wvpgGgvNFINRxtWjvcGy2IFMCAtDulgyOlwx16dYI1mU3hEmwZK_DDP49ZgXUehXqVrxwK96aypKR2QxKVVdJYgNsvPyDDwPd0EUz3HSgL-fSQbC1lNZLnD7XUj0YHW2m8V2Q-mFldF_ru7KAL1oq0CqBNHrs_rotVw2HDIekBJkE0oBBGjFIw-rZTw-2AkQvARiSLbSy9MTMbdaMGZK4If9hrC5NTpdG53Uav7yodfWGIOv8aegXPVUf1f_yY3HwN-LwWXG0IW49FUfPiuMn4vHyv18BAAD__47ayRw=

query T nodeidx=3
USE multi_region_test_db; EXPLAIN (DISTSQL) SELECT
Expand Down Expand Up @@ -402,7 +402,7 @@ vectorized: true
table: orders@orders_pkey
spans: [/'ap-southeast-2'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727' - /'ap-southeast-2'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727'] [/'us-east-1'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727' - /'us-east-1'/'94e4b847-8f2f-4ac5-83f1-641d6e3df727']
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysU19v0zAQf-dTWPcymNw1_9Z2kSZ5GgU6lXa0k0DCVZXF182stYPtQNDUJz4b3wsl6TYy0UobPCS27-7n-_3Od7dgvy4hhv6n8-HJYERevh5ML6Yfhq_ItD_sn14QbQSauRSUZEavtD2olo1BpkhOpvVm_l26a527eRVw590nQtpU58o1A-so8mYyfl-nsORsPBhtkpDx3e5AqoUmjOeeF-ImsrZ9fNef9O_pkWOydxRhdNmLuq3eIli0oiQ9bPXChd_qRL7oYCgW3aC7BxSUFjhKVmgh_gwRzChkRqdorTal6bYKGIgCYo-CVFnuSvOMQqoNQnwLTrolQgwXyeUSJ5gING0PKAh0iVxW19ZMWb3Msxv8ARRO9TJfKRs3iipTpKRUBBSmWVK62xwYhzYHzoujiPMCy99l7y3nRW_RPvv1k_Ni4QvOC1-o4_LQ3ePQ9kiiBPGJdtdoYLamoHP3QN-65Aoh9tf0eRL9_yuxFOM9S-ZWacFWaQ-KLBqZLEmuKoYoGqJm67_UYKRbOmsHTfVDuZKO-FupeE-p8kB9Q-NQnGmp0LTDZqp6Eli9zMs6zqUogN7D-kVmCOvcjwkrLxjnLibMpyygLKQs2so0fArTkuGmHaJdLDftMNT6Js_IFy0V0SomrASNR4R1m2QnqASaii9hh5SwoPz2WWcr6-gprCdoM60sPnrrbS83o4DiCuu-sTo3KZ4bnVZp6uO4wlUGgdbV3qA-DFTlqsbsT7D_L-BgJzhsgL3H4HAnONoNjnaCDx-BZ-sXvwMAAP__8qQUmA==
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysVN1uGjsQvj9PYc1NzolM2L8AWSmSoxzaElFIIVIr1Qht1kPiBuyt7W23irjqs_W9qt0lpBsVpKS9ANsz83m-b3bG92A_LyGG_ofL4dlgRP79fzC9mr4b_kem_WH__IpoI9DMpaAkM3ql7VG1bAwyRXI2rTfzr9Ld6tzNq4AH7yER0qY6V64ZWEeRV5Px2zqFJRfjwWiThIwfdkdSLTRhPPe8EDeRte39m_6kv6VHTsnBSYTRdS_qtnqLYNGKkvS41QsXfqsT-aKDoVh0g-4BUFBa4ChZoYX4I0Qwo5AZnaK12pSm-ypgIAqIPQpSZbkrzTMKqTYI8T046ZYIMVwl10ucYCLQtD2gINAlclldWzNl9TLP7vAbUDjXy3ylbNwoqkyRklIRUJhmSeluc2Ac2hw4L04izgss_657rzkveov2xY_vnBcLX3Be-EKdlofuAYe2RxIliE-0u0UDszUFnbtH-tYlNwixv6Yvk-j_XYmlGO9FMndKC3ZKe1Rk0chkSXJVMUTREDVb_6YGI93SWTtoqh_KlXTE30nFe06VB-oLGofiQkuFph02U9WTwOplXtZxLkUBdAvrF5khrLMdE1ZeMM5dTJhPWUBZSFm0k2n4HKYlw007RPtYbtphqPVdnpFPWiqiVUxYCRqPCOs2yW7b5vF1eXg3tp0zQSXQVJoIO6aEBeXvkHV2Koueo2yCNtPK4pN-2PV1ZxRQ3GDdW1bnJsVLo9MqTX0cV7jKINC62hvUh4GqXNUo_gr2_wQc7AWHDbD3FBzuBUf7wdFe8PET8Gz9z88AAAD__y7iIUk=

# Regression test for #74890. Code should not panic due to distribution already
# provided by input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY
Scan /Table/112/1/"@"/10/0, /Table/112/1/"\x80"/10/0, /Table/112/1/"\xc0"/10/0
fetched: /child/child_pkey/?/10/c_p_id -> /10
Scan /Table/111/1/"@"/10/0, /Table/111/1/"\x80"/10/0, /Table/111/1/"\xc0"/10/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> <undecoded>

# Semi join with locality optimized search disabled.
query T
Expand Down Expand Up @@ -654,7 +654,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY
Scan /Table/112/1/"@"/10/0, /Table/112/1/"\x80"/10/0, /Table/112/1/"\xc0"/10/0
fetched: /child/child_pkey/?/10/c_p_id -> /10
Scan /Table/111/1/"@"/10/0, /Table/111/1/"\x80"/10/0, /Table/111/1/"\xc0"/10/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> <undecoded>
output row: [10 10]

# Inner join with locality optimized search disabled.
Expand Down Expand Up @@ -750,7 +750,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child WHERE NOT EXISTS (SELECT *
table: child@child_pkey
spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10]
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0k2GLm04Qxt__P8Uwb5L82ZLVWHosBAx3hnpYvSZCDy4SrA539oxr3RVyhHz3oqbcGZrQu7Zv1J2dx_09w7M7VN9zFLh0POcyhP9hvgg-wZ1ze-PNXB-GV-4yXH72RtBvSB6yPIUvH52FA0M_CMG5bRph2G8r44oKfegr11kKU0jWzcdoBDP_CoZJVzT4KIJgPl86IZjIsJAp-fGGFIo7NDBiWFYyIaVk1ZR2bYObblFwhllR1ropRwwTWRGKHepM54QCw_hrTguKU6rGHBmmpOMsb3_berDb57p8pCdkeCnzelMoAQ0WO6Aiw2UZN9XxCler7QVf4djgYw5xkYIBUj9QhdGeoaz1M4nS8T2hMPbsbbTGX6C1D6Qn6cyTdM9QiqoszqEuZJVSRWmPK9r_woYv38lybPYNeNkm02CcROGvGdS1zIrDnCb9Y8KnkgR4zjyEmR-6cB24PjLskmh3r58D9KR8rEv4JrMCZCFgaE9gCrZ5yKZtwRS2A4sPhBC2wbnBP4yQYVBrAbbBbPOkmckbzVj_0kxzn7eDi5d2GGwHSc_fbxq0XmNwQaqUhaKj5JzKQcSQ0nvqUqhkXSV0U8mkPaZbBq2uLaSkdLdrdgu3aLfae_dSbPyJ2DwrnvTE_Fg8OSu2zouts-L3R-Jo_9-PAAAA__9jBNRX
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0k2Fro04Qxt__P8Uwb5L82SOr8biyULC0hrN4ppcIV2gkWHdovdpdb1VIKfnuh5qjMVwCzd29UXd2Hvf3DM--YvkjR4ELL_AuI_gfpvPZF7jzbm-CCz-E4ZW_iBZfgxH0G9LHLJfw7bM392AYziLwbptGGPbbisSQqrZ9xSqTcA7pqvkYjeAivIJh2hUtPophNp0uvAhsZKi0pDB5phLFHVoYMyyMTqkstWlKr22DL9coOMNMFXXVlGOGqTaE4hWrrMoJBUbJfU5zSiSZMUeGkqoky9vfth7c9rkqnugFGV7qvH5WpYAGi21RkeGiSJrqeInL5fqML3Fs8TGHREmwQFePZDDeMNR19UZSVskDobA27DRa6y_QulvSg3T2Qbo3qJJMluRQK20kGZI9rnjzGxuh_qCLsd03EGTPWQXWQRT-nkFd60xt5zTpHxO9FCQg8KYRXISRD9czP0SGXRLd7vVrgIHWT3UB33WmQCsBQ3cC5-Da22y6DpzDeuDwgRDCtTi3-KfR7tyLbu5G3q8MPWRaHTQ3OdGc8y_NNfd7PTjbtcdgPUh7fk807LzH8JzKQquS9pJ1KCcxQ5IP1KW01LVJ6cbotD2mW85aXVuQVFbdrt0tfNVutfdyV2z9idg-Kp70xHxfPDkqdo6LnaPij3viePPfzwAAAP__dhHiVw==

statement ok
SET vectorize=on
Expand Down Expand Up @@ -783,7 +783,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY
Scan /Table/112/1/"@"/10/0
fetched: /child/child_pkey/?/10/c_p_id -> /10
Scan /Table/111/1/"@"/10/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> <undecoded>

statement ok
SET tracing = on,kv,results; SELECT * FROM child WHERE NOT EXISTS (SELECT * FROM parent WHERE p_id = c_p_id) AND c_id = 20; SET tracing = off
Expand All @@ -801,7 +801,7 @@ Scan /Table/112/1/"\x80"/20/0, /Table/112/1/"\xc0"/20/0
fetched: /child/child_pkey/?/20/c_p_id -> /20
Scan /Table/111/1/"@"/20/0
Scan /Table/111/1/"\x80"/20/0, /Table/111/1/"\xc0"/20/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ca-central-1'/20 -> <undecoded>

# Semi join with locality optimized search enabled.
query T
Expand All @@ -827,7 +827,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child WHERE EXISTS (SELECT * FROM
table: child@child_pkey
spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10]
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2z4Uxd__n-JyX5L80YjsFFYEAZfWYS5u0sWGFRoTPPvSenUkT5IhJeS7D9sZrcPS0W0vtnV1jvTT0fUOzfcSBUZ-6F_G8D_MlosbuPfvbsOLYA7DqyCKo8_hCPqC7LEoc_jyyV_64N81Ghj2FVWqSdqDpFoXOUwhWzcfI7iYX8Ew62oOHyWwmM0iPwYXGUqV0zzdkEFxjw4mDCutMjJG6aa0awVBvkXBGRayqm1TThhmShOKHdrCloQC4_RrSUtKc9JjjgxzsmlRtsu29F77XFdP9IwML1VZb6QR0GCxAykyjKq0qY5XuFptz_kKxw4fc0hlDg4o-0gakz1DVdsXEmPTB0Lh7Nmf0Tr_gNY7kJ6kc0_SvUAZ0kVaQi2VzklT3uNK9r84xlx9UNXY7R8gLDaFBeckCn9PUNeqkIecJv1t4ueKBIT-LIbIvwngehHMkWHXiF73-hlgqNRTXcE3VUhQUsDQm8AUPPfQm94ZTGE7OOMDIYTncO7wjyNkuKSNsgTlb93Nr7MdnL_2M9gOst6CzYqL2grwHOa5J-OZvCeeJZlKSUNHV3Uq-IQh5Q_UXbtRtc7oVqus3aYbLlpfW8jJ2G7W7QaBbKfaRn9tdv7G7L5pnvTM_Ng8edN8dmRO9v_9CAAA__-CWJEk
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2zAQx9_3KY57STI0IjuBFUHApXWYi5t0sWGFxgTXOlKvjuTJNqSEfPdhO6NxWDq67cW2TveXfve_8w6LHxkKDFzfvQrhI0wX81t4cO_v_EtvBv1rLwiDr_4AugnJU5pJ-PbFXbjg3tc50O9m5LEhVR5S8lUqYQLJqv4YwOXsGvpJG7P4IIL5dBq4IdjIUGlJs3hDBYoHtDBimBudUFFoU4d2TYIntyg4w1TlVVmHI4aJNoRih2VaZoQCw_gxowXFksyQI0NJZZxmzbENvdM8V_kzvSDDK51VG1UIqLHYgRQZBnlcR4dLXC63F3yJQ4sPOcRKggW6fCKD0Z6hrspXkqKM14TC2rO_o7X-A61zID1LZ5-le4UqyKRxBpXSRpIh2eGK9r8pY6Y_6Xxodwvw001agnUWhb_HqBudqoNPo-414UtOAnx3GkLg3npwM_dmyLAdRKd9_TLQ1_q5yuG7ThVoJaDvjGACjn2YTWcME9j2xrwnhHAszi3-eYAMF7TRJUH2R3X962x7F8d6Btte0jlwcNzJvO2kkY8rQ-tUq7N2jd5j14KKXKuCTlp3rhERQ5Jraseg0JVJ6M7opLmmXc4bXROQVJTtrt0uPNVsNYN_LLb-RWy_KR51xPxUPHpTPD4RR_sPPwMAAP__OaSYJA==

statement ok
SET vectorize=on
Expand Down Expand Up @@ -859,7 +859,7 @@ SELECT message FROM [SHOW KV TRACE FOR SESSION] WITH ORDINALITY
Scan /Table/112/1/"@"/10/0
fetched: /child/child_pkey/?/10/c_p_id -> /10
Scan /Table/111/1/"@"/10/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ap-southeast-2'/10 -> <undecoded>
output row: [10 10]

statement ok
Expand All @@ -878,7 +878,7 @@ Scan /Table/112/1/"\x80"/20/0, /Table/112/1/"\xc0"/20/0
fetched: /child/child_pkey/?/20/c_p_id -> /20
Scan /Table/111/1/"@"/20/0
Scan /Table/111/1/"\x80"/20/0, /Table/111/1/"\xc0"/20/0
fetched: /parent/parent_pkey/?/? -> <undecoded>
fetched: /parent/parent_pkey/'ca-central-1'/20 -> <undecoded>
output row: [20 20]

# Inner join with locality optimized search enabled.
Expand All @@ -905,7 +905,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child INNER JOIN parent ON p_id =
table: child@child_pkey
spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10]
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9Fq2zAUhu_3FIdzk2RoRLYDK4KAS-swl8zunMAGjQmefWi9OpYnyZAR8u4jckbrsHR0241tHemTPv2Sd6i_VyhwEcyDqyW8hVkSf4S74Mvt_DKMYHgdLpaLT_MR9AfkD2VVQBhFQQI3cRhBkymqDcQRNOuygCnka_vx-UOQBJB3NYenEM9mi2AJLjKsZUFRtiGN4g4dTBk2SuaktVSH0s4OCIstCs6wrJvWHMopw1wqQrFDU5qKUOAy-1pRQllBasyRYUEmKys7rRX17XPdPNIPZHglq3ZTa2Gt2FEUGS6a7FAdr3C12l7wFY4dPuaQ1QU4IM0DKUz3DGVrnky0ye4JhbNnf2fr_Adb_2h61s49a_ckpUmVWQVtLVVBioqeV7r_zTYi-U42Y7e_gXm5KQ04Z1X4a4K6kWV9zMnrL9PdNr97_UpqLuVj28A3WdYgawFD34Mp-O4ILqNrGPoTmMJ2MOEDIYTvcO7w9yNkmNBGGoLqj_Thd9gOLp7zDLaDvDfhYca4NQJ8h_ku872zUXiviSIh3cha08mxnAs5ZUjFPXVHrGWrcrpVMrfLdM3YcrZQkDZdr9s1wtp22Uv9HHb-BXZfhL0ezE9h70V4cgKn-zc_AwAA__8ZoYaJ
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk2Fr2zwQgL-_v-K4L2leNCLbhRVBwKV1mEtmd05gg8YE1zpSr47kyTJkhPz3ETujcVg6uu2LbZ30SI_uzlusv5UocBZMg5s5_A-TJP4ID8GX--l1GMHFbTibzz5Nh9BfkD8VpYQwioIE7uIwgiozpCzEEVTLQsIY8mX78flDkASQdzGHpxBPJrNgDi4yVFpSlK2pRvGADqYMK6Nzqmtt9qFtuyCUGxScYaGqxu7DKcNcG0KxRVvYklDgPHssKaFMkhlxZCjJZkXZbtuK-u1zWT3Td2R4o8tmrWrRWrGDKDKcVdk-OlrgYrG54gscOXzEIVMSHND2iQymO4a6sS8mtc1WhMLZsT-zdf6BrX8wPWvnnrV7karJFFkJjdJGkiHZ80p3v7hGpN_pauT2LzAt1oUF56wKf0ui7nShDnny-sd03eZ3r5-Zmmr93FTwVRcKtBJw4XswBt8dwnV0Cxf-JYxhM7jkAyGE73Du8PdDZJjQWluC8rf0_nfYDK6OeQabQd7bcHhcsqormZGPS0OrQitkGDdWgO8w32W-dzZP3lvylFBdaVXTSc3OVSBlSHJFXf1r3Zic7o3O22O6YdxybUBSbbtZtxuEqp1qO_4Ydv4Gdl-FvR7MT2HvVfjyBE53__0IAAD__5JOkJo=

statement ok
SET vectorize=on
Expand Down Expand Up @@ -983,7 +983,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child LEFT JOIN parent ON p_id =
table: child@child_pkey
spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10]
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2zAUhd_3Ky73Je3QiGwXVgQBl9ZhKZ7dOR4bNCZ49qX16lieJENKyH8fkTNah6Wj215s60jn6tPR9Qb1jxoFzoMwuEzhLUyT-CPcBl9vwotZBCdXs3k6_xSewnBBcV_VJYTBNIXreBZBmytqDMQRtMuqhAkUS_vx5UOQBFD0msMziKfTeZCCiwwbWVKUr0ijuEUHM4atkgVpLdVO2tgFs3KNgjOsmrYzOzljWEhFKDZoKlMTCkzzbzUllJekxhwZlmTyqrZlLadvn8v2gR6R4aWsu1WjhaVie1BkOG_znTpe4GKxPucLHDt8zCFvSnBAmntSmG0Zys48kWiT3xEKZ8v-jtb5D7T-nvQonXuU7glKk6ryGrpGqpIUlQOubPubY0TynWzH7vAAYbWqDDhHUfhrgrqWVbPPyRtukz62JPruiz-nQWJ7EBn2Xej3r18JhlI-dC18l1UDshFw4nswAd89hYvoCk78M5jAenTGR0II3-Hc4e9PkWFCK2kI6j-6d3_JenT-3M9gPSoGBXcV484I8B3mu8z3jkbkvSaihHQrG00H13Us_IwhlXfUX72WnSroRsnCbtMPY-uzQkna9LNuP5g1dso2-3Oz8y9m90WzNzDzQ7P3ovnswJxt3_wMAAD__4udjM4=
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk2Fr2zwQgL-_v-K4L2leNCI7hRVBwaV1WIpnd47HBo0JrnW0Xh3Jk2VIKfnvI3JH67B0dNuXxDrpkR7dnR6x_V6jwEUYhecZ_A-zNPkI1-HXq-hsHsPRxXyRLT5FYxguKO-qWkIUzjK4TOYxNIUhZSGJoVlVEk6hXLmPLx_CNISyj3k8h2Q2W4QZ-MhQaUlxsaYWxTV6mDNsjC6pbbXZhR7dgrncoOAMK9V0dhfOGZbaEIpHtJWtCQVmxU1NKRWSzIQjQ0m2qGq3rfMM3O-quacHZHiu626tWuGs2JMoMlw0xS46WeJyuTnhS5x4fMKhUBI80PaODOZbhrqzzyatLW4Jhbdlf2br_QPb4Mn0oJ1_0O5ZqiVTFTV0ShtJhuTAK9_-4hqxfqebiT-8QFStKwveQRX-lkRd6ko95Wk6PCZ7aEj03Zd8zsLU9SAy7Lsw6P9-ZjDS-r5r4JuuFGgl4CiYwikE_hjO4gs4Co7hFDajYz4SQgQe5x5_P0aGKa21Jah_S-9eyWZ08pJnsBmVgw3HL0vZ9KU08mZl6LbSChkmnRUQeCzwWTA9mL_pW_KXUtto1dJeLQ9VJmdI8pb6vmh1Z0q6Mrp0x_TDxHEuIKm1_azfD-bKTbmX8BL2_gb2X4WnA5jvw9NX4eM9ON_-9yMAAP__uiqW3w==

statement ok
SET vectorize=on
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/catalog/descpb/index_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *IndexFetchSpec) KeyColumns() []IndexFetchSpec_KeyColumn {

// KeyFullColumns returns the key columns in the index, plus all key suffix
// columns if that index is not a unique index. It parallels
// TableDesciptor.IndexFullColumns.
// TableDescriptor.IndexFullColumns.
func (s *IndexFetchSpec) KeyFullColumns() []IndexFetchSpec_KeyColumn {
if s.IsUniqueIndex {
// For unique indexes, the suffix columns are not part of the key (except
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/colexec/colbuilder/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ func NewColOperator(
indexJoinOp, err := colfetcher.NewColIndexJoin(
ctx, getStreamingAllocator(ctx, args),
colmem.NewAllocator(ctx, cFetcherMemAcc, factory),
kvFetcherMemAcc, streamerBudgetAcc, flowCtx, args.ExprHelper,
inputs[0].Root, core.JoinReader, post, inputTypes,
kvFetcherMemAcc, streamerBudgetAcc, flowCtx,
inputs[0].Root, core.JoinReader, inputTypes,
)
if err != nil {
return r, err
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/colexec/colexecspan/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ go_library(
"//pkg/sql/rowenc", # keep
"//pkg/sql/rowenc/keyside", # keep
"//pkg/sql/sem/tree", # keep
"//pkg/sql/span",
"//pkg/sql/types", # keep
"//pkg/util", # keep
"//pkg/util/duration", # keep
Expand Down
33 changes: 12 additions & 21 deletions pkg/sql/colexec/colexecspan/span_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,37 @@ import (
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/colmem"
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/span"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/errors"
)

// NewColSpanAssembler returns a ColSpanAssembler operator that is able to
// generate lookup spans from input batches.
// - neededColOrdsInWholeTable is a set containing the ordinals of all columns
// that need to be fetched. These ordinals are based on the schema of the whole
// table rather than only among the needed columns.
// See JoinReaderSpec for more info on fetchSpec and splitFamilyIDs.
func NewColSpanAssembler(
codec keys.SQLCodec,
allocator *colmem.Allocator,
table catalog.TableDescriptor,
index catalog.Index,
fetchSpec *descpb.IndexFetchSpec,
splitFamilyIDs []descpb.FamilyID,
inputTypes []*types.T,
neededColOrdsInWholeTable util.FastIntSet,
) ColSpanAssembler {
sa := spanAssemblerPool.Get().(*spanAssembler)
sa.colFamStartKeys, sa.colFamEndKeys = getColFamilyEncodings(neededColOrdsInWholeTable, table, index)
keyPrefix := rowenc.MakeIndexKeyPrefix(codec, table.GetID(), index.GetID())
sa.colFamStartKeys, sa.colFamEndKeys = getColFamilyEncodings(splitFamilyIDs)
keyPrefix := rowenc.MakeIndexKeyPrefix(codec, fetchSpec.TableID, fetchSpec.IndexID)
sa.scratchKey = append(sa.scratchKey[:0], keyPrefix...)
sa.prefixLength = len(keyPrefix)
sa.allocator = allocator

// Add span encoders to encode each primary key column as bytes. The
// ColSpanAssembler will later append these together to form valid spans.
for i := 0; i < index.NumKeyColumns(); i++ {
asc := index.GetKeyColumnDirection(i) == descpb.IndexDescriptor_ASC
keyColumns := fetchSpec.KeyColumns()
for i := range keyColumns {
asc := keyColumns[i].Direction == descpb.IndexDescriptor_ASC
sa.spanEncoders = append(sa.spanEncoders, newSpanEncoder(allocator, inputTypes[i], asc, i))
}
if cap(sa.spanCols) < len(sa.spanEncoders) {
Expand Down Expand Up @@ -284,18 +279,14 @@ func (sa *spanAssembler) Release() {
// keys of a span over a specific column family (or adjacent column families).
// If the returned lists are empty, the spans cannot be split into separate
// family spans.
func getColFamilyEncodings(
neededCols util.FastIntSet, table catalog.TableDescriptor, index catalog.Index,
) (startKeys, endKeys []roachpb.Key) {
splitter := span.MakeSplitter(table, index, neededCols)
if splitter.IsNoop() {
func getColFamilyEncodings(splitFamilyIDs []descpb.FamilyID) (startKeys, endKeys []roachpb.Key) {
if len(splitFamilyIDs) == 0 {
return nil, nil
}
familyIDs := splitter.FamilyIDs()
for i, familyID := range familyIDs {
for i, familyID := range splitFamilyIDs {
var key roachpb.Key
key = keys.MakeFamilyKey(key, uint32(familyID))
if i > 0 && familyID-1 == familyIDs[i-1] && endKeys != nil {
if i > 0 && familyID-1 == splitFamilyIDs[i-1] && endKeys != nil {
// This column family is adjacent to the previous one. We can merge
// the two spans into one.
endKeys[len(endKeys)-1] = key.PrefixEnd()
Expand Down
14 changes: 12 additions & 2 deletions pkg/sql/colexec/colexecspan/span_assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,19 @@ func TestSpanAssembler(t *testing.T) {
builder.Init(&evalCtx, keys.TODOSQLCodec, testTable, testTable.GetPrimaryIndex())
splitter := span.MakeSplitter(testTable, testTable.GetPrimaryIndex(), neededColumns)

var fetchSpec descpb.IndexFetchSpec
if err := rowenc.InitIndexFetchSpec(
&fetchSpec, keys.TODOSQLCodec, testTable, testTable.GetPrimaryIndex(), nil, /* fetchedColumnIDs */
); err != nil {
t.Fatal(err)
}

colBuilder := NewColSpanAssembler(
keys.TODOSQLCodec, testAllocator, testTable,
testTable.GetPrimaryIndex(), typs, neededColumns,
keys.TODOSQLCodec,
testAllocator,
&fetchSpec,
splitter.FamilyIDs(),
typs,
)
defer func() {
colBuilder.Close()
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/colfetcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ go_library(
"//pkg/sql/catalog/typedesc",
"//pkg/sql/colconv",
"//pkg/sql/colencoding",
"//pkg/sql/colexec/colexecargs",
"//pkg/sql/colexec/colexecspan",
"//pkg/sql/colexec/colexecutils",
"//pkg/sql/colexecerror",
"//pkg/sql/colexecop",
"//pkg/sql/colmem",
"//pkg/sql/execinfra",
"//pkg/sql/execinfrapb",
"//pkg/sql/memsize",
"//pkg/sql/physicalplan",
"//pkg/sql/row",
"//pkg/sql/rowenc",
"//pkg/sql/rowenc/keyside",
Expand Down
Loading

0 comments on commit 170d49c

Please sign in to comment.