2
0

tx.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. package storage
  2. import (
  3. "fmt"
  4. "sort"
  5. "strings"
  6. "sync"
  7. )
  8. // ErrSerialization is returned when a transaction's optimistic validation fails
  9. // because a concurrent transaction committed a conflicting change.
  10. var ErrSerialization = fmt.Errorf("serialization failure: concurrent transaction modified the database")
  11. // Session is a buffered SQL transaction/session wrapper around a TableManager.
  12. // While in a transaction, writes are staged in memory, reads observe that
  13. // staged overlay, and COMMIT issues a single atomic compare-and-swap batch
  14. // write. Rollback simply discards the staged changes (no compensating durable
  15. // writes). A Session is used for both autocommit statements (where operations
  16. // delegate straight to the durable TableManager) and buffered transactions.
  17. type Session struct {
  18. schema *SchemaManager
  19. table *TableManager
  20. mu sync.Mutex
  21. inTx bool
  22. aborted bool
  23. // overlay holds staged writes keyed by lowercased table then data key.
  24. overlay map[string]map[string]*overlayEntry
  25. // log records mutations in order so savepoints can roll back.
  26. log []txMutation
  27. // reads records the durable LSN of every key the transaction observed
  28. // (0 means the key was observed absent). It becomes the compare set at
  29. // commit and also captures the base LSN of every written key.
  30. reads map[string]uint64
  31. // scanGens records the per-table generation captured by the first scan of
  32. // each table, validated at commit to detect phantoms. Indexed equality reads
  33. // use predicateGens so writes to other index values do not cause conflicts.
  34. scanGens map[string]uint64
  35. predicateGens map[string]predicateRead
  36. }
  37. type predicateRead struct {
  38. table string
  39. gen uint64
  40. }
  41. type overlayEntry struct {
  42. row Row
  43. absent bool
  44. }
  45. type txMutation struct {
  46. table string
  47. key string
  48. prev *overlayEntry
  49. }
  50. // NewSession creates a session wrapping the given schema and table managers.
  51. func NewSession(schema *SchemaManager, table *TableManager) *Session {
  52. return &Session{
  53. schema: schema,
  54. table: table,
  55. overlay: make(map[string]map[string]*overlayEntry),
  56. reads: make(map[string]uint64),
  57. scanGens: make(map[string]uint64),
  58. predicateGens: make(map[string]predicateRead),
  59. }
  60. }
  61. // Begin starts a buffered transaction.
  62. func (s *Session) Begin() error {
  63. s.mu.Lock()
  64. defer s.mu.Unlock()
  65. if s.inTx {
  66. return fmt.Errorf("cannot start a transaction within a transaction")
  67. }
  68. s.inTx = true
  69. s.aborted = false
  70. s.overlay = make(map[string]map[string]*overlayEntry)
  71. s.log = nil
  72. s.reads = make(map[string]uint64)
  73. s.scanGens = make(map[string]uint64)
  74. s.predicateGens = make(map[string]predicateRead)
  75. return nil
  76. }
  77. // InTx reports whether a transaction is in progress.
  78. func (s *Session) InTx() bool {
  79. s.mu.Lock()
  80. defer s.mu.Unlock()
  81. return s.inTx
  82. }
  83. // Abort marks the transaction as aborted without discarding state.
  84. func (s *Session) Abort() {
  85. s.mu.Lock()
  86. defer s.mu.Unlock()
  87. if s.inTx {
  88. s.aborted = true
  89. }
  90. }
  91. // Snapshot returns the current mutation-log position for a savepoint.
  92. func (s *Session) Snapshot() int {
  93. s.mu.Lock()
  94. defer s.mu.Unlock()
  95. return len(s.log)
  96. }
  97. // RollbackTo discards mutations after the given savepoint position.
  98. func (s *Session) RollbackTo(pos int) {
  99. s.mu.Lock()
  100. defer s.mu.Unlock()
  101. for i := len(s.log) - 1; i >= pos && i >= 0; i-- {
  102. m := s.log[i]
  103. if m.prev == nil {
  104. delete(s.overlay[m.table], m.key)
  105. if len(s.overlay[m.table]) == 0 {
  106. delete(s.overlay, m.table)
  107. }
  108. } else {
  109. if s.overlay[m.table] == nil {
  110. s.overlay[m.table] = make(map[string]*overlayEntry)
  111. }
  112. s.overlay[m.table][m.key] = m.prev
  113. }
  114. }
  115. if pos < len(s.log) {
  116. s.log = s.log[:pos]
  117. }
  118. s.aborted = false
  119. }
  120. // Rollback discards the transaction without writing anything durable.
  121. func (s *Session) Rollback() error {
  122. s.mu.Lock()
  123. defer s.mu.Unlock()
  124. if !s.inTx {
  125. return fmt.Errorf("cannot rollback: no transaction in progress")
  126. }
  127. s.resetLocked()
  128. return nil
  129. }
  130. // Commit validates and durably applies the staged transaction in one atomic
  131. // compare-and-swap batch write.
  132. func (s *Session) Commit() error {
  133. s.mu.Lock()
  134. defer s.mu.Unlock()
  135. if !s.inTx {
  136. return fmt.Errorf("cannot commit: no transaction in progress")
  137. }
  138. if s.aborted {
  139. s.resetLocked()
  140. return fmt.Errorf("current transaction is aborted")
  141. }
  142. // Collect affected tables and lock them in sorted order. Tables read through
  143. // scans or predicates need an exclusive validation gate. Tables that are
  144. // only written use the shared publication gate, allowing disjoint optimistic
  145. // commits to proceed concurrently while still excluding scanner commits.
  146. affected := make(map[string]bool)
  147. for t := range s.overlay {
  148. affected[t] = false
  149. }
  150. for t := range s.scanGens {
  151. affected[t] = true
  152. }
  153. for _, predicate := range s.predicateGens {
  154. affected[predicate.table] = true
  155. }
  156. tables := make([]string, 0, len(affected))
  157. for t := range affected {
  158. tables = append(tables, t)
  159. }
  160. sort.Strings(tables)
  161. locks := make([]*sync.RWMutex, len(tables))
  162. exclusive := make([]bool, len(tables))
  163. for i, t := range tables {
  164. locks[i] = s.table.tableLock(t)
  165. exclusive[i] = affected[t]
  166. }
  167. for i, lock := range locks {
  168. if exclusive[i] {
  169. lock.Lock()
  170. } else {
  171. lock.RLock()
  172. }
  173. }
  174. defer func() {
  175. for i := len(locks) - 1; i >= 0; i-- {
  176. if exclusive[i] {
  177. locks[i].Unlock()
  178. } else {
  179. locks[i].RUnlock()
  180. }
  181. }
  182. }()
  183. // Validate scan generations for phantom detection.
  184. for t, gen := range s.scanGens {
  185. if s.table.generation(t) != gen {
  186. s.resetLocked()
  187. return ErrSerialization
  188. }
  189. }
  190. for key, predicate := range s.predicateGens {
  191. if s.table.predicateGeneration(key) != predicate.gen {
  192. s.resetLocked()
  193. return ErrSerialization
  194. }
  195. }
  196. // Build the compare set from every observed key.
  197. checks := make([]CompareCheck, 0, len(s.reads))
  198. for key, lsn := range s.reads {
  199. checks = append(checks, CompareCheck{Key: []byte(key), LSN: lsn})
  200. }
  201. sort.Slice(checks, func(i, j int) bool { return string(checks[i].Key) < string(checks[j].Key) })
  202. // Build the batch ops from the staged overlay.
  203. ops := make([]BatchOp, 0)
  204. for _, entries := range s.overlay {
  205. for key, e := range entries {
  206. if e.absent {
  207. ops = append(ops, BatchOp{Op: batchDelete, Key: []byte(key)})
  208. } else {
  209. data, err := encodeRow(e.row)
  210. if err != nil {
  211. return err
  212. }
  213. ops = append(ops, BatchOp{Op: batchPut, Key: []byte(key), Value: data})
  214. }
  215. }
  216. }
  217. sort.Slice(ops, func(i, j int) bool { return string(ops[i].Key) < string(ops[j].Key) })
  218. // A read-only transaction has nothing to write; commit trivially.
  219. if len(ops) == 0 {
  220. s.resetLocked()
  221. return nil
  222. }
  223. var committed bool
  224. err := s.table.pool.WithClient(func(c *KVClient) error {
  225. _, ok, err := c.CompareBatchWrite(checks, ops, nil)
  226. committed = ok
  227. return err
  228. })
  229. if err != nil {
  230. return err
  231. }
  232. if !committed {
  233. s.resetLocked()
  234. return ErrSerialization
  235. }
  236. // Advance generations and invalidate derived caches for written tables.
  237. for t := range s.overlay {
  238. s.table.InvalidateCache(t)
  239. s.table.bumpIndexPredicateWildcard(t)
  240. s.table.bumpGeneration(t)
  241. }
  242. s.resetLocked()
  243. return nil
  244. }
  245. func (s *Session) resetLocked() {
  246. s.inTx = false
  247. s.aborted = false
  248. s.overlay = make(map[string]map[string]*overlayEntry)
  249. s.log = nil
  250. s.reads = make(map[string]uint64)
  251. s.scanGens = make(map[string]uint64)
  252. s.predicateGens = make(map[string]predicateRead)
  253. }
  254. func (s *Session) stagePut(table, key string, row Row) {
  255. tl := strings.ToLower(table)
  256. if s.overlay[tl] == nil {
  257. s.overlay[tl] = make(map[string]*overlayEntry)
  258. }
  259. s.log = append(s.log, txMutation{table: tl, key: key, prev: s.overlay[tl][key]})
  260. s.overlay[tl][key] = &overlayEntry{row: cloneRow(row)}
  261. if _, ok := s.reads[key]; !ok {
  262. s.reads[key] = 0
  263. }
  264. }
  265. func (s *Session) stageDelete(table, key string) {
  266. tl := strings.ToLower(table)
  267. if s.overlay[tl] == nil {
  268. s.overlay[tl] = make(map[string]*overlayEntry)
  269. }
  270. s.log = append(s.log, txMutation{table: tl, key: key, prev: s.overlay[tl][key]})
  271. s.overlay[tl][key] = &overlayEntry{absent: true}
  272. if _, ok := s.reads[key]; !ok {
  273. s.reads[key] = 0
  274. }
  275. }
  276. // GetByPK retrieves a row by primary key, observing the staged overlay in a
  277. // transaction and recording the observed LSN for validation.
  278. func (s *Session) GetByPK(table, pk string) (Row, error) {
  279. s.mu.Lock()
  280. defer s.mu.Unlock()
  281. if !s.inTx {
  282. return s.table.GetByPK(table, pk)
  283. }
  284. key := s.table.dataKey(table, pk)
  285. tl := strings.ToLower(table)
  286. if e, ok := s.overlay[tl][key]; ok {
  287. if e.absent {
  288. return nil, ErrKeyNotFound
  289. }
  290. return cloneRow(e.row), nil
  291. }
  292. row, lsn, err := s.table.getByPKWithLSN(table, pk)
  293. if err != nil {
  294. if err == ErrKeyNotFound {
  295. s.reads[key] = 0
  296. return nil, ErrKeyNotFound
  297. }
  298. return nil, err
  299. }
  300. s.reads[key] = lsn
  301. return row, nil
  302. }
  303. // Select scans a table, merging the staged overlay so a transaction sees its
  304. // own writes, and records per-row LSNs plus the table generation.
  305. func (s *Session) Select(table string, filter func(Row) bool) ([]Row, error) {
  306. s.mu.Lock()
  307. if !s.inTx {
  308. s.mu.Unlock()
  309. return s.table.Select(table, filter)
  310. }
  311. defer s.mu.Unlock()
  312. return s.selectLocked(table, filter)
  313. }
  314. func (s *Session) selectLocked(table string, filter func(Row) bool) ([]Row, error) {
  315. schema, err := s.schema.GetSchema(table)
  316. if err != nil {
  317. return nil, err
  318. }
  319. tl := strings.ToLower(table)
  320. tableLock := s.table.tableLock(tl)
  321. tableLock.RLock()
  322. defer tableLock.RUnlock()
  323. if _, ok := s.scanGens[tl]; !ok {
  324. s.scanGens[tl] = s.table.generation(tl)
  325. }
  326. overlay := s.overlay[tl]
  327. var rows []Row
  328. err = s.table.scanRowsWithLSN(table, func(row Row, lsn uint64) (bool, error) {
  329. key := s.table.dataKey(table, fmt.Sprintf("%v", row[schema.PrimaryKey]))
  330. if _, ok := overlay[key]; ok {
  331. return false, nil
  332. }
  333. s.reads[key] = lsn
  334. if filter == nil || filter(row) {
  335. rows = append(rows, row)
  336. }
  337. return false, nil
  338. })
  339. if err != nil {
  340. return nil, err
  341. }
  342. for _, e := range overlay {
  343. if e.absent {
  344. continue
  345. }
  346. if filter == nil || filter(e.row) {
  347. rows = append(rows, cloneRow(e.row))
  348. }
  349. }
  350. return rows, nil
  351. }
  352. // SelectByIndex reads only matching durable rows while capturing their LSNs,
  353. // then merges the transaction overlay. The table generation protects against
  354. // matching rows being inserted or removed after the lookup.
  355. func (s *Session) SelectByIndex(table, indexName string, colValue interface{}) ([]Row, error) {
  356. s.mu.Lock()
  357. defer s.mu.Unlock()
  358. if !s.inTx {
  359. return s.table.SelectByIndex(table, indexName, colValue)
  360. }
  361. tableKey := strings.ToLower(table)
  362. index, err := s.schema.GetIndex(indexName)
  363. if err != nil {
  364. return nil, err
  365. }
  366. col := index.Columns[0].Name
  367. want := formatIndexValue(colValue)
  368. versions, predicate, err := s.table.selectByIndexWithLSN(table, indexName, colValue)
  369. if err != nil {
  370. return nil, err
  371. }
  372. if _, ok := s.predicateGens[predicate.valueKey]; !ok {
  373. s.predicateGens[predicate.valueKey] = predicateRead{table: tableKey, gen: predicate.valueGen}
  374. }
  375. if _, ok := s.predicateGens[predicate.wildcardKey]; !ok {
  376. s.predicateGens[predicate.wildcardKey] = predicateRead{table: tableKey, gen: predicate.wildcardGen}
  377. }
  378. overlay := s.overlay[tableKey]
  379. rows := make([]Row, 0, len(versions)+len(overlay))
  380. for _, version := range versions {
  381. if _, staged := overlay[version.key]; staged {
  382. continue
  383. }
  384. s.reads[version.key] = version.lsn
  385. rows = append(rows, version.row)
  386. }
  387. for _, entry := range overlay {
  388. if !entry.absent && formatIndexValue(entry.row[col]) == want {
  389. rows = append(rows, cloneRow(entry.row))
  390. }
  391. }
  392. return rows, nil
  393. }
  394. // CountFast returns the exact row count, observing the staged overlay in a
  395. // transaction.
  396. func (s *Session) CountFast(table string) (int, error) {
  397. s.mu.Lock()
  398. defer s.mu.Unlock()
  399. if !s.inTx {
  400. return s.table.CountFast(table)
  401. }
  402. rows, err := s.selectLocked(table, nil)
  403. if err != nil {
  404. return 0, err
  405. }
  406. return len(rows), nil
  407. }
  408. // Insert stages an insert in a transaction, or performs a durable autocommit
  409. // insert otherwise.
  410. func (s *Session) Insert(table string, row Row) error {
  411. s.mu.Lock()
  412. defer s.mu.Unlock()
  413. if !s.inTx {
  414. return s.table.Insert(table, row)
  415. }
  416. nr, key, err := s.table.prepareInsert(table, row)
  417. if err != nil {
  418. return err
  419. }
  420. schema, err := s.schema.GetSchema(table)
  421. if err != nil {
  422. return err
  423. }
  424. pk := fmt.Sprintf("%v", nr[schema.PrimaryKey])
  425. tl := strings.ToLower(table)
  426. if e, ok := s.overlay[tl][key]; ok {
  427. if !e.absent {
  428. return fmt.Errorf("duplicate primary key: %s", pk)
  429. }
  430. } else {
  431. _, lsn, err := s.table.getByPKWithLSN(table, pk)
  432. if err == nil {
  433. s.reads[key] = lsn
  434. return fmt.Errorf("duplicate primary key: %s", pk)
  435. }
  436. if err != ErrKeyNotFound {
  437. return err
  438. }
  439. s.reads[key] = 0
  440. }
  441. s.stagePut(table, key, nr)
  442. return nil
  443. }
  444. // InsertBulk stages or durably bulk-inserts multiple rows.
  445. func (s *Session) InsertBulk(table string, rows []Row) (int, error) {
  446. s.mu.Lock()
  447. defer s.mu.Unlock()
  448. if !s.inTx {
  449. return s.table.InsertBulk(table, rows)
  450. }
  451. count := 0
  452. for _, row := range rows {
  453. if err := s.insertLocked(table, row); err != nil {
  454. return count, err
  455. }
  456. count++
  457. }
  458. return count, nil
  459. }
  460. // insertLocked is the transaction insert helper (caller holds s.mu).
  461. func (s *Session) insertLocked(table string, row Row) error {
  462. nr, key, err := s.table.prepareInsert(table, row)
  463. if err != nil {
  464. return err
  465. }
  466. schema, err := s.schema.GetSchema(table)
  467. if err != nil {
  468. return err
  469. }
  470. pk := fmt.Sprintf("%v", nr[schema.PrimaryKey])
  471. tl := strings.ToLower(table)
  472. if e, ok := s.overlay[tl][key]; ok {
  473. if !e.absent {
  474. return fmt.Errorf("duplicate primary key: %s", pk)
  475. }
  476. } else {
  477. _, lsn, err := s.table.getByPKWithLSN(table, pk)
  478. if err == nil {
  479. s.reads[key] = lsn
  480. return fmt.Errorf("duplicate primary key: %s", pk)
  481. }
  482. if err != ErrKeyNotFound {
  483. return err
  484. }
  485. s.reads[key] = 0
  486. }
  487. s.stagePut(table, key, nr)
  488. return nil
  489. }
  490. // UpdateByPK stages or durably applies a single-row update.
  491. func (s *Session) UpdateByPK(table, pk string, updateFn func(Row) (Row, error)) (Row, bool, error) {
  492. s.mu.Lock()
  493. if !s.inTx {
  494. s.mu.Unlock()
  495. return s.table.UpdateByPK(table, pk, updateFn)
  496. }
  497. defer s.mu.Unlock()
  498. schema, err := s.schema.GetSchema(table)
  499. if err != nil {
  500. return nil, false, err
  501. }
  502. key := s.table.dataKey(table, pk)
  503. row, err := s.getByPKLocked(table, pk)
  504. if err == ErrKeyNotFound {
  505. return nil, false, nil
  506. }
  507. if err != nil {
  508. return nil, false, err
  509. }
  510. oldRow := cloneRow(row)
  511. updates, err := updateFn(row)
  512. if err != nil {
  513. return nil, false, err
  514. }
  515. for name, value := range updates {
  516. for _, column := range schema.Columns {
  517. if strings.EqualFold(name, column.Name) {
  518. row[column.Name] = value
  519. break
  520. }
  521. }
  522. }
  523. s.stagePut(table, key, row)
  524. return oldRow, true, nil
  525. }
  526. // DeleteByPK stages or durably applies a single-row delete.
  527. func (s *Session) DeleteByPK(table, pk string) (Row, bool, error) {
  528. s.mu.Lock()
  529. defer s.mu.Unlock()
  530. if !s.inTx {
  531. return s.table.DeleteByPK(table, pk)
  532. }
  533. key := s.table.dataKey(table, pk)
  534. row, err := s.getByPKLocked(table, pk)
  535. if err == ErrKeyNotFound {
  536. return nil, false, nil
  537. }
  538. if err != nil {
  539. return nil, false, err
  540. }
  541. s.stageDelete(table, key)
  542. return row, true, nil
  543. }
  544. // getByPKLocked reads a row observing the overlay (caller holds s.mu).
  545. func (s *Session) getByPKLocked(table, pk string) (Row, error) {
  546. key := s.table.dataKey(table, pk)
  547. tl := strings.ToLower(table)
  548. if e, ok := s.overlay[tl][key]; ok {
  549. if e.absent {
  550. return nil, ErrKeyNotFound
  551. }
  552. return cloneRow(e.row), nil
  553. }
  554. row, lsn, err := s.table.getByPKWithLSN(table, pk)
  555. if err != nil {
  556. if err == ErrKeyNotFound {
  557. s.reads[key] = 0
  558. return nil, ErrKeyNotFound
  559. }
  560. return nil, err
  561. }
  562. s.reads[key] = lsn
  563. return row, nil
  564. }
  565. // UpdateFunc stages or durably applies a scan-based update.
  566. func (s *Session) UpdateFunc(table string, updateFn func(Row) (Row, error), filter func(Row) bool) (int, error) {
  567. s.mu.Lock()
  568. if !s.inTx {
  569. s.mu.Unlock()
  570. return s.table.UpdateFunc(table, updateFn, filter)
  571. }
  572. defer s.mu.Unlock()
  573. schema, err := s.schema.GetSchema(table)
  574. if err != nil {
  575. return 0, err
  576. }
  577. rows, err := s.selectLocked(table, filter)
  578. if err != nil {
  579. return 0, err
  580. }
  581. count := 0
  582. for _, row := range rows {
  583. updates, err := updateFn(row)
  584. if err != nil {
  585. return count, err
  586. }
  587. for name, value := range updates {
  588. for _, column := range schema.Columns {
  589. if strings.EqualFold(name, column.Name) {
  590. row[column.Name] = value
  591. break
  592. }
  593. }
  594. }
  595. key := s.table.dataKey(table, fmt.Sprintf("%v", row[schema.PrimaryKey]))
  596. s.stagePut(table, key, row)
  597. count++
  598. }
  599. return count, nil
  600. }
  601. // Delete stages or durably applies a scan-based delete.
  602. func (s *Session) Delete(table string, filter func(Row) bool) (int, error) {
  603. s.mu.Lock()
  604. if !s.inTx {
  605. s.mu.Unlock()
  606. return s.table.Delete(table, filter)
  607. }
  608. defer s.mu.Unlock()
  609. schema, err := s.schema.GetSchema(table)
  610. if err != nil {
  611. return 0, err
  612. }
  613. rows, err := s.selectLocked(table, filter)
  614. if err != nil {
  615. return 0, err
  616. }
  617. count := 0
  618. for _, row := range rows {
  619. key := s.table.dataKey(table, fmt.Sprintf("%v", row[schema.PrimaryKey]))
  620. s.stageDelete(table, key)
  621. count++
  622. }
  623. return count, nil
  624. }
  625. // ClearIndex passes through to the durable table manager.
  626. func (s *Session) ClearIndex(indexName, tableName string, columns []string) error {
  627. return s.table.ClearIndex(indexName, tableName, columns)
  628. }
  629. // InvalidateCache passes through to the durable table manager.
  630. func (s *Session) InvalidateCache(table string) {
  631. s.table.InvalidateCache(table)
  632. }
  633. // BuildIndex passes through to the durable table manager.
  634. func (s *Session) BuildIndex(indexName, tableName string, columns []string) error {
  635. return s.table.BuildIndex(indexName, tableName, columns)
  636. }