@@ -1587,59 +1587,29 @@ func (ef *execFactory) ConstructUpdate(
1587
1587
return nil , errors .AssertionFailedf ("execution requires all update columns have a fetch column" )
1588
1588
}
1589
1589
1590
- // Derive table and column descriptors.
1591
1590
rowsNeeded := ! returnColOrdSet .Empty ()
1592
1591
tabDesc := table .(* optTable ).desc
1593
- fetchCols := makeColList (table , fetchColOrdSet )
1594
- updateCols := makeColList (table , updateColOrdSet )
1595
-
1596
- // Create the table updater, which does the bulk of the work.
1597
- ru , err := row .MakeUpdater (
1598
- ef .planner .ExecCfg ().Codec ,
1599
- tabDesc ,
1600
- ordinalsToIndexes (table , uniqueWithTombstoneIndexes ),
1601
- ordinalsToIndexes (table , lockedIndexes ),
1602
- updateCols ,
1603
- fetchCols ,
1604
- row .UpdaterDefault ,
1605
- ef .planner .SessionData (),
1606
- & ef .planner .ExecCfg ().Settings .SV ,
1607
- ef .planner .ExecCfg ().GetRowMetrics (ef .planner .SessionData ().Internal ),
1608
- )
1609
- if err != nil {
1610
- return nil , err
1611
- }
1612
1592
1613
1593
upd := updateNodePool .Get ().(* updateNode )
1614
1594
* upd = updateNode {
1615
1595
singleInputPlanNode : singleInputPlanNode {input .(planNode )},
1616
- run : updateRun {
1617
- tu : tableUpdater {ru : ru },
1618
- checkOrds : checks ,
1619
- numPassthrough : len (passthrough ),
1620
- },
1621
1596
}
1622
1597
1623
- upd .run .regionLocalInfo .setupEnforceHomeRegion (ef .planner , table , ru .UpdateCols ,
1624
- upd .run .tu .ru .UpdateColIDtoRowIndex )
1625
-
1626
1598
// If rows are not needed, no columns are returned.
1599
+ var returnCols []catalog.Column
1627
1600
if rowsNeeded {
1628
- returnCols := makeColList (table , returnColOrdSet )
1629
-
1601
+ returnCols = makeColList (table , returnColOrdSet )
1630
1602
upd .columns = colinfo .ResultColumnsFromColumns (tabDesc .GetID (), returnCols )
1631
1603
// Add the passthrough columns to the returning columns.
1632
1604
upd .columns = append (upd .columns , passthrough ... )
1605
+ }
1633
1606
1634
- // Set the rowIdxToRetIdx for the mutation. Update returns the non-mutation
1635
- // columns specified, in the same order they are defined in the table.
1636
- //
1637
- // The Updater derives/stores the fetch columns of the mutation and
1638
- // since the return columns are always a subset of the fetch columns,
1639
- // we can use use the fetch columns to generate the mapping for the
1640
- // returned rows.
1641
- upd .run .rowIdxToRetIdx = row .ColMapping (ru .FetchCols , returnCols )
1642
- upd .run .rowsNeeded = true
1607
+ // Create the table updater, which does the bulk of the work.
1608
+ if err := ef .constructUpdateRun (
1609
+ & upd .run , table , fetchColOrdSet , updateColOrdSet , returnColOrdSet , rowsNeeded , returnCols ,
1610
+ checks , passthrough , uniqueWithTombstoneIndexes , lockedIndexes ,
1611
+ ); err != nil {
1612
+ return nil , err
1643
1613
}
1644
1614
1645
1615
if autoCommit {
@@ -1660,6 +1630,62 @@ func (ef *execFactory) ConstructUpdate(
1660
1630
return & rowCountNode {source : upd }, nil
1661
1631
}
1662
1632
1633
+ func (ef * execFactory ) constructUpdateRun (
1634
+ run * updateRun ,
1635
+ table cat.Table ,
1636
+ fetchColOrdSet exec.TableColumnOrdinalSet ,
1637
+ updateColOrdSet exec.TableColumnOrdinalSet ,
1638
+ returnColOrdSet exec.TableColumnOrdinalSet ,
1639
+ rowsNeeded bool ,
1640
+ returnCols []catalog.Column ,
1641
+ checks exec.CheckOrdinalSet ,
1642
+ passthrough colinfo.ResultColumns ,
1643
+ uniqueWithTombstoneIndexes cat.IndexOrdinals ,
1644
+ lockedIndexes cat.IndexOrdinals ,
1645
+ ) error {
1646
+ tabDesc := table .(* optTable ).desc
1647
+ fetchCols := makeColList (table , fetchColOrdSet )
1648
+ updateCols := makeColList (table , updateColOrdSet )
1649
+
1650
+ // Create the table updater.
1651
+ ru , err := row .MakeUpdater (
1652
+ ef .planner .ExecCfg ().Codec ,
1653
+ tabDesc ,
1654
+ ordinalsToIndexes (table , uniqueWithTombstoneIndexes ),
1655
+ ordinalsToIndexes (table , lockedIndexes ),
1656
+ updateCols ,
1657
+ fetchCols ,
1658
+ row .UpdaterDefault ,
1659
+ ef .planner .SessionData (),
1660
+ & ef .planner .ExecCfg ().Settings .SV ,
1661
+ ef .planner .ExecCfg ().GetRowMetrics (ef .planner .SessionData ().Internal ),
1662
+ )
1663
+ if err != nil {
1664
+ return err
1665
+ }
1666
+
1667
+ run .tu = tableUpdater {ru : ru }
1668
+ run .checkOrds = checks
1669
+ run .numPassthrough = len (passthrough )
1670
+
1671
+ run .regionLocalInfo .setupEnforceHomeRegion (ef .planner , table , ru .UpdateCols ,
1672
+ run .tu .ru .UpdateColIDtoRowIndex )
1673
+
1674
+ if rowsNeeded {
1675
+ // Set the rowIdxToRetIdx for the mutation. Update returns the non-mutation
1676
+ // columns specified, in the same order they are defined in the table.
1677
+ //
1678
+ // The Updater derives/stores the fetch columns of the mutation and
1679
+ // since the return columns are always a subset of the fetch columns,
1680
+ // we can use use the fetch columns to generate the mapping for the
1681
+ // returned rows.
1682
+ run .rowIdxToRetIdx = row .ColMapping (ru .FetchCols , returnCols )
1683
+ run .rowsNeeded = true
1684
+ }
1685
+
1686
+ return nil
1687
+ }
1688
+
1663
1689
func (ef * execFactory ) ConstructUpsert (
1664
1690
input exec.Node ,
1665
1691
table cat.Table ,
@@ -1770,46 +1796,31 @@ func (ef *execFactory) ConstructDelete(
1770
1796
lockedIndexes cat.IndexOrdinals ,
1771
1797
autoCommit bool ,
1772
1798
) (exec.Node , error ) {
1773
- // Derive table and column descriptors.
1774
1799
rowsNeeded := ! returnColOrdSet .Empty ()
1775
1800
tabDesc := table .(* optTable ).desc
1776
- fetchCols := makeColList (table , fetchColOrdSet )
1777
-
1778
- // Create the table deleter, which does the bulk of the work.
1779
- rd := row .MakeDeleter (
1780
- ef .planner .ExecCfg ().Codec ,
1781
- tabDesc ,
1782
- ordinalsToIndexes (table , lockedIndexes ),
1783
- fetchCols ,
1784
- ef .planner .SessionData (),
1785
- & ef .planner .ExecCfg ().Settings .SV ,
1786
- ef .planner .ExecCfg ().GetRowMetrics (ef .planner .SessionData ().Internal ),
1787
- )
1788
1801
1789
1802
// Now make a delete node. We use a pool.
1790
1803
del := deleteNodePool .Get ().(* deleteNode )
1791
1804
* del = deleteNode {
1792
1805
singleInputPlanNode : singleInputPlanNode {input .(planNode )},
1793
- run : deleteRun {
1794
- td : tableDeleter {rd : rd },
1795
- numPassthrough : len (passthrough ),
1796
- },
1797
1806
}
1798
1807
1799
1808
// If rows are not needed, no columns are returned.
1809
+ var returnCols []catalog.Column
1800
1810
if rowsNeeded {
1801
- returnCols : = makeColList (table , returnColOrdSet )
1811
+ returnCols = makeColList (table , returnColOrdSet )
1802
1812
// Delete returns the non-mutation columns specified, in the same
1803
1813
// order they are defined in the table.
1804
1814
del .columns = colinfo .ResultColumnsFromColumns (tabDesc .GetID (), returnCols )
1805
-
1806
1815
// Add the passthrough columns to the returning columns.
1807
1816
del .columns = append (del .columns , passthrough ... )
1808
-
1809
- del .run .rowIdxToRetIdx = row .ColMapping (rd .FetchCols , returnCols )
1810
- del .run .rowsNeeded = true
1811
1817
}
1812
1818
1819
+ // Create the table deleter, which does the bulk of the work.
1820
+ ef .constructDeleteRun (
1821
+ & del .run , table , fetchColOrdSet , rowsNeeded , returnCols , passthrough , lockedIndexes ,
1822
+ )
1823
+
1813
1824
if autoCommit {
1814
1825
del .enableAutoCommit ()
1815
1826
}
@@ -1828,6 +1839,38 @@ func (ef *execFactory) ConstructDelete(
1828
1839
return & rowCountNode {source : del }, nil
1829
1840
}
1830
1841
1842
+ func (ef * execFactory ) constructDeleteRun (
1843
+ run * deleteRun ,
1844
+ table cat.Table ,
1845
+ fetchColOrdSet exec.TableColumnOrdinalSet ,
1846
+ rowsNeeded bool ,
1847
+ returnCols []catalog.Column ,
1848
+ passthrough colinfo.ResultColumns ,
1849
+ lockedIndexes cat.IndexOrdinals ,
1850
+ ) {
1851
+ tabDesc := table .(* optTable ).desc
1852
+ fetchCols := makeColList (table , fetchColOrdSet )
1853
+
1854
+ // Create the table deleter.
1855
+ rd := row .MakeDeleter (
1856
+ ef .planner .ExecCfg ().Codec ,
1857
+ tabDesc ,
1858
+ ordinalsToIndexes (table , lockedIndexes ),
1859
+ fetchCols ,
1860
+ ef .planner .SessionData (),
1861
+ & ef .planner .ExecCfg ().Settings .SV ,
1862
+ ef .planner .ExecCfg ().GetRowMetrics (ef .planner .SessionData ().Internal ),
1863
+ )
1864
+
1865
+ run .td = tableDeleter {rd : rd }
1866
+ run .numPassthrough = len (passthrough )
1867
+
1868
+ if rowsNeeded {
1869
+ run .rowIdxToRetIdx = row .ColMapping (rd .FetchCols , returnCols )
1870
+ run .rowsNeeded = true
1871
+ }
1872
+ }
1873
+
1831
1874
func (ef * execFactory ) ConstructDeleteRange (
1832
1875
table cat.Table ,
1833
1876
needed exec.TableColumnOrdinalSet ,
0 commit comments