From d3446a5c7aa1daeabba0bf3959d7ad9bc8da46c9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 09:32:21 +0000 Subject: [PATCH 001/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 2 +- source/libs/tdb/src/db/tdbPage.c | 253 ---------------------------- source/libs/tdb/src/inc/tdbPage.h | 26 +-- source/libs/tdb/src/page/tdbPage.c | 244 +++++++++++++++++---------- source/libs/tdb/src/page/tdbPageL.c | 45 +++-- 5 files changed, 198 insertions(+), 372 deletions(-) delete mode 100644 source/libs/tdb/src/db/tdbPage.c diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index c6e8c9dca9..423de0b53c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -414,7 +414,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { } // TODO: need to update the SPage.nFree - pPage->nFree = pPage->pFreeEnd - pPage->pFreeStart; + // pPage->nFree = pPage->pFreeEnd - pPage->pFreeStart; pPage->nOverflow = 0; return 0; diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c deleted file mode 100644 index df158de756..0000000000 --- a/source/libs/tdb/src/db/tdbPage.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "tdbInt.h" - -typedef struct __attribute__((__packed__)) { - u8 szCell[2]; - u8 nxOffset[2]; -} SFreeCell; - -typedef struct __attribute__((__packed__)) { - u8 szCell[3]; - u8 nxOffset[3]; -} SFreeCellL; - -/* For small page */ -#define TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL) (((SFreeCell *)(PCELL))->szCell) -#define TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) (((SFreeCell *)(PCELL))->nxOffset) - -#define TDB_SPAGE_FREE_CELL_SIZE(PCELL) ((u16 *)TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL))[0] -#define TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL) ((u16 *)TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL))[0] - -#define TDB_SPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE) (TDB_SPAGE_FREE_CELL_SIZE(PCELL) = (SIZE)) -#define TDB_SPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET) (TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL) = (OFFSET)) - -/* For large page */ -#define TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL) (((SFreeCellL *)(PCELL))->szCell) -#define TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) (((SFreeCellL *)(PCELL))->nxOffset) - -#define TDB_LPAGE_FREE_CELL_SIZE(PCELL) TDB_GET_U24(TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL)) -#define TDB_LPAGE_FREE_CELL_NXOFFSET(PCELL) TDB_GET_U24(TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL)) - -#define TDB_LPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE) TDB_PUT_U24(TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL), SIZE) -#define TDB_LPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET) TDB_PUT_U24(TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL), OFFSET) - -/* For page */ -#define TDB_PAGE_FREE_CELL_SIZE_PTR(PPAGE, PCELL) \ - (TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL) : TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL)) -#define TDB_PAGE_FREE_CELL_NXOFFSET_PTR(PPAGE, PCELL) \ - (TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) : TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL)) - -#define TDB_PAGE_FREE_CELL_SIZE(PPAGE, PCELL) \ - (TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_SIZE(PCELL) : TDB_SPAGE_FREE_CELL_SIZE(PCELL)) -#define TDB_PAGE_FREE_CELL_NXOFFSET(PPAGE, PCELL) \ - (TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_NXOFFSET(PCELL) : TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL)) - -#define TDB_PAGE_FREE_CELL_SIZE_SET(PPAGE, PCELL, SIZE) \ - do { \ - if (TDB_IS_LARGE_PAGE(PPAGE)) { \ - TDB_LPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE); \ - } else { \ - TDB_SPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE); \ - } \ - } while (0) -#define TDB_PAGE_FREE_CELL_NXOFFSET_SET(PPAGE, PCELL, OFFSET) \ - do { \ - if (TDB_IS_LARGE_PAGE(PPAGE)) { \ - TDB_LPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET); \ - } else { \ - TDB_SPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET); \ - } \ - } while (0) - -static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell); -static int tdbPageDefragment(SPage *pPage); - -int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg) { - SPage *pPage; - u8 *ptr; - int size; - - ASSERT(TDB_IS_PGSIZE_VLD(pageSize)); - - *ppPage = NULL; - size = pageSize + sizeof(*pPage); - - ptr = (u8 *)((*xMalloc)(arg, size)); - if (pPage == NULL) { - return -1; - } - - memset(ptr, 0, size); - pPage = (SPage *)(ptr + pageSize); - - pPage->pData = ptr; - pPage->pageSize = pageSize; - if (pageSize < 65536) { - pPage->szOffset = 2; - pPage->szPageHdr = sizeof(SPageHdr); - pPage->szFreeCell = sizeof(SFreeCell); - } else { - pPage->szOffset = 3; - pPage->szPageHdr = sizeof(SPageHdrL); - pPage->szFreeCell = sizeof(SFreeCellL); - } - TDB_INIT_PAGE_LOCK(pPage); - - /* TODO */ - - *ppPage = pPage; - return 0; -} - -int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) { - u8 *ptr; - - ptr = pPage->pData; - (*xFree)(arg, ptr); - - return 0; -} - -int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { - int ret; - SCell *pTarget; - u8 *pTmp; - int j; - - if (pPage->nOverflow || szCell + pPage->szOffset > pPage->nFree) { - // TODO: need to figure out if pCell may be used by outside of this function - j = pPage->nOverflow++; - - pPage->apOvfl[j] = pCell; - pPage->aiOvfl[j] = idx; - } else { - ret = tdbPageAllocate(pPage, szCell, &pTarget); - if (ret < 0) { - return -1; - } - - memcpy(pTarget, pCell, szCell); - pTmp = pPage->pCellIdx + idx * pPage->szOffset; - memmove(pTmp + pPage->szOffset, pTmp, pPage->pFreeStart - pTmp - pPage->szOffset); - TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pTarget - pPage->pData); - TDB_PAGE_NCELLS_SET(pPage, TDB_PAGE_NCELLS(pPage) + 1); - } - - return 0; -} - -int tdbPageDropCell(SPage *pPage, int idx) { - // TODO - return 0; -} - -static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { - SCell *pCell; - SFreeCell *pFreeCell; - u8 *pOffset; - int ret; - - ASSERT(pPage->nFree > size + pPage->szOffset); - - pCell = NULL; - *ppCell = NULL; - - // 1. Try to allocate from the free space area - if (pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset) { - pPage->pFreeEnd -= size; - pPage->pFreeStart += pPage->szOffset; - pCell = pPage->pFreeEnd; - } - - // 2. Try to allocate from the page free list - if ((pCell == NULL) && (pPage->pFreeEnd - pPage->pFreeStart >= pPage->szOffset) && TDB_PAGE_FCELL(pPage)) { - int szCell; - int nxOffset; - - pCell = pPage->pData + TDB_PAGE_FCELL(pPage); - pOffset = TDB_IS_LARGE_PAGE(pPage) ? ((SPageHdrL *)(pPage->pPageHdr))[0].fCell - : (u8 *)&(((SPageHdr *)(pPage->pPageHdr))[0].fCell); - szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell); - nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell); - - for (;;) { - // Find a cell - if (szCell >= size) { - if (szCell - size >= pPage->szFreeCell) { - SCell *pTmpCell = pCell + size; - - TDB_PAGE_FREE_CELL_SIZE_SET(pPage, pTmpCell, szCell - size); - TDB_PAGE_FREE_CELL_NXOFFSET_SET(pPage, pTmpCell, nxOffset); - // TODO: *pOffset = pTmpCell - pPage->pData; - } else { - TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_NFREE(pPage) + szCell - size); - // TODO: *pOffset = nxOffset; - } - break; - } - - // Not find a cell yet - if (nxOffset > 0) { - pCell = pPage->pData + nxOffset; - pOffset = TDB_PAGE_FREE_CELL_NXOFFSET_PTR(pPage, pCell); - szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell); - nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell); - continue; - } else { - pCell = NULL; - break; - } - } - - if (pCell) { - pPage->pFreeStart = pPage->pFreeStart + pPage->szOffset; - } - } - - // 3. Try to dfragment and allocate again - if (pCell == NULL) { - ret = tdbPageDefragment(pPage); - if (ret < 0) { - return -1; - } - - ASSERT(pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset); - ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart); - - // Allocate from the free space area again - pPage->pFreeEnd -= size; - pPage->pFreeStart += pPage->szOffset; - pCell = pPage->pFreeEnd; - } - - ASSERT(pCell != NULL); - - pPage->nFree = pPage->nFree - size - pPage->szOffset; - *ppCell = pCell; - return 0; -} - -static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) { - // TODO - return 0; -} - -static int tdbPageDefragment(SPage *pPage) { - // TODO - ASSERT(0); - return 0; -} \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 6479574abe..418a1b6626 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -45,6 +45,9 @@ typedef struct { // cell offset at idx int (*getCellOffset)(SPage *, int); void (*setCellOffset)(SPage *, int, int); + // free cell info + void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset); + void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset); } SPageMethods; // Page footer @@ -59,20 +62,19 @@ struct SPage { SPageMethods *pPageMethods; // Fields below used by pager and am u8 szAmHdr; - u8 *pPageHdr; u8 *pAmHdr; + u8 *pPageHdr; u8 *pCellIdx; u8 *pFreeStart; u8 *pFreeEnd; SPageFtr *pPageFtr; - int kLen; // key length of the page, -1 for unknown - int vLen; // value length of the page, -1 for unknown - int nFree; - int maxLocal; - int minLocal; int nOverflow; SCell *apOvfl[4]; int aiOvfl[4]; + int kLen; // key length of the page, -1 for unknown + int vLen; // value length of the page, -1 for unknown + int maxLocal; + int minLocal; // Fields used by SPCache TDB_PCACHE_PAGE }; @@ -92,8 +94,6 @@ struct SPage { #define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE) #define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET) -#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) - #define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx)) // For page lock @@ -119,10 +119,12 @@ struct SPage { }) // APIs -int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); -int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); -int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); -int tdbPageDropCell(SPage *pPage, int idx); +int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); +int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); +void tdbPageZero(SPage *pPage); +void tdbPageInit(SPage *pPage); +int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); +int tdbPageDropCell(SPage *pPage, int idx); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 4ec3a895e7..e198891338 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -18,10 +18,11 @@ extern SPageMethods pageMethods; extern SPageMethods pageLargeMethods; -typedef struct __attribute__((__packed__)) { - u16 szCell; - u16 nxOffset; -} SFreeCell; +#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) +#define TDB_PAGE_HDR_SIZE(pPage) ((pPage)->pPageMethods->szPageHdr) +#define TDB_PAGE_FREE_CELL_SIZE(pPage) ((pPage)->pPageMethods->szFreeCell) +#define TDB_PAGE_MAX_FREE_BLOCK(pPage) \ + ((pPage)->pageSize - (pPage)->szAmHdr - TDB_PAGE_HDR_SIZE(pPage) - sizeof(SPageFtr)) static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell); static int tdbPageDefragment(SPage *pPage); @@ -44,6 +45,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) memset(ptr, 0, size); pPage = (SPage *)(ptr + pageSize); + TDB_INIT_PAGE_LOCK(pPage); pPage->pData = ptr; pPage->pageSize = pageSize; if (pageSize < 65536) { @@ -51,9 +53,6 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) } else { pPage->pPageMethods = &pageLargeMethods; } - TDB_INIT_PAGE_LOCK(pPage); - - /* TODO */ *ppPage = pPage; return 0; @@ -68,29 +67,64 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) return 0; } +void tdbPageZero(SPage *pPage) { + TDB_PAGE_NCELLS_SET(pPage, 0); + TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr)); + TDB_PAGE_FCELL_SET(pPage, 0); + TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_MAX_FREE_BLOCK(pPage)); + tdbPageInit(pPage); +} + +void tdbPageInit(SPage *pPage) { + pPage->pAmHdr = pPage->pData; + pPage->pPageHdr = pPage->pAmHdr + pPage->szAmHdr; + pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); + pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage); + pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); + pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr)); + pPage->nOverflow = 0; + + ASSERT(pPage->pFreeEnd >= pPage->pFreeStart); + ASSERT(pPage->pFreeEnd - pPage->pFreeStart <= TDB_PAGE_NFREE(pPage)); +} + int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { + int nFree; int ret; - SCell *pTarget; - u8 *pTmp; - int j; + int nCells; + int lidx; // local idx + SCell *pNewCell; - if (pPage->nOverflow || szCell + TDB_PAGE_OFFSET_SIZE(pPage) > pPage->nFree) { - // TODO: need to figure out if pCell may be used by outside of this function - j = pPage->nOverflow++; + ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage)); - pPage->apOvfl[j] = pCell; - pPage->aiOvfl[j] = idx; - } else { - ret = tdbPageAllocate(pPage, szCell, &pTarget); - if (ret < 0) { - return -1; + nFree = TDB_PAGE_NFREE(pPage); + nCells = TDB_PAGE_NCELLS(pPage); + + if (nFree >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { + // page must has enough space to hold the cell locally + ret = tdbPageAllocate(pPage, szCell, &pNewCell); + ASSERT(ret == 0); + + memcpy(pNewCell, pCell, szCell); + + if (pPage->nOverflow == 0) { + lidx = idx; + } else { + // TODO + // lidx = ; } - memcpy(pTarget, pCell, szCell); - pTmp = pPage->pCellIdx + idx * TDB_PAGE_OFFSET_SIZE(pPage); - memmove(pTmp + TDB_PAGE_OFFSET_SIZE(pPage), pTmp, pPage->pFreeStart - pTmp - TDB_PAGE_OFFSET_SIZE(pPage)); - TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pTarget - pPage->pData); - TDB_PAGE_NCELLS_SET(pPage, TDB_PAGE_NCELLS(pPage) + 1); + // no overflow cell exists in this page + u8 *src = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * lidx; + u8 *dest = src + TDB_PAGE_OFFSET_SIZE(pPage); + memmove(dest, src, pPage->pFreeStart - dest); + TDB_PAGE_CELL_OFFSET_AT_SET(pPage, lidx, TDB_PAGE_OFFSET_SIZE(pPage) * lidx); + TDB_PAGE_NCELLS_SET(pPage, nCells + 1); + } else { + // TODO: page not has enough space + pPage->apOvfl[pPage->nOverflow] = pCell; + pPage->aiOvfl[pPage->nOverflow] = idx; + pPage->nOverflow++; } return 0; @@ -101,73 +135,80 @@ int tdbPageDropCell(SPage *pPage, int idx) { return 0; } -static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { - SCell *pCell; - SFreeCell *pFreeCell; - u8 *pOffset; - int ret; +static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { + SCell *pFreeCell; + u8 *pOffset; + int nFree; + int ret; + int cellFree; - ASSERT(pPage->nFree > size + TDB_PAGE_OFFSET_SIZE(pPage)); - - pCell = NULL; *ppCell = NULL; + nFree = TDB_PAGE_NFREE(pPage); - // 1. Try to allocate from the free space area - if (pPage->pFreeEnd - pPage->pFreeStart > size + TDB_PAGE_OFFSET_SIZE(pPage)) { - pPage->pFreeEnd -= size; + ASSERT(nFree >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)); + ASSERT(TDB_PAGE_CCELLS(pPage) == pPage->pFreeEnd - pPage->pData); + + // 1. Try to allocate from the free space block area + if (pPage->pFreeEnd - pPage->pFreeStart >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); - pCell = pPage->pFreeEnd; + pPage->pFreeEnd -= szCell; + + TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData); + TDB_PAGE_NFREE_SET(pPage, nFree - szCell - TDB_PAGE_OFFSET_SIZE(pPage)); + + *ppCell = pPage->pFreeEnd; + return 0; } // 2. Try to allocate from the page free list - if ((pCell == NULL) && (pPage->pFreeEnd - pPage->pFreeStart >= TDB_PAGE_OFFSET_SIZE(pPage)) && - TDB_PAGE_FCELL(pPage)) { -#if 0 - int szCell; - int nxOffset; - - pCell = pPage->pData + TDB_PAGE_FCELL(pPage); - pOffset = TDB_IS_LARGE_PAGE(pPage) ? ((SPageHdrL *)(pPage->pPageHdr))[0].fCell - : (u8 *)&(((SPageHdr *)(pPage->pPageHdr))[0].fCell); - szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell); - nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell); + cellFree = TDB_PAGE_FCELL(pPage); + ASSERT(cellFree == 0 || cellFree > pPage->pFreeEnd - pPage->pData); + if (cellFree && pPage->pFreeEnd - pPage->pFreeStart >= TDB_PAGE_OFFSET_SIZE(pPage)) { + SCell *pPrevFreeCell = NULL; + int szPrevFreeCell; + int szFreeCell; + int nxFreeCell; + int newSize; for (;;) { - // Find a cell - if (szCell >= size) { - if (szCell - size >= pPage->szFreeCell) { - SCell *pTmpCell = pCell + size; + if (cellFree == 0) break; - TDB_PAGE_FREE_CELL_SIZE_SET(pPage, pTmpCell, szCell - size); - TDB_PAGE_FREE_CELL_NXOFFSET_SET(pPage, pTmpCell, nxOffset); - // TODO: *pOffset = pTmpCell - pPage->pData; + pFreeCell = pPage->pData + cellFree; + pPage->pPageMethods->getFreeCellInfo(pFreeCell, &szFreeCell, &nxFreeCell); + + if (szFreeCell >= szCell) { + pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); + TDB_PAGE_NFREE_SET(pPage, nFree - TDB_PAGE_OFFSET_SIZE(pPage) - szCell); + *ppCell = pFreeCell; + + newSize = szFreeCell - szCell; + pFreeCell += szCell; + if (newSize >= TDB_PAGE_FREE_CELL_SIZE(pPage)) { + pPage->pPageMethods->setFreeCellInfo(pFreeCell, newSize, nxFreeCell); + if (pPrevFreeCell) { + pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, pFreeCell - pPage->pData); + } else { + TDB_PAGE_FCELL_SET(pPage, pFreeCell - pPage->pData); + } + + return 0; } else { - TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_NFREE(pPage) + szCell - size); - // TODO: *pOffset = nxOffset; + if (pPrevFreeCell) { + pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, nxFreeCell); + } else { + TDB_PAGE_FCELL_SET(pPage, nxFreeCell); + } } - break; - } - - // Not find a cell yet - if (nxOffset > 0) { - pCell = pPage->pData + nxOffset; - pOffset = TDB_PAGE_FREE_CELL_NXOFFSET_PTR(pPage, pCell); - szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell); - nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell); - continue; } else { - pCell = NULL; - break; + pPrevFreeCell = pFreeCell; + szPrevFreeCell = szFreeCell; + cellFree = nxFreeCell; } } - - if (pCell) { - pPage->pFreeStart = pPage->pFreeStart + pPage->szOffset; - } -#endif } - // 3. Try to dfragment and allocate again +// 3. Try to dfragment and allocate again +#if 0 if (pCell == NULL) { ret = tdbPageDefragment(pPage); if (ret < 0) { @@ -175,7 +216,7 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { } ASSERT(pPage->pFreeEnd - pPage->pFreeStart > size + TDB_PAGE_OFFSET_SIZE(pPage)); - ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart); + // ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart); // Allocate from the free space area again pPage->pFreeEnd -= size; @@ -185,8 +226,9 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { ASSERT(pCell != NULL); - pPage->nFree = pPage->nFree - size - TDB_PAGE_OFFSET_SIZE(pPage); + // pPage->nFree = pPage->nFree - size - TDB_PAGE_OFFSET_SIZE(pPage); *ppCell = pCell; +#endif return 0; } @@ -210,6 +252,11 @@ typedef struct __attribute__((__packed__)) { u16 nFree; } SPageHdr; +typedef struct __attribute__((__packed__)) { + u16 szCell; + u16 nxOffset; +} SFreeCell; + // flags static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; } static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; } @@ -253,20 +300,35 @@ static inline void setPageCellOffset(SPage *pPage, int idx, int offset) { ((u16 *)pPage->pCellIdx)[idx] = (u16)offset; } +// free cell info +static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) { + SFreeCell *pFreeCell = (SFreeCell *)pCell; + *szCell = pFreeCell->szCell; + *nxOffset = pFreeCell->nxOffset; +} + +static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { + SFreeCell *pFreeCell = (SFreeCell *)pCell; + pFreeCell->szCell = szCell; + pFreeCell->nxOffset = nxOffset; +} + SPageMethods pageMethods = { - 2, // szOffset - sizeof(SPageHdr), // szPageHdr - sizeof(SFreeCell), // szFreeCell - getPageFlags, // getPageFlags - setPageFlags, // setFlagsp - getPageCellNum, // getCellNum - setPageCellNum, // setCellNum - getPageCellBody, // getCellBody - setPageCellBody, // setCellBody - getPageCellFree, // getCellFree - setPageCellFree, // setCellFree - getPageNFree, // getFreeBytes - setPageNFree, // setFreeBytes - getPageCellOffset, // getCellOffset - setPageCellOffset // setCellOffset + 2, // szOffset + sizeof(SPageHdr), // szPageHdr + sizeof(SFreeCell), // szFreeCell + getPageFlags, // getPageFlags + setPageFlags, // setFlagsp + getPageCellNum, // getCellNum + setPageCellNum, // setCellNum + getPageCellBody, // getCellBody + setPageCellBody, // setCellBody + getPageCellFree, // getCellFree + setPageCellFree, // setCellFree + getPageNFree, // getFreeBytes + setPageNFree, // setFreeBytes + getPageCellOffset, // getCellOffset + setPageCellOffset, // setCellOffset + getPageFreeCellInfo, // getFreeCellInfo + setPageFreeCellInfo // setFreeCellInfo }; \ No newline at end of file diff --git a/source/libs/tdb/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c index e7c60118d2..e3c1bb8d37 100644 --- a/source/libs/tdb/src/page/tdbPageL.c +++ b/source/libs/tdb/src/page/tdbPageL.c @@ -66,20 +66,35 @@ static inline void setPageCellOffset(SPage *pPage, int idx, int offset) { TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset); } +// free cell info +static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) { + SFreeCellL *pFreeCell = (SFreeCellL *)pCell; + *szCell = TDB_GET_U24(pFreeCell->szCell); + *nxOffset = TDB_GET_U24(pFreeCell->nxOffset); +} + +static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { + SFreeCellL *pFreeCell = (SFreeCellL *)pCell; + TDB_PUT_U24(pFreeCell->szCell, szCell); + TDB_PUT_U24(pFreeCell->nxOffset, nxOffset); +} + SPageMethods pageLargeMethods = { - 3, // szOffset - sizeof(SPageHdrL), // szPageHdr - sizeof(SFreeCellL), // szFreeCell - getPageFlags, // getPageFlags - setPageFlags, // setFlagsp - getPageCellNum, // getCellNum - setPageCellNum, // setCellNum - getPageCellBody, // getCellBody - setPageCellBody, // setCellBody - getPageCellFree, // getCellFree - setPageCellFree, // setCellFree - getPageNFree, // getFreeBytes - setPageNFree, // setFreeBytes - getPageCellOffset, // getCellOffset - setPageCellOffset // setCellOffset + 3, // szOffset + sizeof(SPageHdrL), // szPageHdr + sizeof(SFreeCellL), // szFreeCell + getPageFlags, // getPageFlags + setPageFlags, // setFlagsp + getPageCellNum, // getCellNum + setPageCellNum, // setCellNum + getPageCellBody, // getCellBody + setPageCellBody, // setCellBody + getPageCellFree, // getCellFree + setPageCellFree, // setCellFree + getPageNFree, // getFreeBytes + setPageNFree, // setFreeBytes + getPageCellOffset, // getCellOffset + setPageCellOffset, // setCellOffset + getPageFreeCellInfo, // getFreeCellInfo + setPageFreeCellInfo // setFreeCellInfo }; \ No newline at end of file From 57a92869ae28c7ce6f2776e521edcb879f9a4c77 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 09:45:49 +0000 Subject: [PATCH 002/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 46 +++++++++++------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index e198891338..892d7ecb31 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -141,6 +141,7 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { int nFree; int ret; int cellFree; + SCell *pCell = NULL; *ppCell = NULL; nFree = TDB_PAGE_NFREE(pPage); @@ -150,14 +151,10 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { // 1. Try to allocate from the free space block area if (pPage->pFreeEnd - pPage->pFreeStart >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { - pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); pPage->pFreeEnd -= szCell; - + pCell = pPage->pFreeEnd; TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData); - TDB_PAGE_NFREE_SET(pPage, nFree - szCell - TDB_PAGE_OFFSET_SIZE(pPage)); - - *ppCell = pPage->pFreeEnd; - return 0; + goto _alloc_finish; } // 2. Try to allocate from the page free list @@ -177,9 +174,7 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { pPage->pPageMethods->getFreeCellInfo(pFreeCell, &szFreeCell, &nxFreeCell); if (szFreeCell >= szCell) { - pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); - TDB_PAGE_NFREE_SET(pPage, nFree - TDB_PAGE_OFFSET_SIZE(pPage) - szCell); - *ppCell = pFreeCell; + pCell = pFreeCell; newSize = szFreeCell - szCell; pFreeCell += szCell; @@ -191,7 +186,7 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { TDB_PAGE_FCELL_SET(pPage, pFreeCell - pPage->pData); } - return 0; + goto _alloc_finish; } else { if (pPrevFreeCell) { pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, nxFreeCell); @@ -207,28 +202,21 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { } } -// 3. Try to dfragment and allocate again -#if 0 - if (pCell == NULL) { - ret = tdbPageDefragment(pPage); - if (ret < 0) { - return -1; - } + // 3. Try to dfragment and allocate again + tdbPageDefragment(pPage); + ASSERT(pPage->pFreeEnd - pPage->pFreeStart == nFree); + ASSERT(nFree == TDB_PAGE_NFREE(pPage)); + ASSERT(pPage->pFreeEnd - pPage->pData == TDB_PAGE_CCELLS(pPage)); - ASSERT(pPage->pFreeEnd - pPage->pFreeStart > size + TDB_PAGE_OFFSET_SIZE(pPage)); - // ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart); + pPage->pFreeEnd -= szCell; + pCell = pPage->pFreeEnd; + TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData); - // Allocate from the free space area again - pPage->pFreeEnd -= size; - pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); - pCell = pPage->pFreeEnd; - } - - ASSERT(pCell != NULL); - - // pPage->nFree = pPage->nFree - size - TDB_PAGE_OFFSET_SIZE(pPage); +_alloc_finish: + ASSERT(pCell); + pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage); + TDB_PAGE_NFREE_SET(pPage, nFree - szCell - TDB_PAGE_OFFSET_SIZE(pPage)); *ppCell = pCell; -#endif return 0; } From 0353e590814cfec20350627f07e5e11e3bcf6c67 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 12:02:26 +0000 Subject: [PATCH 003/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 892d7ecb31..1c9984cd01 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -220,8 +220,38 @@ _alloc_finish: return 0; } -static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) { - // TODO +static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell) { + int nFree; + int cellFree; + u8 *dest; + u8 *src; + + ASSERT(pCell >= pPage->pFreeEnd); + ASSERT(pCell + szCell <= (u8 *)(pPage->pPageFtr)); + ASSERT(pCell == TDB_PAGE_CELL_AT(pPage, idx)); + + nFree = TDB_PAGE_NFREE(pPage); + + if (pCell == pPage->pFreeEnd) { + pPage->pFreeEnd += szCell; + TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData); + } else { + if (szCell >= TDB_PAGE_FREE_CELL_SIZE(pPage)) { + cellFree = TDB_PAGE_FCELL(pPage); + pPage->pPageMethods->setFreeCellInfo(pCell, szCell, cellFree); + TDB_PAGE_FCELL_SET(pPage, pCell - pPage->pData); + } else { + ASSERT(0); + } + } + + dest = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * idx; + src = dest + TDB_PAGE_OFFSET_SIZE(pPage); + memmove(dest, src, pPage->pFreeStart - src); + + pPage->pFreeStart -= TDB_PAGE_OFFSET_SIZE(pPage); + nFree = nFree + szCell + TDB_PAGE_OFFSET_SIZE(pPage); + TDB_PAGE_NFREE_SET(pPage, nFree); return 0; } From dd7344c7800d88c6f444031319965130824cc7b7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 12:41:15 +0000 Subject: [PATCH 004/149] more TDB --- source/libs/tdb/src/inc/tdbPage.h | 1 + source/libs/tdb/src/page/tdbPage.c | 58 ++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 418a1b6626..9c40e9d5c1 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -75,6 +75,7 @@ struct SPage { int vLen; // value length of the page, -1 for unknown int maxLocal; int minLocal; + int (*xCellSize)(SCell *pCell); // Fields used by SPCache TDB_PCACHE_PAGE }; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 1c9984cd01..b10cd7b0ec 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -256,8 +256,62 @@ static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell) { } static int tdbPageDefragment(SPage *pPage) { - // TODO - ASSERT(0); + int nFree; + int nCells; + SCell *pCell; + SCell *pNextCell; + SCell *pTCell; + int szCell; + int idx; + int iCell; + + ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree); + + nFree = TDB_PAGE_NFREE(pPage); + nCells = TDB_PAGE_NCELLS(pPage); + + // Loop to compact the page content + // Here we use an O(n^2) algorithm to do the job since + // this is a low frequency job. + pNextCell = (u8 *)pPage->pPageFtr; + pCell = NULL; + for (iCell = 0;; iCell++) { + // compact over + if (iCell == nCells) { + pPage->pFreeEnd = pNextCell; + break; + } + + for (int i = 0; i < nCells; i++) { + if (TDB_PAGE_CELL_OFFSET_AT(pPage, i) < pNextCell - pPage->pData) { + pTCell = TDB_PAGE_CELL_AT(pPage, i); + if (pCell == NULL || pCell < pTCell) { + pCell = pTCell; + idx = i; + } + } else { + continue; + } + } + + ASSERT(pCell != NULL); + + szCell = (*pPage->xCellSize)(pCell); + + ASSERT(pCell + szCell <= pNextCell); + if (pCell + szCell < pNextCell) { + memmove(pNextCell - szCell, pCell, szCell); + } + + pCell = NULL; + pNextCell = pNextCell - szCell; + TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pNextCell - pPage->pData); + } + + ASSERT(pPage->pFreeEnd - pPage->pFreeStart == nFree); + TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData); + TDB_PAGE_FCELL_SET(pPage, 0); + return 0; } From f91124ef8edc8f2ae300270b46798a9885f7b81b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 13:00:51 +0000 Subject: [PATCH 005/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index b10cd7b0ec..9d679118e7 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -26,6 +26,7 @@ extern SPageMethods pageLargeMethods; static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell); static int tdbPageDefragment(SPage *pPage); +static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell); int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg) { SPage *pPage; @@ -131,7 +132,25 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { } int tdbPageDropCell(SPage *pPage, int idx) { - // TODO + int lidx; + SCell *pCell; + int szCell; + int nCells; + + nCells = TDB_PAGE_NCELLS(pPage); + + if (pPage->nOverflow == 0) { + lidx = idx; + } else { + // TODO + } + + pCell = TDB_PAGE_CELL_AT(pPage, lidx); + szCell = (*pPage->xCellSize)(pCell); + tdbPageFree(pPage, lidx, pCell, szCell); + + TDB_PAGE_NCELLS_SET(pPage, nCells - 1); + return 0; } From 6eb2e1b288d1363abf998b1604978a64340ad20a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 13:13:08 +0000 Subject: [PATCH 006/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 9d679118e7..d91a32cb7c 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -136,19 +136,26 @@ int tdbPageDropCell(SPage *pPage, int idx) { SCell *pCell; int szCell; int nCells; + int iOvfl; nCells = TDB_PAGE_NCELLS(pPage); - if (pPage->nOverflow == 0) { - lidx = idx; - } else { - // TODO + ASSERT(idx >= 0 && idx < nCells + pPage->nOverflow); + + iOvfl = 0; + for (; iOvfl < pPage->nOverflow; iOvfl++) { + if (pPage->aiOvfl[iOvfl] == idx) { + // TODO: remove the over flow cell + return 0; + } else if (pPage->aiOvfl[iOvfl] > idx) { + break; + } } + lidx = idx - iOvfl; pCell = TDB_PAGE_CELL_AT(pPage, lidx); szCell = (*pPage->xCellSize)(pCell); tdbPageFree(pPage, lidx, pCell, szCell); - TDB_PAGE_NCELLS_SET(pPage, nCells - 1); return 0; From 7d5030bc7fc2576411698f718f50fbaf7ff697ec Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 15:04:29 +0000 Subject: [PATCH 007/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index d91a32cb7c..2c9563d36d 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -145,7 +145,13 @@ int tdbPageDropCell(SPage *pPage, int idx) { iOvfl = 0; for (; iOvfl < pPage->nOverflow; iOvfl++) { if (pPage->aiOvfl[iOvfl] == idx) { - // TODO: remove the over flow cell + // remove the over flow cell + for (; (++iOvfl) < pPage->nOverflow;) { + pPage->aiOvfl[iOvfl - 1] = pPage->aiOvfl[iOvfl] - 1; + pPage->apOvfl[iOvfl - 1] = pPage->apOvfl[iOvfl]; + } + + pPage->nOverflow--; return 0; } else if (pPage->aiOvfl[iOvfl] > idx) { break; @@ -158,6 +164,11 @@ int tdbPageDropCell(SPage *pPage, int idx) { tdbPageFree(pPage, lidx, pCell, szCell); TDB_PAGE_NCELLS_SET(pPage, nCells - 1); + for (; iOvfl < pPage->nOverflow; iOvfl++) { + pPage->aiOvfl[iOvfl]--; + ASSERT(pPage->aiOvfl[iOvfl] > 0); + } + return 0; } From 7a5985ae46de83a3fbe359aa5d79e21e54b4a8de Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 20 Mar 2022 15:39:51 +0000 Subject: [PATCH 008/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 39 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 2c9563d36d..4673a561e6 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -91,8 +91,8 @@ void tdbPageInit(SPage *pPage) { int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { int nFree; - int ret; int nCells; + int iOvfl; int lidx; // local idx SCell *pNewCell; @@ -100,32 +100,45 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { nFree = TDB_PAGE_NFREE(pPage); nCells = TDB_PAGE_NCELLS(pPage); + iOvfl = 0; + + for (; iOvfl < pPage->nOverflow; iOvfl++) { + if (pPage->aiOvfl[iOvfl] >= idx) { + break; + } + } + + lidx = idx - iOvfl; if (nFree >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { // page must has enough space to hold the cell locally - ret = tdbPageAllocate(pPage, szCell, &pNewCell); - ASSERT(ret == 0); + tdbPageAllocate(pPage, szCell, &pNewCell); memcpy(pNewCell, pCell, szCell); - if (pPage->nOverflow == 0) { - lidx = idx; - } else { - // TODO - // lidx = ; - } - // no overflow cell exists in this page u8 *src = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * lidx; u8 *dest = src + TDB_PAGE_OFFSET_SIZE(pPage); memmove(dest, src, pPage->pFreeStart - dest); TDB_PAGE_CELL_OFFSET_AT_SET(pPage, lidx, TDB_PAGE_OFFSET_SIZE(pPage) * lidx); TDB_PAGE_NCELLS_SET(pPage, nCells + 1); + + ASSERT(pPage->pFreeStart == pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * (nCells + 1)); } else { - // TODO: page not has enough space - pPage->apOvfl[pPage->nOverflow] = pCell; - pPage->aiOvfl[pPage->nOverflow] = idx; + // add the cell as an overflow cell + for (int i = pPage->nOverflow; i > iOvfl; i--) { + pPage->apOvfl[i] = pPage->apOvfl[i - 1]; + pPage->aiOvfl[i] = pPage->aiOvfl[i - 1]; + } + + pPage->apOvfl[iOvfl] = pCell; + pPage->aiOvfl[iOvfl] = idx; pPage->nOverflow++; + iOvfl++; + } + + for (; iOvfl < pPage->nOverflow; iOvfl++) { + pPage->aiOvfl[iOvfl]++; } return 0; From 13b7ba3edb940b226754215ecd17af97025eb727 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 02:27:46 +0000 Subject: [PATCH 009/149] refact TDB --- source/libs/tdb/src/db/tdbBtree.c | 63 +++++++++++++++++------------- source/libs/tdb/src/inc/tdbPage.h | 44 +++++++++++++-------- source/libs/tdb/src/page/tdbPage.c | 20 ++++++++-- 3 files changed, 80 insertions(+), 47 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 423de0b53c..621afc9dfb 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -145,7 +145,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p } if (pCur->idx == -1) { - ASSERT(TDB_PAGE_NCELLS(pCur->pPage) == 0); + ASSERT(TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0); idx = 0; } else { if (cret > 0) { @@ -218,7 +218,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p pCur->iPage = 0; - if (TDB_PAGE_NCELLS(pCur->pPage) == 0) { + if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) { // Current page is empty ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); return 0; @@ -231,7 +231,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p SCellDecoder cd = {0}; pPage = pCur->pPage; - nCells = TDB_PAGE_NCELLS(pPage); + nCells = TDB_PAGE_TOTAL_CELLS(pPage); lidx = 0; ridx = nCells - 1; @@ -242,7 +242,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p midx = (lidx + ridx) >> 1; - pCell = TDB_PAGE_CELL_AT(pPage, midx); + pCell = tdbPageGetCell(pPage, midx); ret = tdbBtreeDecodeCell(pPage, pCell, &cd); if (ret < 0) { // TODO: handle error @@ -283,7 +283,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p } else { // TODO: reset cd as uninitialized pCur->idx = midx + 1; - pCell = TDB_PAGE_CELL_AT(pPage, midx + 1); + pCell = tdbPageGetCell(pPage, midx + 1); tdbBtreeDecodeCell(pPage, pCell, &cd); tdbBtCursorMoveToChild(pCur, cd.pgno); } @@ -391,16 +391,12 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { } else { pPage->szAmHdr = sizeof(SBtPageHdr); } - pPage->pPageHdr = pPage->pData; - pPage->pAmHdr = pPage->pPageHdr + pPage->pPageMethods->szPageHdr; - pPage->pCellIdx = pPage->pAmHdr + pPage->szAmHdr; - pPage->pFreeStart = pPage->pCellIdx + pPage->pPageMethods->szOffset * TDB_PAGE_NCELLS(pPage); - pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); - pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr)); + pPage->xCellSize = NULL; // TODO + + tdbPageInit(pPage); TDB_BTREE_ASSERT_FLAG(flags); - // Init other fields if (isLeaf) { pPage->kLen = pBt->keyLen; pPage->vLen = pBt->valLen; @@ -413,30 +409,41 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { pPage->minLocal = pBt->minLocal; } - // TODO: need to update the SPage.nFree - // pPage->nFree = pPage->pFreeEnd - pPage->pFreeStart; - pPage->nOverflow = 0; - return 0; } static int tdbBtreeZeroPage(SPage *pPage, void *arg) { u16 flags; SBTree *pBt; + u8 isLeaf; flags = ((SBtreeZeroPageArg *)arg)->flags; pBt = ((SBtreeZeroPageArg *)arg)->pBt; - - pPage->pPageHdr = pPage->pData; + isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); // Init the page header TDB_PAGE_FLAGS_SET(pPage, flags); - TDB_PAGE_NCELLS_SET(pPage, 0); - TDB_PAGE_CCELLS_SET(pPage, pBt->pageSize - sizeof(SPageFtr)); - TDB_PAGE_FCELL_SET(pPage, 0); - TDB_PAGE_NFREE_SET(pPage, 0); + // Set szAmHdr + if (isLeaf) { + pPage->szAmHdr = 0; + } else { + pPage->szAmHdr = sizeof(SBtPageHdr); + } + pPage->xCellSize = NULL; // TODO - tdbBtreeInitPage(pPage, (void *)pBt); + tdbPageZero(pPage); + + if (isLeaf) { + pPage->kLen = pBt->keyLen; + pPage->vLen = pBt->valLen; + pPage->maxLocal = pBt->maxLeaf; + pPage->minLocal = pBt->minLeaf; + } else { + pPage->kLen = pBt->keyLen; + pPage->vLen = sizeof(SPgno); + pPage->maxLocal = pBt->maxLocal; + pPage->minLocal = pBt->minLocal; + } return 0; } @@ -453,7 +460,8 @@ typedef struct { } SBtreeBalanceHelper; static int tdbBtreeCopyPageContent(SPage *pFrom, SPage *pTo) { - int nCells = TDB_PAGE_NCELLS(pFrom); +#if 0 + int nCells = TDB_PAGE_TOTAL_CELLS(pFrom); int cCells = TDB_PAGE_CCELLS(pFrom); int fCell = TDB_PAGE_FCELL(pFrom); int nFree = TDB_PAGE_NFREE(pFrom); @@ -469,6 +477,7 @@ static int tdbBtreeCopyPageContent(SPage *pFrom, SPage *pTo) { TDB_PAGE_NFREE_SET(pTo, nFree); // TODO: update other fields +#endif return 0; } @@ -529,7 +538,7 @@ static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) { SBTree *pBt; pParent = pBlh->pParent; - nCells = TDB_PAGE_NCELLS(pParent); + nCells = TDB_PAGE_TOTAL_CELLS(pParent); nChild = nCells + 1; pBt = pBlh->pBt; @@ -556,7 +565,7 @@ static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) { if (idxStart + i == nCells) { pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild; } else { - pCell = TDB_PAGE_CELL_AT(pParent, idxStart + i); + pCell = tdbPageGetCell(pParent, idxStart + i); // TODO: no need to decode the payload part, and even the kLen, vLen part // we only need the pgno part ret = tdbBtreeDecodeCell(pParent, pCell, &cd); @@ -610,7 +619,7 @@ static int tdbBtreeBalanceStep2(SBtreeBalanceHelper *pBlh) { if (cidx < limit) { // Get local cells - pCell = TDB_PAGE_CELL_AT(pPage, cidx); + pCell = tdbPageGetCell(pPage, cidx); } else if (cidx == limit) { // Get overflow cells pCell = pPage->apOvfl[oidx++]; diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 9c40e9d5c1..82287b0921 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -57,8 +57,8 @@ typedef struct __attribute__((__packed__)) { struct SPage { pthread_spinlock_t lock; - u8 *pData; int pageSize; + u8 *pData; SPageMethods *pPageMethods; // Fields below used by pager and am u8 szAmHdr; @@ -81,21 +81,8 @@ struct SPage { }; /* For page */ -#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage) -#define TDB_PAGE_NCELLS(pPage) (*(pPage)->pPageMethods->getCellNum)(pPage) -#define TDB_PAGE_CCELLS(pPage) (*(pPage)->pPageMethods->getCellBody)(pPage) -#define TDB_PAGE_FCELL(pPage) (*(pPage)->pPageMethods->getCellFree)(pPage) -#define TDB_PAGE_NFREE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) -#define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) (*(pPage)->pPageMethods->getCellOffset)(pPage, idx) - -#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS) -#define TDB_PAGE_NCELLS_SET(pPage, NCELLS) (*(pPage)->pPageMethods->setCellNum)(pPage, NCELLS) -#define TDB_PAGE_CCELLS_SET(pPage, CCELLS) (*(pPage)->pPageMethods->setCellBody)(pPage, CCELLS) -#define TDB_PAGE_FCELL_SET(pPage, FCELL) (*(pPage)->pPageMethods->setCellFree)(pPage, FCELL) -#define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE) -#define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET) - -#define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx)) +#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage) +#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS) // For page lock #define P_LOCK_SUCC 0 @@ -120,6 +107,8 @@ struct SPage { }) // APIs +#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) + int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); void tdbPageZero(SPage *pPage); @@ -127,6 +116,29 @@ void tdbPageInit(SPage *pPage); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); int tdbPageDropCell(SPage *pPage, int idx); +static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { + SCell *pCell; + int iOvfl; + int lidx; + + ASSERT(idx >= 0 && idx < pPage->nOverflow + pPage->pPageMethods->getCellNum(pPage)); + + iOvfl = 0; + for (; iOvfl < pPage->nOverflow; iOvfl++) { + if (pPage->aiOvfl[iOvfl] == idx) { + pCell = pPage->apOvfl[iOvfl]; + return pCell; + } else if (pPage->aiOvfl[iOvfl] > idx) { + break; + } + } + + lidx = idx - iOvfl; + pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx); + + return pCell; +} + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 4673a561e6..2b0e573aae 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -18,9 +18,20 @@ extern SPageMethods pageMethods; extern SPageMethods pageLargeMethods; -#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) -#define TDB_PAGE_HDR_SIZE(pPage) ((pPage)->pPageMethods->szPageHdr) -#define TDB_PAGE_FREE_CELL_SIZE(pPage) ((pPage)->pPageMethods->szFreeCell) +#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) +#define TDB_PAGE_HDR_SIZE(pPage) ((pPage)->pPageMethods->szPageHdr) +#define TDB_PAGE_FREE_CELL_SIZE(pPage) ((pPage)->pPageMethods->szFreeCell) +#define TDB_PAGE_NCELLS(pPage) (*(pPage)->pPageMethods->getCellNum)(pPage) +#define TDB_PAGE_CCELLS(pPage) (*(pPage)->pPageMethods->getCellBody)(pPage) +#define TDB_PAGE_FCELL(pPage) (*(pPage)->pPageMethods->getCellFree)(pPage) +#define TDB_PAGE_NFREE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) +#define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) (*(pPage)->pPageMethods->getCellOffset)(pPage, idx) +#define TDB_PAGE_NCELLS_SET(pPage, NCELLS) (*(pPage)->pPageMethods->setCellNum)(pPage, NCELLS) +#define TDB_PAGE_CCELLS_SET(pPage, CCELLS) (*(pPage)->pPageMethods->setCellBody)(pPage, CCELLS) +#define TDB_PAGE_FCELL_SET(pPage, FCELL) (*(pPage)->pPageMethods->setCellFree)(pPage, FCELL) +#define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE) +#define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET) +#define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx)) #define TDB_PAGE_MAX_FREE_BLOCK(pPage) \ ((pPage)->pageSize - (pPage)->szAmHdr - TDB_PAGE_HDR_SIZE(pPage) - sizeof(SPageFtr)) @@ -47,8 +58,8 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) pPage = (SPage *)(ptr + pageSize); TDB_INIT_PAGE_LOCK(pPage); - pPage->pData = ptr; pPage->pageSize = pageSize; + pPage->pData = ptr; if (pageSize < 65536) { pPage->pPageMethods = &pageMethods; } else { @@ -125,6 +136,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { ASSERT(pPage->pFreeStart == pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * (nCells + 1)); } else { + // TODO: make it extensible // add the cell as an overflow cell for (int i = pPage->nOverflow; i > iOvfl; i--) { pPage->apOvfl[i] = pPage->apOvfl[i - 1]; From cde7a7c6a1558a8bb76ad3d7bd83fef44fc89172 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 02:54:00 +0000 Subject: [PATCH 010/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 14 ++++++++------ source/libs/tdb/src/inc/tdbPage.h | 6 +++--- source/libs/tdb/src/page/tdbPage.c | 24 ++++++++++++++++-------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 621afc9dfb..0c83dd609c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -381,19 +381,20 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { SBTree *pBt; u16 flags; u8 isLeaf; + u8 szAmHdr; pBt = (SBTree *)arg; flags = TDB_PAGE_FLAGS(pPage); isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (isLeaf) { - pPage->szAmHdr = 0; + szAmHdr = 0; } else { - pPage->szAmHdr = sizeof(SBtPageHdr); + szAmHdr = sizeof(SBtPageHdr); } pPage->xCellSize = NULL; // TODO - tdbPageInit(pPage); + tdbPageInit(pPage, szAmHdr); TDB_BTREE_ASSERT_FLAG(flags); @@ -416,6 +417,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { u16 flags; SBTree *pBt; u8 isLeaf; + u8 szAmHdr; flags = ((SBtreeZeroPageArg *)arg)->flags; pBt = ((SBtreeZeroPageArg *)arg)->pBt; @@ -425,13 +427,13 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { TDB_PAGE_FLAGS_SET(pPage, flags); // Set szAmHdr if (isLeaf) { - pPage->szAmHdr = 0; + szAmHdr = 0; } else { - pPage->szAmHdr = sizeof(SBtPageHdr); + szAmHdr = sizeof(SBtPageHdr); } pPage->xCellSize = NULL; // TODO - tdbPageZero(pPage); + tdbPageZero(pPage, szAmHdr); if (isLeaf) { pPage->kLen = pBt->keyLen; diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 82287b0921..58ae1f3963 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -61,7 +61,6 @@ struct SPage { u8 *pData; SPageMethods *pPageMethods; // Fields below used by pager and am - u8 szAmHdr; u8 *pAmHdr; u8 *pPageHdr; u8 *pCellIdx; @@ -111,8 +110,8 @@ struct SPage { int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); -void tdbPageZero(SPage *pPage); -void tdbPageInit(SPage *pPage); +void tdbPageZero(SPage *pPage, u8 szAmHdr); +void tdbPageInit(SPage *pPage, u8 szAmHdr); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); int tdbPageDropCell(SPage *pPage, int idx); @@ -134,6 +133,7 @@ static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { } lidx = idx - iOvfl; + ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage)); pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx); return pCell; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 2b0e573aae..11c9a9247e 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -32,8 +32,8 @@ extern SPageMethods pageLargeMethods; #define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE) #define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET) #define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx)) -#define TDB_PAGE_MAX_FREE_BLOCK(pPage) \ - ((pPage)->pageSize - (pPage)->szAmHdr - TDB_PAGE_HDR_SIZE(pPage) - sizeof(SPageFtr)) +#define TDB_PAGE_MAX_FREE_BLOCK(pPage, szAmHdr) \ + ((pPage)->pageSize - (szAmHdr)-TDB_PAGE_HDR_SIZE(pPage) - sizeof(SPageFtr)) static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell); static int tdbPageDefragment(SPage *pPage); @@ -79,17 +79,25 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) return 0; } -void tdbPageZero(SPage *pPage) { +void tdbPageZero(SPage *pPage, u8 szAmHdr) { + pPage->pAmHdr = pPage->pData; + pPage->pPageHdr = pPage->pAmHdr + szAmHdr; TDB_PAGE_NCELLS_SET(pPage, 0); TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr)); TDB_PAGE_FCELL_SET(pPage, 0); - TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_MAX_FREE_BLOCK(pPage)); - tdbPageInit(pPage); + TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_MAX_FREE_BLOCK(pPage, szAmHdr)); + pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); + pPage->pFreeStart = pPage->pCellIdx; + pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); + pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr)); + pPage->nOverflow = 0; + + ASSERT((u8 *)pPage->pPageFtr == pPage->pFreeEnd); } -void tdbPageInit(SPage *pPage) { +void tdbPageInit(SPage *pPage, u8 szAmHdr) { pPage->pAmHdr = pPage->pData; - pPage->pPageHdr = pPage->pAmHdr + pPage->szAmHdr; + pPage->pPageHdr = pPage->pAmHdr + szAmHdr; pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage); pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); @@ -107,7 +115,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { int lidx; // local idx SCell *pNewCell; - ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage)); + ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage, pPage->pPageHdr - pPage->pAmHdr)); nFree = TDB_PAGE_NFREE(pPage); nCells = TDB_PAGE_NCELLS(pPage); From 50aa291ff60089a8270f3b85f3e4bd84d0a2aae9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 03:29:39 +0000 Subject: [PATCH 011/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0c83dd609c..59c132ecb2 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -423,9 +423,6 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { pBt = ((SBtreeZeroPageArg *)arg)->pBt; isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); - // Init the page header - TDB_PAGE_FLAGS_SET(pPage, flags); - // Set szAmHdr if (isLeaf) { szAmHdr = 0; } else { @@ -433,6 +430,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { } pPage->xCellSize = NULL; // TODO + TDB_PAGE_FLAGS_SET(pPage, flags); tdbPageZero(pPage, szAmHdr); if (isLeaf) { From 03eaa648d68c2b9f11a54f780d88e13630809d99 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 03:42:18 +0000 Subject: [PATCH 012/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 59c132ecb2..52f0c7d466 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -385,6 +385,9 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { pBt = (SBTree *)arg; + ASSERT(0); + + // TODO: here has problem flags = TDB_PAGE_FLAGS(pPage); isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (isLeaf) { @@ -430,8 +433,8 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { } pPage->xCellSize = NULL; // TODO - TDB_PAGE_FLAGS_SET(pPage, flags); tdbPageZero(pPage, szAmHdr); + TDB_PAGE_FLAGS_SET(pPage, flags); if (isLeaf) { pPage->kLen = pBt->keyLen; From 4e8f8445de7f719dbef9a75321253df3d4b1fff5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 05:47:06 +0000 Subject: [PATCH 013/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 41 +++++++++++++++++------------ source/libs/tdb/src/inc/tdbPage.h | 4 +++ source/libs/tdb/src/page/tdbPage.c | 10 ++++--- source/libs/tdb/src/page/tdbPageL.c | 10 ++++--- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 52f0c7d466..4b2394f861 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -39,9 +39,16 @@ struct SBTree { u8 *pTmp; }; +#define TDB_BTREE_PAGE_COMMON_HDR u8 flags; + typedef struct __attribute__((__packed__)) { - SPgno rChild; -} SBtPageHdr; + TDB_BTREE_PAGE_COMMON_HDR +} SLeafHdr; + +typedef struct __attribute__((__packed__)) { + TDB_BTREE_PAGE_COMMON_HDR; + SPgno pgno; // right-most child +} SIntHdr; typedef struct { u16 flags; @@ -220,7 +227,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) { // Current page is empty - ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); + // ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); return 0; } @@ -265,7 +272,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p } // Move downward or break - u16 flags = TDB_PAGE_FLAGS(pPage); + u16 flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (leaf) { pCur->idx = midx; @@ -279,7 +286,7 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p if (midx == nCells - 1) { /* Move to right-most child */ pCur->idx = midx + 1; - tdbBtCursorMoveToChild(pCur, ((SBtPageHdr *)(pPage->pAmHdr))->rChild); + // tdbBtCursorMoveToChild(pCur, ((SBtPageHdr *)(pPage->pAmHdr))->rChild); } else { // TODO: reset cd as uninitialized pCur->idx = midx + 1; @@ -388,12 +395,12 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { ASSERT(0); // TODO: here has problem - flags = TDB_PAGE_FLAGS(pPage); + flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (isLeaf) { - szAmHdr = 0; + szAmHdr = sizeof(SLeafHdr); } else { - szAmHdr = sizeof(SBtPageHdr); + szAmHdr = sizeof(SIntHdr); } pPage->xCellSize = NULL; // TODO @@ -427,14 +434,14 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (isLeaf) { - szAmHdr = 0; + szAmHdr = sizeof(SLeafHdr); } else { - szAmHdr = sizeof(SBtPageHdr); + szAmHdr = sizeof(SIntHdr); } pPage->xCellSize = NULL; // TODO tdbPageZero(pPage, szAmHdr); - TDB_PAGE_FLAGS_SET(pPage, flags); + // TDB_PAGE_FLAGS_SET(pPage, flags); if (isLeaf) { pPage->kLen = pBt->keyLen; @@ -522,7 +529,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { return -1; } - ((SBtPageHdr *)pRoot->pAmHdr)[0].rChild = pgnoChild; + // TODO: ((SBtPageHdr *)pRoot->pAmHdr)[0].rChild = pgnoChild; *ppChild = pChild; return 0; @@ -566,7 +573,7 @@ static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) { i = pBlh->nOld - 1; if (idxStart + i == nCells) { - pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild; + // pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild; } else { pCell = tdbPageGetCell(pParent, idxStart + i); // TODO: no need to decode the payload part, and even the kLen, vLen part @@ -676,7 +683,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int ret; SBtreeBalanceHelper blh; - ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_PAGE_FLAGS(pParent))); + // ASSERT(!TDB_BTREE_PGE_IS_LEAF(TDB_PAGE_FLAGS(pParent))); blh.pBt = pBt; blh.pParent = pParent; @@ -748,7 +755,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) { for (;;) { iPage = pCur->iPage; pPage = pCur->pPage; - flags = TDB_PAGE_FLAGS(pPage); + flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); root = TDB_BTREE_PAGE_IS_ROOT(flags); @@ -842,7 +849,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo nPayload = 0; nHeader = 0; - flags = TDB_PAGE_FLAGS(pPage); + flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // 1. Encode Header part @@ -911,7 +918,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD int ret; nHeader = 0; - flags = TDB_PAGE_FLAGS(pPage); + flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // Clear the state of decoder diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 58ae1f3963..155e7b2e37 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -27,9 +27,11 @@ typedef struct { int szOffset; int szPageHdr; int szFreeCell; +#if 0 // flags u16 (*getFlags)(SPage *); void (*setFlags)(SPage *, u16); +#endif // cell number int (*getCellNum)(SPage *); void (*setCellNum)(SPage *, int); @@ -79,9 +81,11 @@ struct SPage { TDB_PCACHE_PAGE }; +#if 0 /* For page */ #define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage) #define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS) +#endif // For page lock #define P_LOCK_SUCC 0 diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 11c9a9247e..61793b6025 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -399,9 +399,11 @@ typedef struct __attribute__((__packed__)) { u16 nxOffset; } SFreeCell; +#if 0 // flags static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; } static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; } +#endif // cellNum static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; } @@ -456,11 +458,13 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { } SPageMethods pageMethods = { - 2, // szOffset - sizeof(SPageHdr), // szPageHdr - sizeof(SFreeCell), // szFreeCell + 2, // szOffset + sizeof(SPageHdr), // szPageHdr + sizeof(SFreeCell), // szFreeCell +#if 0 getPageFlags, // getPageFlags setPageFlags, // setFlagsp +#endif getPageCellNum, // getCellNum setPageCellNum, // setCellNum getPageCellBody, // getCellBody diff --git a/source/libs/tdb/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c index e3c1bb8d37..f4bcc62494 100644 --- a/source/libs/tdb/src/page/tdbPageL.c +++ b/source/libs/tdb/src/page/tdbPageL.c @@ -28,9 +28,11 @@ typedef struct __attribute__((__packed__)) { u8 nxOffset[3]; } SFreeCellL; +#if 0 // flags static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdrL *)(pPage->pPageHdr))[0].flags; } static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdrL *)(pPage->pPageHdr))[0].flags = flags; } +#endif // cellNum static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); } @@ -80,11 +82,13 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { } SPageMethods pageLargeMethods = { - 3, // szOffset - sizeof(SPageHdrL), // szPageHdr - sizeof(SFreeCellL), // szFreeCell + 3, // szOffset + sizeof(SPageHdrL), // szPageHdr + sizeof(SFreeCellL), // szFreeCell +#if 0 getPageFlags, // getPageFlags setPageFlags, // setFlagsp +#endif getPageCellNum, // getCellNum setPageCellNum, // setCellNum getPageCellBody, // getCellBody From df306127a644ebec5d8dc6ff37264ed8c4d9fed3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 05:56:33 +0000 Subject: [PATCH 014/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 3 ++- source/libs/tdb/src/inc/tdbPage.h | 11 ----------- source/libs/tdb/src/page/tdbPage.c | 16 +++------------- source/libs/tdb/src/page/tdbPageL.c | 16 +++------------- 4 files changed, 8 insertions(+), 38 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4b2394f861..68319da3b2 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -39,7 +39,8 @@ struct SBTree { u8 *pTmp; }; -#define TDB_BTREE_PAGE_COMMON_HDR u8 flags; +#define TDB_BTREE_PAGE_COMMON_HDR u8 flags; +#define TDB_BTREE_PAGE_FLAGS(PAGE) (PAGE)->pAmHdr[0] typedef struct __attribute__((__packed__)) { TDB_BTREE_PAGE_COMMON_HDR diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 155e7b2e37..dc3b803708 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -27,11 +27,6 @@ typedef struct { int szOffset; int szPageHdr; int szFreeCell; -#if 0 - // flags - u16 (*getFlags)(SPage *); - void (*setFlags)(SPage *, u16); -#endif // cell number int (*getCellNum)(SPage *); void (*setCellNum)(SPage *, int); @@ -81,12 +76,6 @@ struct SPage { TDB_PCACHE_PAGE }; -#if 0 -/* For page */ -#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage) -#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS) -#endif - // For page lock #define P_LOCK_SUCC 0 #define P_LOCK_BUSY 1 diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 61793b6025..b3a3bdbdcc 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -399,12 +399,6 @@ typedef struct __attribute__((__packed__)) { u16 nxOffset; } SFreeCell; -#if 0 -// flags -static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; } -static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; } -#endif - // cellNum static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; } static inline void setPageCellNum(SPage *pPage, int cellNum) { @@ -458,13 +452,9 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { } SPageMethods pageMethods = { - 2, // szOffset - sizeof(SPageHdr), // szPageHdr - sizeof(SFreeCell), // szFreeCell -#if 0 - getPageFlags, // getPageFlags - setPageFlags, // setFlagsp -#endif + 2, // szOffset + sizeof(SPageHdr), // szPageHdr + sizeof(SFreeCell), // szFreeCell getPageCellNum, // getCellNum setPageCellNum, // setCellNum getPageCellBody, // getCellBody diff --git a/source/libs/tdb/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c index f4bcc62494..cfd8c919df 100644 --- a/source/libs/tdb/src/page/tdbPageL.c +++ b/source/libs/tdb/src/page/tdbPageL.c @@ -28,12 +28,6 @@ typedef struct __attribute__((__packed__)) { u8 nxOffset[3]; } SFreeCellL; -#if 0 -// flags -static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdrL *)(pPage->pPageHdr))[0].flags; } -static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdrL *)(pPage->pPageHdr))[0].flags = flags; } -#endif - // cellNum static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); } static inline void setPageCellNum(SPage *pPage, int cellNum) { @@ -82,13 +76,9 @@ static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) { } SPageMethods pageLargeMethods = { - 3, // szOffset - sizeof(SPageHdrL), // szPageHdr - sizeof(SFreeCellL), // szFreeCell -#if 0 - getPageFlags, // getPageFlags - setPageFlags, // setFlagsp -#endif + 3, // szOffset + sizeof(SPageHdrL), // szPageHdr + sizeof(SFreeCellL), // szFreeCell getPageCellNum, // getCellNum setPageCellNum, // setCellNum getPageCellBody, // getCellBody From 2b7da2a79b1972c35853419cb564e9e429f40609 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:05:32 +0000 Subject: [PATCH 015/149] more TDB --- source/libs/tdb/src/btree/tdbBtreeBalance.c | 14 +++++++++++ source/libs/tdb/src/btree/tdbBtreeCommon.c | 14 +++++++++++ source/libs/tdb/src/btree/tdbBtreeInt.h | 27 +++++++++++++++++++++ source/libs/tdb/src/btree/tdbBtreeOpen.c | 14 +++++++++++ 4 files changed, 69 insertions(+) create mode 100644 source/libs/tdb/src/btree/tdbBtreeBalance.c create mode 100644 source/libs/tdb/src/btree/tdbBtreeCommon.c create mode 100644 source/libs/tdb/src/btree/tdbBtreeInt.h create mode 100644 source/libs/tdb/src/btree/tdbBtreeOpen.c diff --git a/source/libs/tdb/src/btree/tdbBtreeBalance.c b/source/libs/tdb/src/btree/tdbBtreeBalance.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeBalance.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeCommon.c b/source/libs/tdb/src/btree/tdbBtreeCommon.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeCommon.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeInt.h b/source/libs/tdb/src/btree/tdbBtreeInt.h new file mode 100644 index 0000000000..b8a935a614 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeInt.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TDB_BTREE_INT_H_ +#define _TDB_BTREE_INT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_BTREE_INT_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeOpen.c b/source/libs/tdb/src/btree/tdbBtreeOpen.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeOpen.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file From d9c4bcab6ccb19c9494587472c7ee6598e7cdd94 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:14:47 +0000 Subject: [PATCH 016/149] more TDB --- source/libs/tdb/CMakeLists.txt | 1 - source/libs/tdb/src/btree/tdbBtreeDelete.c | 14 ++++++++++++++ source/libs/tdb/src/btree/tdbBtreeInsert.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 source/libs/tdb/src/btree/tdbBtreeDelete.c create mode 100644 source/libs/tdb/src/btree/tdbBtreeInsert.c diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 978649499a..a9b56d42b8 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -8,7 +8,6 @@ target_sources(tdb "src/db/tdbBtree.c" "src/db/tdbDb.c" "src/db/tdbEnv.c" - # "src/db/tdbPage.c" "src/page/tdbPage.c" "src/page/tdbPageL.c" ) diff --git a/source/libs/tdb/src/btree/tdbBtreeDelete.c b/source/libs/tdb/src/btree/tdbBtreeDelete.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeDelete.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file diff --git a/source/libs/tdb/src/btree/tdbBtreeInsert.c b/source/libs/tdb/src/btree/tdbBtreeInsert.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/btree/tdbBtreeInsert.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file From a84155b951b24d87b204a2a4009c9c19cbe6f2cc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:23:32 +0000 Subject: [PATCH 017/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 21 ++++++++++++++------- source/libs/tdb/src/inc/tdbPage.h | 2 +- source/libs/tdb/src/page/tdbPage.c | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 68319da3b2..2a2d630cd8 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -52,9 +52,9 @@ typedef struct __attribute__((__packed__)) { } SIntHdr; typedef struct { - u16 flags; + u8 flags; SBTree *pBt; -} SBtreeZeroPageArg; +} SBtreeInitPageArg; typedef struct { int kLen; @@ -74,6 +74,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo int *szCell); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); static int tdbBtreeBalance(SBtCursor *pCur); +static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { SBTree *pBt; @@ -371,7 +372,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { } // Try to create a new database - SBtreeZeroPageArg zArg = {.flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF, .pBt = pBt}; + SBtreeInitPageArg zArg = {.flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF, .pBt = pBt}; ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage, tdbBtreeZeroPage, &zArg); if (ret < 0) { return -1; @@ -430,8 +431,8 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { u8 isLeaf; u8 szAmHdr; - flags = ((SBtreeZeroPageArg *)arg)->flags; - pBt = ((SBtreeZeroPageArg *)arg)->pBt; + flags = ((SBtreeInitPageArg *)arg)->flags; + pBt = ((SBtreeInitPageArg *)arg)->pBt; isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (isLeaf) { @@ -498,7 +499,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { SPage *pChild; SPgno pgnoChild; int ret; - SBtreeZeroPageArg zArg; + SBtreeInitPageArg zArg; pPager = pRoot->pPager; @@ -959,4 +960,10 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD return 0; } -#endif \ No newline at end of file +#endif + +static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { + // TODO + ASSERT(0); + return 0; +} \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index dc3b803708..0960d88c33 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -71,7 +71,7 @@ struct SPage { int vLen; // value length of the page, -1 for unknown int maxLocal; int minLocal; - int (*xCellSize)(SCell *pCell); + int (*xCellSize)(const SPage *, SCell *); // Fields used by SPCache TDB_PCACHE_PAGE }; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index b3a3bdbdcc..7088904285 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -193,7 +193,7 @@ int tdbPageDropCell(SPage *pPage, int idx) { lidx = idx - iOvfl; pCell = TDB_PAGE_CELL_AT(pPage, lidx); - szCell = (*pPage->xCellSize)(pCell); + szCell = (*pPage->xCellSize)(pPage, pCell); tdbPageFree(pPage, lidx, pCell, szCell); TDB_PAGE_NCELLS_SET(pPage, nCells - 1); @@ -366,7 +366,7 @@ static int tdbPageDefragment(SPage *pPage) { ASSERT(pCell != NULL); - szCell = (*pPage->xCellSize)(pCell); + szCell = (*pPage->xCellSize)(pPage, pCell); ASSERT(pCell + szCell <= pNextCell); if (pCell + szCell < pNextCell) { From 0a6be10ff1d1f5b35c0ffceb095485347f774194 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:34:34 +0000 Subject: [PATCH 018/149] more tdb --- source/libs/tdb/src/db/tdbBtree.c | 44 ++++++++++++++---------------- source/libs/tdb/src/inc/tdbPage.h | 4 +-- source/libs/tdb/src/page/tdbPage.c | 6 ++-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 2a2d630cd8..06f96e5498 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -39,8 +39,10 @@ struct SBTree { u8 *pTmp; }; -#define TDB_BTREE_PAGE_COMMON_HDR u8 flags; -#define TDB_BTREE_PAGE_FLAGS(PAGE) (PAGE)->pAmHdr[0] +#define TDB_BTREE_PAGE_COMMON_HDR u8 flags; + +#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pAmHdr[0] +#define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pAmHdr[0] = (flags)) typedef struct __attribute__((__packed__)) { TDB_BTREE_PAGE_COMMON_HDR @@ -274,8 +276,8 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p } // Move downward or break - u16 flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); - u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); + u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (leaf) { pCur->idx = midx; *pCRst = c; @@ -388,25 +390,23 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { static int tdbBtreeInitPage(SPage *pPage, void *arg) { SBTree *pBt; - u16 flags; + u8 flags; u8 isLeaf; u8 szAmHdr; - pBt = (SBTree *)arg; - - ASSERT(0); - - // TODO: here has problem - flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); + pBt = ((SBtreeInitPageArg *)arg)->pBt; + flags = ((SBtreeInitPageArg *)arg)->flags; isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); + + ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage)); + if (isLeaf) { szAmHdr = sizeof(SLeafHdr); } else { szAmHdr = sizeof(SIntHdr); } - pPage->xCellSize = NULL; // TODO - tdbPageInit(pPage, szAmHdr); + tdbPageInit(pPage, szAmHdr, tdbBtreeCellSize); TDB_BTREE_ASSERT_FLAG(flags); @@ -426,7 +426,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { } static int tdbBtreeZeroPage(SPage *pPage, void *arg) { - u16 flags; + u8 flags; SBTree *pBt; u8 isLeaf; u8 szAmHdr; @@ -440,10 +440,8 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { } else { szAmHdr = sizeof(SIntHdr); } - pPage->xCellSize = NULL; // TODO - tdbPageZero(pPage, szAmHdr); - // TDB_PAGE_FLAGS_SET(pPage, flags); + tdbPageZero(pPage, szAmHdr, tdbBtreeCellSize); if (isLeaf) { pPage->kLen = pBt->keyLen; @@ -749,7 +747,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) { SPage *pParent; SPage *pPage; int ret; - u16 flags; + u8 flags; u8 leaf; u8 root; @@ -757,7 +755,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) { for (;;) { iPage = pCur->iPage; pPage = pCur->pPage; - flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); root = TDB_BTREE_PAGE_IS_ROOT(flags); @@ -840,7 +838,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, i static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell) { - u16 flags; + u8 flags; u8 leaf; int nHeader; int nPayload; @@ -851,7 +849,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo nPayload = 0; nHeader = 0; - flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // 1. Encode Header part @@ -914,13 +912,13 @@ static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder } static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) { - u16 flags; + u8 flags; u8 leaf; int nHeader; int ret; nHeader = 0; - flags = 0; // TODO: TDB_PAGE_FLAGS(pPage); + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // Clear the state of decoder diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 0960d88c33..b9007b99e0 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -103,8 +103,8 @@ struct SPage { int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); -void tdbPageZero(SPage *pPage, u8 szAmHdr); -void tdbPageInit(SPage *pPage, u8 szAmHdr); +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); int tdbPageDropCell(SPage *pPage, int idx); diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 7088904285..97ed9bb703 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -79,7 +79,7 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) return 0; } -void tdbPageZero(SPage *pPage, u8 szAmHdr) { +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { pPage->pAmHdr = pPage->pData; pPage->pPageHdr = pPage->pAmHdr + szAmHdr; TDB_PAGE_NCELLS_SET(pPage, 0); @@ -91,11 +91,12 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr) { pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr)); pPage->nOverflow = 0; + pPage->xCellSize = xCellSize; ASSERT((u8 *)pPage->pPageFtr == pPage->pFreeEnd); } -void tdbPageInit(SPage *pPage, u8 szAmHdr) { +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { pPage->pAmHdr = pPage->pData; pPage->pPageHdr = pPage->pAmHdr + szAmHdr; pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); @@ -103,6 +104,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr) { pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr)); pPage->nOverflow = 0; + pPage->xCellSize = xCellSize; ASSERT(pPage->pFreeEnd >= pPage->pFreeStart); ASSERT(pPage->pFreeEnd - pPage->pFreeStart <= TDB_PAGE_NFREE(pPage)); From ad0e3a007bba08799cf7b193db4b2f97323edf27 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:45:08 +0000 Subject: [PATCH 019/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 06f96e5498..8b4bef50a5 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -392,7 +392,6 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { SBTree *pBt; u8 flags; u8 isLeaf; - u8 szAmHdr; pBt = ((SBtreeInitPageArg *)arg)->pBt; flags = ((SBtreeInitPageArg *)arg)->flags; @@ -400,13 +399,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage)); - if (isLeaf) { - szAmHdr = sizeof(SLeafHdr); - } else { - szAmHdr = sizeof(SIntHdr); - } - - tdbPageInit(pPage, szAmHdr, tdbBtreeCellSize); + tdbPageInit(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); TDB_BTREE_ASSERT_FLAG(flags); @@ -429,26 +422,26 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { u8 flags; SBTree *pBt; u8 isLeaf; - u8 szAmHdr; flags = ((SBtreeInitPageArg *)arg)->flags; pBt = ((SBtreeInitPageArg *)arg)->pBt; isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); - if (isLeaf) { - szAmHdr = sizeof(SLeafHdr); - } else { - szAmHdr = sizeof(SIntHdr); - } - - tdbPageZero(pPage, szAmHdr, tdbBtreeCellSize); + tdbPageZero(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); if (isLeaf) { + SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pPageHdr); + pLeafHdr->flags = flags; + pPage->kLen = pBt->keyLen; pPage->vLen = pBt->valLen; pPage->maxLocal = pBt->maxLeaf; pPage->minLocal = pBt->minLeaf; } else { + SIntHdr *pIntHdr = (SIntHdr *)(pPage->pPageHdr); + pIntHdr->flags = flags; + pIntHdr->pgno = 0; + pPage->kLen = pBt->keyLen; pPage->vLen = sizeof(SPgno); pPage->maxLocal = pBt->maxLocal; From 9c8102027fc921e0c9d35f50b16e4579a5df6569 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:46:37 +0000 Subject: [PATCH 020/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 8b4bef50a5..f72ce41355 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -430,7 +430,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { tdbPageZero(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); if (isLeaf) { - SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pPageHdr); + SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pAmHdr); pLeafHdr->flags = flags; pPage->kLen = pBt->keyLen; @@ -438,7 +438,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { pPage->maxLocal = pBt->maxLeaf; pPage->minLocal = pBt->minLeaf; } else { - SIntHdr *pIntHdr = (SIntHdr *)(pPage->pPageHdr); + SIntHdr *pIntHdr = (SIntHdr *)(pPage->pAmHdr); pIntHdr->flags = flags; pIntHdr->pgno = 0; From 0cd8cca66dd1aa03b16079de53514c4545ec9d31 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 06:55:17 +0000 Subject: [PATCH 021/149] more TDB --- source/libs/tdb/src/page/tdbPage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 97ed9bb703..4a067bb978 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -141,7 +141,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { u8 *src = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * lidx; u8 *dest = src + TDB_PAGE_OFFSET_SIZE(pPage); memmove(dest, src, pPage->pFreeStart - dest); - TDB_PAGE_CELL_OFFSET_AT_SET(pPage, lidx, TDB_PAGE_OFFSET_SIZE(pPage) * lidx); + TDB_PAGE_CELL_OFFSET_AT_SET(pPage, lidx, pNewCell - pPage->pData); TDB_PAGE_NCELLS_SET(pPage, nCells + 1); ASSERT(pPage->pFreeStart == pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * (nCells + 1)); From 8becb5421110425ce073ce2e8fb70176087862b3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 07:30:34 +0000 Subject: [PATCH 022/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 7 ------- source/libs/tdb/src/inc/tdbPage.h | 1 + source/libs/tdb/src/page/tdbPage.c | 10 ++++++++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index f72ce41355..4c7cddf311 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -752,13 +752,6 @@ static int tdbBtreeBalance(SBtCursor *pCur) { leaf = TDB_BTREE_PAGE_IS_LEAF(flags); root = TDB_BTREE_PAGE_IS_ROOT(flags); - // TODO: Get the page free space if not get yet - // if (pPage->nFree < 0) { - // if (tdbBtreeComputeFreeSpace(pPage) < 0) { - // return -1; - // } - // } - // when the page is not overflow and not too empty, the balance work // is finished. Just break out the balance loop. if (pPage->nOverflow == 0 /* TODO: && pPage->nFree <= */) { diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index b9007b99e0..00322067df 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -107,6 +107,7 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); int tdbPageDropCell(SPage *pPage, int idx); +void tdbPageCopy(SPage *pFromPage, SPage *pToPage); static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { SCell *pCell; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 4a067bb978..c3fec25d81 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -207,6 +207,16 @@ int tdbPageDropCell(SPage *pPage, int idx) { return 0; } +void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { + pToPage->pFreeStart = pToPage->pPageHdr + (pFromPage->pFreeStart - pFromPage->pPageHdr); + pToPage->pFreeEnd = (u8 *)(pToPage->pPageFtr) - ((u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd); + + ASSERT(pToPage->pFreeEnd >= pToPage->pFreeStart); + + memcpy(pToPage->pPageHdr, pFromPage->pPageHdr, pFromPage->pFreeStart - pFromPage->pPageHdr); + memcpy(pToPage->pFreeEnd, pFromPage->pFreeEnd, (u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd); +} + static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { SCell *pFreeCell; u8 *pOffset; From b8954ae1c5036a91293b385c80fc69501a8e5e82 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 07:55:56 +0000 Subject: [PATCH 023/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 28 +--------------------------- source/libs/tdb/src/page/tdbPage.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4c7cddf311..9e6ea91a4c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -462,29 +462,6 @@ typedef struct { SPage *pNewPages[5]; } SBtreeBalanceHelper; -static int tdbBtreeCopyPageContent(SPage *pFrom, SPage *pTo) { -#if 0 - int nCells = TDB_PAGE_TOTAL_CELLS(pFrom); - int cCells = TDB_PAGE_CCELLS(pFrom); - int fCell = TDB_PAGE_FCELL(pFrom); - int nFree = TDB_PAGE_NFREE(pFrom); - - pTo->pFreeStart = pTo->pCellIdx + nCells * pFrom->pPageMethods->szOffset; - memcpy(pTo->pCellIdx, pFrom->pCellIdx, nCells * pFrom->pPageMethods->szOffset); - pTo->pFreeEnd = (u8 *)pTo->pPageFtr - (u8 *)(pFrom->pPageFtr) + pFrom->pFreeEnd; - memcpy(pTo->pFreeEnd, pFrom->pFreeEnd, (u8 *)pFrom->pPageFtr - pFrom->pFreeEnd); - - TDB_PAGE_NCELLS_SET(pTo, nCells); - TDB_PAGE_CCELLS_SET(pTo, cCells); - TDB_PAGE_FCELL_SET(pTo, fCell); - TDB_PAGE_NFREE_SET(pTo, nFree); - - // TODO: update other fields -#endif - - return 0; -} - static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { SPager *pPager; SPage *pChild; @@ -503,10 +480,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { } // Copy the root page content to the child page - ret = tdbBtreeCopyPageContent(pRoot, pChild); - if (ret < 0) { - return -1; - } + tdbPageCopy(pRoot, pChild); pChild->nOverflow = pRoot->nOverflow; for (int i = 0; i < pChild->nOverflow; i++) { diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index c3fec25d81..803bf168cf 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -208,6 +208,8 @@ int tdbPageDropCell(SPage *pPage, int idx) { } void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { + int delta, nFree; + pToPage->pFreeStart = pToPage->pPageHdr + (pFromPage->pFreeStart - pFromPage->pPageHdr); pToPage->pFreeEnd = (u8 *)(pToPage->pPageFtr) - ((u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd); @@ -215,6 +217,16 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { memcpy(pToPage->pPageHdr, pFromPage->pPageHdr, pFromPage->pFreeStart - pFromPage->pPageHdr); memcpy(pToPage->pFreeEnd, pFromPage->pFreeEnd, (u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd); + + ASSERT(TDB_PAGE_CCELLS(pToPage) == pToPage->pFreeEnd - pToPage->pData); + + delta = (pToPage->pPageHdr - pToPage->pAmHdr) - (pFromPage->pPageHdr - pFromPage->pAmHdr); + if (delta != 0) { + nFree = TDB_PAGE_NFREE(pFromPage); + TDB_PAGE_NFREE_SET(pToPage, nFree - delta); + } + + // TODO: do we need to copy the overflow part ??? } static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { From 2e6f7f15d5934ab67f6ee2cb1f2e7bb435bccb9e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 07:59:37 +0000 Subject: [PATCH 024/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 6 ------ source/libs/tdb/src/page/tdbPage.c | 7 ++++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 9e6ea91a4c..5f56b2f1e7 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -482,12 +482,6 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { // Copy the root page content to the child page tdbPageCopy(pRoot, pChild); - pChild->nOverflow = pRoot->nOverflow; - for (int i = 0; i < pChild->nOverflow; i++) { - pChild->apOvfl[i] = pRoot->apOvfl[i]; - pChild->aiOvfl[i] = pRoot->aiOvfl[i]; - } - // Reinitialize the root page zArg.flags = TDB_BTREE_ROOT; zArg.pBt = pBt; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 803bf168cf..2f6d4101a5 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -226,7 +226,12 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { TDB_PAGE_NFREE_SET(pToPage, nFree - delta); } - // TODO: do we need to copy the overflow part ??? + // Copy the overflow cells + for (int iOvfl = 0; iOvfl < pFromPage->nOverflow; iOvfl++) { + pToPage->aiOvfl[iOvfl] = pFromPage->aiOvfl[iOvfl]; + pToPage->apOvfl[iOvfl] = pFromPage->apOvfl[iOvfl]; + } + pToPage->nOverflow = pFromPage->nOverflow; } static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { From 5ca3e29cf19ed454ec9a0a4e7c00c3d474d01c99 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 08:17:58 +0000 Subject: [PATCH 025/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 6 ++++-- source/libs/tdb/src/page/tdbPage.c | 1 - source/libs/tdb/src/page/tdbPageL.c | 9 ++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 5f56b2f1e7..4e4b2275f8 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -467,6 +467,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { SPage *pChild; SPgno pgnoChild; int ret; + SIntHdr *pIntHdr; SBtreeInitPageArg zArg; pPager = pRoot->pPager; @@ -490,7 +491,8 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { return -1; } - // TODO: ((SBtPageHdr *)pRoot->pAmHdr)[0].rChild = pgnoChild; + pIntHdr = (SIntHdr *)(pRoot->pAmHdr); + pIntHdr->pgno = pgnoChild; *ppChild = pChild; return 0; @@ -731,7 +733,7 @@ static int tdbBtreeBalance(SBtCursor *pCur) { // ignore the case of empty if (pPage->nOverflow == 0) break; - ret = tdbBtreeBalanceDeeper(pCur->pBt, pCur->pPage, &(pCur->pgStack[1])); + ret = tdbBtreeBalanceDeeper(pCur->pBt, pPage, &(pCur->pgStack[1])); if (ret < 0) { return -1; } diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 2f6d4101a5..bc00da9381 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -416,7 +416,6 @@ static int tdbPageDefragment(SPage *pPage) { /* ---------------------------------------------------------------------------------------------------------- */ typedef struct __attribute__((__packed__)) { - u16 flags; u16 cellNum; u16 cellBody; u16 cellFree; diff --git a/source/libs/tdb/src/page/tdbPageL.c b/source/libs/tdb/src/page/tdbPageL.c index cfd8c919df..c5d4a6047f 100644 --- a/source/libs/tdb/src/page/tdbPageL.c +++ b/source/libs/tdb/src/page/tdbPageL.c @@ -16,11 +16,10 @@ #include "tdbInt.h" typedef struct __attribute__((__packed__)) { - u16 flags; - u8 cellNum[3]; - u8 cellBody[3]; - u8 cellFree[3]; - u8 nFree[3]; + u8 cellNum[3]; + u8 cellBody[3]; + u8 cellFree[3]; + u8 nFree[3]; } SPageHdrL; typedef struct __attribute__((__packed__)) { From db870af8b7afb105417d4d3d7e6acaaf1bc90235 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 09:33:10 +0000 Subject: [PATCH 026/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 65 +++++++++++++++++++++++++----- source/libs/tdb/src/inc/tdbPage.h | 3 +- source/libs/tdb/src/page/tdbPage.c | 10 ++--- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4e4b2275f8..b801002822 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -41,8 +41,8 @@ struct SBTree { #define TDB_BTREE_PAGE_COMMON_HDR u8 flags; -#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pAmHdr[0] -#define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pAmHdr[0] = (flags)) +#define TDB_BTREE_PAGE_GET_FLAGS(PAGE) (PAGE)->pData[0] +#define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pData[0] = (flags)) typedef struct __attribute__((__packed__)) { TDB_BTREE_PAGE_COMMON_HDR @@ -393,8 +393,8 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) { u8 flags; u8 isLeaf; - pBt = ((SBtreeInitPageArg *)arg)->pBt; - flags = ((SBtreeInitPageArg *)arg)->flags; + pBt = (SBTree *)arg; + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); ASSERT(flags == TDB_BTREE_PAGE_GET_FLAGS(pPage)); @@ -430,7 +430,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { tdbPageZero(pPage, isLeaf ? sizeof(SLeafHdr) : sizeof(SIntHdr), tdbBtreeCellSize); if (isLeaf) { - SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pAmHdr); + SLeafHdr *pLeafHdr = (SLeafHdr *)(pPage->pData); pLeafHdr->flags = flags; pPage->kLen = pBt->keyLen; @@ -438,7 +438,7 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) { pPage->maxLocal = pBt->maxLeaf; pPage->minLocal = pBt->minLeaf; } else { - SIntHdr *pIntHdr = (SIntHdr *)(pPage->pAmHdr); + SIntHdr *pIntHdr = (SIntHdr *)(pPage->pData); pIntHdr->flags = flags; pIntHdr->pgno = 0; @@ -491,7 +491,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { return -1; } - pIntHdr = (SIntHdr *)(pRoot->pAmHdr); + pIntHdr = (SIntHdr *)(pRoot->pData); pIntHdr->pgno = pgnoChild; *ppChild = pChild; @@ -643,15 +643,59 @@ static int tdbBtreeBalanceStep6(SBtreeBalanceHelper *pBlh) { } static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { - int ret; + int ret; +#if 0 SBtreeBalanceHelper blh; - // ASSERT(!TDB_BTREE_PGE_IS_LEAF(TDB_PAGE_FLAGS(pParent))); - blh.pBt = pBt; blh.pParent = pParent; blh.idx = idx; +#endif + int nOlds; + SPage *pOlds[3]; + + { + // Find 3 child pages at most to do balance + int nCells = TDB_PAGE_TOTAL_CELLS(pParent); + int sIdx; + if (nCells <= 2) { + sIdx = 0; + nOlds = nCells + 1; + } else { + // has more than three child pages + if (idx == 0) { + sIdx = 0; + } else if (idx == nCells) { + sIdx = idx - 2; + } else { + sIdx = idx - 1; + } + nOlds = 3; + } + for (int i = 0; i < nOlds; i++, sIdx++) { + ASSERT(sIdx <= nCells); + + SPgno pgno; + if (sIdx == nCells) { + ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); + pgno = ((SIntHdr *)(pParent->pData))->pgno; + } else { + SCell *pCell; + + pCell = tdbPageGetCell(pParent, sIdx); + pgno = *(SPgno *)pCell; + } + + ret = tdbPagerFetchPage(pBt->pPager, pgno, pOlds + i, tdbBtreeInitPage, pBt); + if (ret < 0) { + ASSERT(0); + return -1; + } + } + } + +#if 0 // Step 1: find two sibling pages and get engough info about the old pages ret = tdbBtreeBalanceStep1(&blh); if (ret < 0) { @@ -693,6 +737,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ASSERT(0); return -1; } +#endif { // TODO: Reset states diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 00322067df..e513a63fe4 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -58,7 +58,6 @@ struct SPage { u8 *pData; SPageMethods *pPageMethods; // Fields below used by pager and am - u8 *pAmHdr; u8 *pPageHdr; u8 *pCellIdx; u8 *pFreeStart; @@ -114,7 +113,7 @@ static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { int iOvfl; int lidx; - ASSERT(idx >= 0 && idx < pPage->nOverflow + pPage->pPageMethods->getCellNum(pPage)); + ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage)); iOvfl = 0; for (; iOvfl < pPage->nOverflow; iOvfl++) { diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index bc00da9381..0dc7853940 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -80,8 +80,7 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) } void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { - pPage->pAmHdr = pPage->pData; - pPage->pPageHdr = pPage->pAmHdr + szAmHdr; + pPage->pPageHdr = pPage->pData + szAmHdr; TDB_PAGE_NCELLS_SET(pPage, 0); TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr)); TDB_PAGE_FCELL_SET(pPage, 0); @@ -97,8 +96,7 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell } void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { - pPage->pAmHdr = pPage->pData; - pPage->pPageHdr = pPage->pAmHdr + szAmHdr; + pPage->pPageHdr = pPage->pData + szAmHdr; pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage); pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage); @@ -117,7 +115,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { int lidx; // local idx SCell *pNewCell; - ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage, pPage->pPageHdr - pPage->pAmHdr)); + ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage, pPage->pPageHdr - pPage->pData)); nFree = TDB_PAGE_NFREE(pPage); nCells = TDB_PAGE_NCELLS(pPage); @@ -220,7 +218,7 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { ASSERT(TDB_PAGE_CCELLS(pToPage) == pToPage->pFreeEnd - pToPage->pData); - delta = (pToPage->pPageHdr - pToPage->pAmHdr) - (pFromPage->pPageHdr - pFromPage->pAmHdr); + delta = (pToPage->pPageHdr - pToPage->pData) - (pFromPage->pPageHdr - pFromPage->pData); if (delta != 0) { nFree = TDB_PAGE_NFREE(pFromPage); TDB_PAGE_NFREE_SET(pToPage, nFree - delta); From b3b5298510d28f1a75ec917dcf8cec1978538697 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 09:47:46 +0000 Subject: [PATCH 027/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index b801002822..52ea45578b 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -695,6 +695,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + // >>>>>>>>>>>>>>>>>>> + #if 0 // Step 1: find two sibling pages and get engough info about the old pages ret = tdbBtreeBalanceStep1(&blh); @@ -854,6 +856,14 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // 1. Encode Header part + /* Encode SPgno if interior page */ + if (!leaf) { + ASSERT(pPage->vLen == sizeof(SPgno)); + + ((SPgno *)(pCell + nHeader))[0] = ((SPgno *)pVal)[0]; + nHeader = nHeader + sizeof(SPgno); + } + /* Encode kLen if need */ if (pPage->kLen == TDB_VARIANT_LEN) { nHeader += tdbPutVarInt(pCell + nHeader, kLen); @@ -864,14 +874,6 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo nHeader += tdbPutVarInt(pCell + nHeader, vLen); } - /* Encode SPgno if interior page */ - if (!leaf) { - ASSERT(pPage->vLen == sizeof(SPgno)); - - ((SPgno *)(pCell + nHeader))[0] = ((SPgno *)pVal)[0]; - nHeader = nHeader + sizeof(SPgno); - } - // 2. Encode payload part if (leaf) { ret = tdbBtreeEncodePayload(pPage, pCell + nHeader, pKey, kLen, pVal, vLen, &nPayload); @@ -930,6 +932,14 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD pDecoder->pgno = 0; // 1. Decode header part + if (!leaf) { + ASSERT(pPage->vLen == sizeof(SPgno)); + + pDecoder->pgno = ((SPgno *)(pCell + nHeader))[0]; + pDecoder->pVal = (u8 *)(&(pDecoder->pgno)); + nHeader = nHeader + sizeof(SPgno); + } + if (pPage->kLen == TDB_VARIANT_LEN) { nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->kLen)); } else { @@ -942,14 +952,6 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD pDecoder->vLen = pPage->vLen; } - if (!leaf) { - ASSERT(pPage->vLen == sizeof(SPgno)); - - pDecoder->pgno = ((SPgno *)(pCell + nHeader))[0]; - pDecoder->pVal = (u8 *)(&(pDecoder->pgno)); - nHeader = nHeader + sizeof(SPgno); - } - // 2. Decode payload part ret = tdbBtreeDecodePayload(pPage, pCell + nHeader, pDecoder); if (ret < 0) { From 1075c230ed0615f80449000afe09feafd9a63723 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 10:18:04 +0000 Subject: [PATCH 028/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 37 ++++++++++++++++++++++--------- source/libs/tdb/src/inc/tdbPage.h | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 52ea45578b..93fc75269c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -644,19 +644,11 @@ static int tdbBtreeBalanceStep6(SBtreeBalanceHelper *pBlh) { static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int ret; -#if 0 - SBtreeBalanceHelper blh; - - blh.pBt = pBt; - blh.pParent = pParent; - blh.idx = idx; -#endif int nOlds; SPage *pOlds[3]; - { - // Find 3 child pages at most to do balance + { // Find 3 child pages at most to do balance int nCells = TDB_PAGE_TOTAL_CELLS(pParent); int sIdx; if (nCells <= 2) { @@ -695,7 +687,32 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - // >>>>>>>>>>>>>>>>>>> + int nNews = 0; + int cntNews[5] = {0}; // TODO: maybe 5 is not enough + int szNews[5] = {0}; + int maxPageCapacity; // TODO + + { // Get how many new pages are needed and the new distribution + + // loop to find number of pages needed + for (int i = 0; i < nOlds; i++) { + SPage *pPage = pOlds[i]; + SCell *pCell; + int cellBytes; + for (int cIdx = 0; cIdx < TDB_PAGE_TOTAL_CELLS(pPage); cIdx++) { + pCell = tdbPageGetCell(pPage, cIdx); + cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); + + if (szNews[nNews] + cellBytes > maxPageCapacity) { + nNews++; + } + cntNews[nNews]++; + szNews[nNews] = szNews[nNews] + cellBytes; + } + } + + // Loop to make the distribution even + } #if 0 // Step 1: find two sibling pages and get engough info about the old pages diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index e513a63fe4..479c7603e1 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -98,7 +98,8 @@ struct SPage { }) // APIs -#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) +#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) +#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); From b5b522d66643663ceeabbf5b8a8548153431073a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 10:23:34 +0000 Subject: [PATCH 029/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 4 ++-- source/libs/tdb/src/inc/tdbPage.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 93fc75269c..aa3e4c6b90 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -690,7 +690,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nNews = 0; int cntNews[5] = {0}; // TODO: maybe 5 is not enough int szNews[5] = {0}; - int maxPageCapacity; // TODO { // Get how many new pages are needed and the new distribution @@ -699,11 +698,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SPage *pPage = pOlds[i]; SCell *pCell; int cellBytes; + for (int cIdx = 0; cIdx < TDB_PAGE_TOTAL_CELLS(pPage); cIdx++) { pCell = tdbPageGetCell(pPage, cIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - if (szNews[nNews] + cellBytes > maxPageCapacity) { + if (szNews[nNews] + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { nNews++; } cntNews[nNews]++; diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 479c7603e1..258eafcf63 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -99,6 +99,7 @@ struct SPage { // APIs #define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) +#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) #define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); From bd8c171be1d79dfefd53288739110cb0536ef2a5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 10:44:18 +0000 Subject: [PATCH 030/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 39 ++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index aa3e4c6b90..4169509280 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -978,10 +978,37 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD return 0; } -#endif - static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { - // TODO - ASSERT(0); - return 0; -} \ No newline at end of file + u8 flags; + u8 isLeaf; + int szCell; + int kLen = 0, vLen = 0; + + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); + isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); + szCell = 0; + + if (!isLeaf) { + szCell += sizeof(SPgno); + } + + if (pPage->kLen == TDB_VARIANT_LEN) { + szCell += tdbGetVarInt(pCell + szCell, &kLen); + } else { + kLen = pPage->kLen; + } + + if (isLeaf) { + if (pPage->vLen == TDB_VARIANT_LEN) { + szCell += tdbGetVarInt(pCell + szCell, &vLen); + } else { + vLen = pPage->vLen; + } + } + + szCell = szCell + kLen + vLen; + + return szCell; +} + +#endif From d123388a1962630ead69fa7d13e4b92c5f7f4be5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 10:53:49 +0000 Subject: [PATCH 031/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4169509280..670cdc002a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -711,7 +711,16 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - // Loop to make the distribution even + nNews = nNews + 1; + + // back loop to make the distribution even + for (int iNew = nNews - 1; iNew > 0; iNew--) { + /* code */ + } + } + + SPage *pNews[5]; + { // Allocate the new pages } #if 0 From 925004770202e76b8de27e4a8f4cfbf48c9d67dc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 21 Mar 2022 14:56:07 +0000 Subject: [PATCH 032/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 670cdc002a..98a5cf158c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -715,7 +715,34 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // back loop to make the distribution even for (int iNew = nNews - 1; iNew > 0; iNew--) { - /* code */ + // TODO: find the last cell of page (iNew-1) + int cIdx; + int iPage; + int cellBytes; + SPage *pPage; + SCell *pCell; + + for (;;) { + pCell = tdbPageGetCell(pPage, cIdx); + cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); + + if (szNews[iNew] + cellBytes >= szNews[iNew - 1] + cellBytes) { + break; + } + + // Move the cell right + szNews[iNew] += cellBytes; + cntNews[iNew]++; + + szNews[iNew - 1] -= cellBytes; + cntNews[iNew - 1]++; + + cIdx--; + if (cIdx < 0) { + pPage = pOlds[--iPage]; + cIdx = TDB_PAGE_TOTAL_CELLS(pPage) - 1; + } + } } } From e2f1434bf2c9d2b5cbe13408f4fbbf876a0ec417 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 02:08:56 +0000 Subject: [PATCH 033/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 108 ++++++++++-------------------- 1 file changed, 34 insertions(+), 74 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 98a5cf158c..cbb389140f 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -688,26 +688,33 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } int nNews = 0; - int cntNews[5] = {0}; // TODO: maybe 5 is not enough - int szNews[5] = {0}; + struct { + int cnt; + int size; + int oPage; + int oIdx; + } infoNews[5] = {0}; { // Get how many new pages are needed and the new distribution - // loop to find number of pages needed - for (int i = 0; i < nOlds; i++) { - SPage *pPage = pOlds[i]; + // first loop to find minimum number of pages needed + for (int oPage = 0; oPage < nOlds; oPage++) { + SPage *pPage = pOlds[oPage]; SCell *pCell; int cellBytes; - for (int cIdx = 0; cIdx < TDB_PAGE_TOTAL_CELLS(pPage); cIdx++) { - pCell = tdbPageGetCell(pPage, cIdx); + for (int oIdx = 0; oIdx < TDB_PAGE_TOTAL_CELLS(pPage); oIdx++) { + pCell = tdbPageGetCell(pPage, oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - if (szNews[nNews] + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { + if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { + // page is full, use a new page nNews++; } - cntNews[nNews]++; - szNews[nNews] = szNews[nNews] + cellBytes; + infoNews[nNews].cnt++; + infoNews[nNews].size += cellBytes; + infoNews[nNews].oPage = oPage; + infoNews[nNews].oIdx = oIdx; } } @@ -715,85 +722,38 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // back loop to make the distribution even for (int iNew = nNews - 1; iNew > 0; iNew--) { - // TODO: find the last cell of page (iNew-1) - int cIdx; - int iPage; - int cellBytes; - SPage *pPage; SCell *pCell; + SPage *pPage; + int cellBytes; for (;;) { - pCell = tdbPageGetCell(pPage, cIdx); + pPage = pOlds[infoNews[iNew - 1].oPage]; + pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - if (szNews[iNew] + cellBytes >= szNews[iNew - 1] + cellBytes) { - break; + infoNews[iNew].cnt++; + infoNews[iNew].size += cellBytes; + infoNews[iNew - 1].cnt--; + infoNews[iNew - 1].size -= cellBytes; + if ((infoNews[iNew - 1].oIdx--) == 0) { + infoNews[iNew - 1].oPage--; + infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pOlds[infoNews[iNew - 1].oPage]); } - // Move the cell right - szNews[iNew] += cellBytes; - cntNews[iNew]++; - - szNews[iNew - 1] -= cellBytes; - cntNews[iNew - 1]++; - - cIdx--; - if (cIdx < 0) { - pPage = pOlds[--iPage]; - cIdx = TDB_PAGE_TOTAL_CELLS(pPage) - 1; + if (infoNews[iNew].size > infoNews[iNew - 1].size) { + break; } } } + + int k = 0; } SPage *pNews[5]; - { // Allocate the new pages + { + // Allocate the new pages } -#if 0 - // Step 1: find two sibling pages and get engough info about the old pages - ret = tdbBtreeBalanceStep1(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Step 2: Load all cells on the old page and the divider cells - ret = tdbBtreeBalanceStep2(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Step 3: Get the number of pages needed to hold all cells - ret = tdbBtreeBalanceStep3(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Step 4: Allocate enough new pages. Reuse old pages as much as possible - ret = tdbBtreeBalanceStep4(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Step 5: Insert new divider cells into pParent - ret = tdbBtreeBalanceStep5(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Step 6: Update the sibling pages - ret = tdbBtreeBalanceStep6(&blh); - if (ret < 0) { - ASSERT(0); - return -1; - } -#endif - { // TODO: Reset states } From d5afc7240a92968e07027c464d1db6caee590084 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 02:39:12 +0000 Subject: [PATCH 034/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index cbb389140f..e969f15775 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -745,13 +745,29 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } - - int k = 0; } - SPage *pNews[5]; - { - // Allocate the new pages + SPage *pNews[5] = {0}; + { // Allocate new pages, reuse the old page when possible + + SPgno pgno; + SBtreeInitPageArg iarg; + u8 flags; + + flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]); + + for (int iNew = 0; iNew < nNews; iNew++) { + if (iNew < nOlds) { + pNews[iNew] = pOlds[iNew]; + } else { + iarg.pBt = pBt; + iarg.flags = flags; + ret = tdbPagerNewPage(pBt->pPager, &pgno, pNews + iNew, tdbBtreeZeroPage, &iarg); + if (ret < 0) { + ASSERT(0); + } + } + } } { From 6cd9d2703428e5647fdd64a0c40c94d3cd68724f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 02:45:59 +0000 Subject: [PATCH 035/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 150 +----------------------------- 1 file changed, 1 insertion(+), 149 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index e969f15775..af0f331373 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -498,150 +498,6 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { return 0; } -static int tdbBtreeBalanceStep1(SBtreeBalanceHelper *pBlh) { - int nCells; - int i; - int idxStart; - int nChild; - int ret; - SPage *pParent; - SPgno pgno; - SCell *pCell; - SCellDecoder cd; - SBTree *pBt; - - pParent = pBlh->pParent; - nCells = TDB_PAGE_TOTAL_CELLS(pParent); - nChild = nCells + 1; - pBt = pBlh->pBt; - - // TODO: ASSERT below needs to be removed - ASSERT(pParent->nOverflow == 0); - ASSERT(pBlh->idx <= nCells); - - if (nChild < 3) { - idxStart = 0; - pBlh->nOld = nChild; - } else { - if (pBlh->idx == 0) { - idxStart = 0; - } else if (pBlh->idx == nCells) { - idxStart = pBlh->idx - 2; - } else { - idxStart = pBlh->idx - 1; - } - pBlh->nOld = 3; - } - - i = pBlh->nOld - 1; - - if (idxStart + i == nCells) { - // pgno = ((SBtPageHdr *)(pParent->pAmHdr))[0].rChild; - } else { - pCell = tdbPageGetCell(pParent, idxStart + i); - // TODO: no need to decode the payload part, and even the kLen, vLen part - // we only need the pgno part - ret = tdbBtreeDecodeCell(pParent, pCell, &cd); - if (ret < 0) { - ASSERT(0); - return -1; - } - pgno = cd.pgno; - } - for (;;) { - ret = tdbPagerFetchPage(pBt->pPager, pgno, &(pBlh->pOldPages[i]), tdbBtreeInitPage, pBt); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // Loop over - if ((i--) == 0) break; - - { - // TODO - // ASSERT(0); - } - } - - return 0; -} - -static int tdbBtreeBalanceStep2(SBtreeBalanceHelper *pBlh) { -#if 0 - SPage *pPage; - int oidx; - int cidx; - int limit; - SCell *pCell; - - for (int i = 0; i < pBlh->nOld; i++) { - pPage = pBlh->pOldPages[i]; - oidx = 0; - cidx = 0; - - if (oidx < pPage->nOverflow) { - limit = pPage->aiOvfl[oidx]; - } else { - limit = pPage->pPageHdr->nCells; - } - - // Loop to copy each cell pointer out - for (;;) { - if (oidx >= pPage->nOverflow && cidx >= pPage->pPageHdr->nCells) break; - - if (cidx < limit) { - // Get local cells - pCell = tdbPageGetCell(pPage, cidx); - } else if (cidx == limit) { - // Get overflow cells - pCell = pPage->apOvfl[oidx++]; - - if (oidx < pPage->nOverflow) { - limit = pPage->aiOvfl[oidx]; - } else { - limit = pPage->pPageHdr->nCells; - } - } else { - ASSERT(0); - } - } - - { - // TODO: Copy divider cells here - } - } - - /* TODO */ - -#endif - return 0; -} - -static int tdbBtreeBalanceStep3(SBtreeBalanceHelper *pBlh) { - // Figure out number of pages needed after balance - for (int i = 0; i < pBlh->nOld; i++) { - /* TODO */ - } - - return 0; -} - -static int tdbBtreeBalanceStep4(SBtreeBalanceHelper *pBlh) { - // TODO - return 0; -} - -static int tdbBtreeBalanceStep5(SBtreeBalanceHelper *pBlh) { - // TODO - return 0; -} - -static int tdbBtreeBalanceStep6(SBtreeBalanceHelper *pBlh) { - // TODO - return 0; -} - static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int ret; @@ -771,11 +627,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } { - // TODO: Reset states - } - - { - // TODO: Clear resources + // Do the actual redistribute } return 0; From f3c10f886c589766bda0ade1f4c9a88b24ef3fd4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 02:48:32 +0000 Subject: [PATCH 036/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index af0f331373..71a9e70064 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -310,32 +310,6 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p return 0; } -static int tdbBtCursorMoveToRoot(SBtCursor *pCur) { - SBTree *pBt; - SPager *pPager; - SPage *pPage; - int ret; - - pBt = pCur->pBt; - pPager = pBt->pPager; - - // pPage = tdbPagerGet(pPager, pBt->root, true); - // if (pPage == NULL) { - // // TODO: handle error - // } - - // ret = tdbInitBtPage(pPage, &pBtPage); - // if (ret < 0) { - // // TODO - // return 0; - // } - - // pCur->pPage = pBtPage; - // pCur->iPage = 0; - - return 0; -} - static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) { int mlen; int cret; From df12ae0d79e73725e54cf4c7ca44743dd21eda71 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 05:28:54 +0000 Subject: [PATCH 037/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 50 ++++++++++++++++++++++++++++-- source/libs/tdb/src/db/tdbPCache.c | 14 +-------- source/libs/tdb/src/inc/tdbUtil.h | 10 ++++++ source/libs/tdb/src/page/tdbPage.c | 7 +++++ 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 71a9e70064..196c4593c5 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -598,10 +598,56 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } + + // TODO: sort the page according to the page number } - { - // Do the actual redistribute + { // Do the actual cell distribution + + SPage *pTPage[2]; + int tPage, tIdx, iOld; + SCell *pCell; + int szCell; + SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt}; + + for (int i = 0; i < 2; i++) { + ret = tdbPageCreate(pOlds[0]->pageSize, &pTPage[i], NULL, NULL); + if (ret < 0) { + ASSERT(0); + } + } + + tPage = 0; + tIdx = 0; + iOld = 0; + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld++], pTPage[tPage]); + + for (int iNew = 0; iNew < nNews; iNew++) { + // fill the iNew page + tdbBtreeZeroPage(pNews[iNew], &iarg); + + for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) { + while (tIdx >= TDB_PAGE_TOTAL_CELLS(pTPage[tPage])) { + tPage = (tPage + 1) % 2; + tIdx = 0; + + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld++], pTPage[tPage]); + } + + pCell = tdbPageGetCell(pTPage[tPage], tIdx); + szCell = tdbBtreeCellSize(pTPage[tPage], pCell); + + tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell); + + tIdx++; + } + } + + for (int i = 0; i < 2; i++) { + tdbPageDestroy(pTPage[i], NULL, NULL); + } } return 0; diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 29f7395cbc..1fc0847b38 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -57,8 +57,6 @@ static void tdbPCachePinPage(SPage *pPage); static void tdbPCacheRemovePageFromHash(SPage *pPage); static void tdbPCacheAddPageToHash(SPage *pPage); static void tdbPCacheUnpinPage(SPage *pPage); -static void *tdbOsMalloc(void *arg, size_t size); -static void tdbOsFree(void *arg, void *ptr); int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { SPCache *pCache; @@ -257,7 +255,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { pCache->nFree = 0; pCache->pFree = NULL; for (int i = 0; i < pCache->cacheSize; i++) { - ret = tdbPageCreate(pCache->pageSize, &pPage, tdbOsMalloc, NULL); + ret = tdbPageCreate(pCache->pageSize, &pPage, NULL, NULL); if (ret < 0) { // TODO: handle error return -1; @@ -297,13 +295,3 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { } int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; } - -static void *tdbOsMalloc(void *arg, size_t size) { - void *ptr; - - ptr = malloc(size); - - return ptr; -} - -static void tdbOsFree(void *arg, void *ptr) { free(ptr); } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 9576ee6d15..9358aae236 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -39,6 +39,16 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); int tdbPRead(int fd, void *pData, int count, i64 offset); +static inline void *tdbOsMalloc(void *arg, size_t size) { + void *ptr; + + ptr = malloc(size); + + return ptr; +} + +static inline void tdbOsFree(void *arg, void *ptr) { free(ptr); } + static inline int tdbPutVarInt(u8 *p, int v) { int n = 0; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 0dc7853940..16130ba13f 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -48,6 +48,9 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) *ppPage = NULL; size = pageSize + sizeof(*pPage); + if (xMalloc == NULL) { + xMalloc = tdbOsMalloc; + } ptr = (u8 *)((*xMalloc)(arg, size)); if (pPage == NULL) { @@ -73,6 +76,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) { u8 *ptr; + if (!xFree) { + xFree = tdbOsFree; + } + ptr = pPage->pData; (*xFree)(arg, ptr); From 3abd4b2e672f5af1e1de3652427dbe840b71d9ce Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 06:08:28 +0000 Subject: [PATCH 038/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 16 +++++++++++++++- source/libs/tdb/src/inc/tdbPage.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 196c4593c5..a05202f456 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -602,7 +602,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // TODO: sort the page according to the page number } - { // Do the actual cell distribution + { // Do the real cell distribution SPage *pTPage[2]; int tPage, tIdx, iOld; @@ -650,6 +650,20 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + { // Insert records in parent page + int cIdx; + int szCell; + SCell pCell[128]; // TODO + SCellDecoder cd; + + for (int iNew = 0; iNew < nNews; iNew++) { + tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); + + tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); + tdbPageInsertCell(pParent, cIdx, pCell, szCell); + } + } + return 0; } diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 258eafcf63..61927fabf6 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -100,6 +100,7 @@ struct SPage { // APIs #define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) #define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) +#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) #define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); From 0b752392aa482ab45cd38d6d78a4112c84782042 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 06:24:16 +0000 Subject: [PATCH 039/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a05202f456..da11eb099a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -495,17 +495,17 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } nOlds = 3; } - for (int i = 0; i < nOlds; i++, sIdx++) { - ASSERT(sIdx <= nCells); + for (int i = 0; i < nOlds; i++) { + ASSERT(sIdx + i <= nCells); SPgno pgno; - if (sIdx == nCells) { + if (sIdx + i == nCells) { ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); pgno = ((SIntHdr *)(pParent->pData))->pgno; } else { SCell *pCell; - pCell = tdbPageGetCell(pParent, sIdx); + pCell = tdbPageGetCell(pParent, sIdx + i); pgno = *(SPgno *)pCell; } @@ -515,6 +515,15 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return -1; } } + // drop the cells + for (int i = 0; i < nOlds; i++) { + nCells = TDB_PAGE_TOTAL_CELLS(pParent); + if (sIdx < nCells) { + tdbPageDropCell(pParent, sIdx); + } else { + ((SIntHdr *)pParent->pData)->pgno = 0; + } + } } int nNews = 0; @@ -657,6 +666,16 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SCellDecoder cd; for (int iNew = 0; iNew < nNews; iNew++) { + if (iNew == nNews - 1) { + // The last new page + + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + if (pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + break; + } + } + tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); @@ -664,6 +683,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + int k = 0; + return 0; } From 2d1e356cc214aa99aed731b17352635f95728f41 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 06:56:29 +0000 Subject: [PATCH 040/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index da11eb099a..e7abbc7161 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -477,10 +477,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nOlds; SPage *pOlds[3]; + int sIdx; { // Find 3 child pages at most to do balance int nCells = TDB_PAGE_TOTAL_CELLS(pParent); - int sIdx; if (nCells <= 2) { sIdx = 0; nOlds = nCells + 1; @@ -515,7 +515,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return -1; } } - // drop the cells + // drop the cells on parent page for (int i = 0; i < nOlds; i++) { nCells = TDB_PAGE_TOTAL_CELLS(pParent); if (sIdx < nCells) { @@ -660,7 +660,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } { // Insert records in parent page - int cIdx; + int cIdx = sIdx; int szCell; SCell pCell[128]; // TODO SCellDecoder cd; @@ -679,12 +679,11 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); + // TODO: the cell here may be used by pParent as an overflow cell tdbPageInsertCell(pParent, cIdx, pCell, szCell); } } - int k = 0; - return 0; } From 238550b0f4d0ceeb987ad41eb7992afba994dacd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 07:50:34 +0000 Subject: [PATCH 041/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 36 ++++++++++++++++++++++++++---- source/libs/tdb/src/inc/tdbPage.h | 1 + source/libs/tdb/src/page/tdbPage.c | 1 - 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index e7abbc7161..d1188ee5b3 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -477,10 +477,15 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nOlds; SPage *pOlds[3]; + SCell *pDivCell[2] = {0}; + int szDivCell[2]; int sIdx; + u8 childLeaf; { // Find 3 child pages at most to do balance - int nCells = TDB_PAGE_TOTAL_CELLS(pParent); + int nCells = TDB_PAGE_TOTAL_CELLS(pParent); + SCell *pCell; + if (nCells <= 2) { sIdx = 0; nOlds = nCells + 1; @@ -503,8 +508,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ASSERT(!TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pParent))); pgno = ((SIntHdr *)(pParent->pData))->pgno; } else { - SCell *pCell; - pCell = tdbPageGetCell(pParent, sIdx + i); pgno = *(SPgno *)pCell; } @@ -515,6 +518,17 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return -1; } } + // copy the parent key out if child pages are not leaf page + childLeaf = TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); + if (childLeaf) { + for (int i = 0; i < nOlds - 1; i++) { + pCell = tdbPageGetCell(pParent, sIdx + i); + + szDivCell[i] = tdbBtreeCellSize(pParent, pCell); + pDivCell[i] = malloc(szDivCell[i]); + memcpy(pDivCell, pCell, szDivCell[i]); + } + } // drop the cells on parent page for (int i = 0; i < nOlds; i++) { nCells = TDB_PAGE_TOTAL_CELLS(pParent); @@ -541,14 +555,28 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SPage *pPage = pOlds[oPage]; SCell *pCell; int cellBytes; + int oIdx; - for (int oIdx = 0; oIdx < TDB_PAGE_TOTAL_CELLS(pPage); oIdx++) { + for (oIdx = 0; oIdx < TDB_PAGE_TOTAL_CELLS(pPage); oIdx++) { pCell = tdbPageGetCell(pPage, oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { // page is full, use a new page nNews++; + // for a child leaf case, this cell is used as the new divider cell + if (childLeaf) continue; + } + infoNews[nNews].cnt++; + infoNews[nNews].size += cellBytes; + infoNews[nNews].oPage = oPage; + infoNews[nNews].oIdx = oIdx; + } + + // For child leaf pages + if (childLeaf && oPage < nOlds - 1) { + if (infoNews[nNews].size + szDivCell[oPage] + TDB_PAGE_OFFSET_SIZE(pPage) > TDB_PAGE_USABLE_SIZE(pPage)) { + nNews++; } infoNews[nNews].cnt++; infoNews[nNews].size += cellBytes; diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 61927fabf6..0ba7cf236b 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -102,6 +102,7 @@ struct SPage { #define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) #define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) #define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) +#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 16130ba13f..14960de45d 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -18,7 +18,6 @@ extern SPageMethods pageMethods; extern SPageMethods pageLargeMethods; -#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) #define TDB_PAGE_HDR_SIZE(pPage) ((pPage)->pPageMethods->szPageHdr) #define TDB_PAGE_FREE_CELL_SIZE(pPage) ((pPage)->pPageMethods->szFreeCell) #define TDB_PAGE_NCELLS(pPage) (*(pPage)->pPageMethods->getCellNum)(pPage) From aee8b603242f0db0facc04cb7b3793815395c521 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 08:13:32 +0000 Subject: [PATCH 042/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index d1188ee5b3..6daecb7908 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -564,7 +564,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { // page is full, use a new page nNews++; - // for a child leaf case, this cell is used as the new divider cell + // for a child leaf case, this cell is used as the new divider cell to parent if (childLeaf) continue; } infoNews[nNews].cnt++; @@ -591,10 +591,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { for (int iNew = nNews - 1; iNew > 0; iNew--) { SCell *pCell; SPage *pPage; + int nCells; int cellBytes; + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + for (;;) { - pPage = pOlds[infoNews[iNew - 1].oPage]; pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); @@ -604,7 +607,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { infoNews[iNew - 1].size -= cellBytes; if ((infoNews[iNew - 1].oIdx--) == 0) { infoNews[iNew - 1].oPage--; - infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pOlds[infoNews[iNew - 1].oPage]); + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pPage); } if (infoNews[iNew].size > infoNews[iNew - 1].size) { From d7b54201bcab335b39a881d32f06af88bb987d72 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 08:26:43 +0000 Subject: [PATCH 043/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 50 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 6daecb7908..cda958c578 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -520,7 +520,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } // copy the parent key out if child pages are not leaf page childLeaf = TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); - if (childLeaf) { + if (!childLeaf) { for (int i = 0; i < nOlds - 1; i++) { pCell = tdbPageGetCell(pParent, sIdx + i); @@ -564,8 +564,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { // page is full, use a new page nNews++; - // for a child leaf case, this cell is used as the new divider cell to parent - if (childLeaf) continue; + // for a internal leaf case, this cell is used as the new divider cell to parent + if (!childLeaf) continue; } infoNews[nNews].cnt++; infoNews[nNews].size += cellBytes; @@ -573,8 +573,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { infoNews[nNews].oIdx = oIdx; } - // For child leaf pages - if (childLeaf && oPage < nOlds - 1) { + // For internal pages + if (!childLeaf && oPage < nOlds - 1) { if (infoNews[nNews].size + szDivCell[oPage] + TDB_PAGE_OFFSET_SIZE(pPage) > TDB_PAGE_USABLE_SIZE(pPage)) { nNews++; } @@ -594,27 +594,31 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nCells; int cellBytes; - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); + if (childLeaf) { // child leaf + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); - for (;;) { - pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); - cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); + for (;;) { + pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); + cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - infoNews[iNew].cnt++; - infoNews[iNew].size += cellBytes; - infoNews[iNew - 1].cnt--; - infoNews[iNew - 1].size -= cellBytes; - if ((infoNews[iNew - 1].oIdx--) == 0) { - infoNews[iNew - 1].oPage--; - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); - infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pPage); - } - - if (infoNews[iNew].size > infoNews[iNew - 1].size) { - break; + infoNews[iNew].cnt++; + infoNews[iNew].size += cellBytes; + infoNews[iNew - 1].cnt--; + infoNews[iNew - 1].size -= cellBytes; + if ((infoNews[iNew - 1].oIdx--) == 0) { + infoNews[iNew - 1].oPage--; + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pPage); + } + + if (infoNews[iNew].size > infoNews[iNew - 1].size) { + break; + } } + } else { // internal leaf + // TODO } } } From 3b49a863ea18e13f224088a212dc3a522089f770 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 10:43:51 +0000 Subject: [PATCH 044/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 194 ++++++++++++++++++++++++------ 1 file changed, 154 insertions(+), 40 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index cda958c578..4c6d85bc0a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -564,7 +564,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { // page is full, use a new page nNews++; - // for a internal leaf case, this cell is used as the new divider cell to parent + // for an internal leaf case, this cell is used as the new divider cell to parent if (!childLeaf) continue; } infoNews[nNews].cnt++; @@ -594,10 +594,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nCells; int cellBytes; - if (childLeaf) { // child leaf - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + if (childLeaf) { // child leaf for (;;) { pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); @@ -618,7 +618,55 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } else { // internal leaf - // TODO + SCell *pCellRight; + SCell *pCellLeft; + int szCellRight, szCellLeft; + + // get pCellLeft, szCellLeft + if (infoNews[iNew - 1].oIdx == nCells) { + ASSERT(infoNews[iNew - 1].oPage < nOlds - 1); + pCellLeft = pDivCell[infoNews[iNew - 1].oPage]; + szCellLeft = szDivCell[infoNews[iNew - 1].oPage]; + } else { + pCellLeft = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); + szCellLeft = tdbBtreeCellSize(pPage, pCellLeft); + } + + // get pCellRight, szCellRight + if (infoNews[iNew - 1].oIdx + 1 < nCells) { + pCellRight = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx + 1); + szCellRight = tdbBtreeCellSize(pPage, pCellRight); + } else { + if (infoNews[iNew - 1].oPage < nOlds - 1) { + pCellRight = pDivCell[infoNews[iNew - 1].oPage]; + szCellRight = szDivCell[infoNews[iNew - 1].oPage]; + } else { + // TODO: what if the next old page is empty? + pCellRight = tdbPageGetCell(pOlds[infoNews[iNew - 1].oPage + 1], 0); + szCellRight = tdbBtreeCellSize(pPage, pCellRight); + } + } + + if (infoNews[iNew - 1].size - szCellLeft - TDB_PAGE_OFFSET_SIZE(pPage) <= + infoNews[iNew].size + szCellRight + TDB_PAGE_OFFSET_SIZE(pPage)) { + break; + } + + // TODO: ASSERT(infoNews[iNew].size < PAGE_MAX_CAPACITY); + infoNews[iNew].cnt++; + infoNews[iNew].size += szCellRight; + infoNews[iNew - 1].cnt--; + infoNews[iNew - 1].size -= szCellLeft; + if ((infoNews[iNew - 1].oIdx--) == 0) { + infoNews[iNew - 1].oPage--; + pPage = pOlds[infoNews[iNew - 1].oPage]; + nCells = TDB_PAGE_TOTAL_CELLS(pPage); + if (infoNews[iNew - 1].oPage < nOlds - 1) { + infoNews[iNew - 1].oIdx = nCells; + } else { + infoNews[iNew - 1].oIdx = nCells - 1; + } + } } } } @@ -654,6 +702,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int tPage, tIdx, iOld; SCell *pCell; int szCell; + int nCells; + SCellDecoder cd; SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt}; for (int i = 0; i < 2; i++) { @@ -666,28 +716,117 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { tPage = 0; tIdx = 0; iOld = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld++], pTPage[tPage]); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + if (!childLeaf) { + ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + } for (int iNew = 0; iNew < nNews; iNew++) { // fill the iNew page + // TODO: copy current page to tmp space tdbBtreeZeroPage(pNews[iNew], &iarg); for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) { - while (tIdx >= TDB_PAGE_TOTAL_CELLS(pTPage[tPage])) { - tPage = (tPage + 1) % 2; - tIdx = 0; + for (;;) { // loop to find the next available cell + if (tIdx < nCells) { + pCell = tdbPageGetCell(pTPage[tPage], tIdx); + szCell = tdbBtreeCellSize(pTPage[tPage], pCell); + tIdx++; + break; + } else { + if (!childLeaf) { + if (iOld < nOlds - 1) { + pCell = pDivCell[iOld]; + szCell = szDivCell[iOld]; + ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld++], pTPage[tPage]); + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + break; + } else { + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + } + } else { + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + } + } } - pCell = tdbPageGetCell(pTPage[tPage], tIdx); - szCell = tdbBtreeCellSize(pTPage[tPage], pCell); - tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell); + } - tIdx++; + // fill right-most child pgno if internal page + if (!childLeaf) { + if (tIdx < nCells) { + pCell = tdbPageGetCell(pTPage[tPage], tIdx); + szCell = tdbBtreeCellSize(pTPage[tPage], pCell); + tIdx++; + break; + } else { + if (!childLeaf) { + if (iOld < nOlds - 1) { + pCell = pDivCell[iOld]; + szCell = szDivCell[iOld]; + ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + break; + } else { + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + } + } else { + iOld++; + tPage = (tPage + 1) % 2; + tIdx = 0; + nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + tdbBtreeZeroPage(pTPage[tPage], &iarg); + tdbPageCopy(pOlds[iOld], pTPage[tPage]); + } + } + + ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; + } + + // insert divider cell into the parent page + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + if (iNew == nNews - 1 && pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + } else { + tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); + tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, + &szCell); + // TODO: the cell here may be used by pParent as an overflow cell + tdbPageInsertCell(pParent, sIdx++, pCell, szCell); } } @@ -696,31 +835,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - { // Insert records in parent page - int cIdx = sIdx; - int szCell; - SCell pCell[128]; // TODO - SCellDecoder cd; - - for (int iNew = 0; iNew < nNews; iNew++) { - if (iNew == nNews - 1) { - // The last new page - - SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; - if (pIntHdr->pgno == 0) { - pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); - break; - } - } - - tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); - - tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); - // TODO: the cell here may be used by pParent as an overflow cell - tdbPageInsertCell(pParent, cIdx, pCell, szCell); - } - } - return 0; } From 3a173f466069f6cf59f2e9e281eaf9298886766d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 22 Mar 2022 11:47:25 +0000 Subject: [PATCH 045/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4c6d85bc0a..67b11f8ef4 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -204,7 +204,19 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p } static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) { - // TODO + int ret; + + pCur->pgStack[pCur->iPage] = pCur->pPage; + pCur->idxStack[pCur->iPage] = pCur->idx; + pCur->iPage++; + pCur->pPage = NULL; + pCur->idx = -1; + + ret = tdbPagerFetchPage(pCur->pBt->pPager, pgno, &pCur->pPage, tdbBtreeInitPage, pCur->pBt); + if (ret < 0) { + ASSERT(0); + } + return 0; } @@ -287,14 +299,12 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p pCur->idx = midx; tdbBtCursorMoveToChild(pCur, cd.pgno); } else { + pCur->idx = midx + 1; if (midx == nCells - 1) { /* Move to right-most child */ - pCur->idx = midx + 1; - // tdbBtCursorMoveToChild(pCur, ((SBtPageHdr *)(pPage->pAmHdr))->rChild); + tdbBtCursorMoveToChild(pCur, ((SIntHdr *)pCur->pPage->pData)->pgno); } else { - // TODO: reset cd as uninitialized - pCur->idx = midx + 1; - pCell = tdbPageGetCell(pPage, midx + 1); + pCell = tdbPageGetCell(pPage, pCur->idx); tdbBtreeDecodeCell(pPage, pCell, &cd); tdbBtCursorMoveToChild(pCur, cd.pgno); } From 44daa77d8db957e3d9e7ca150bfce61f26f8764a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 05:32:39 +0000 Subject: [PATCH 046/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 33 ++++++++++++++++++------------ source/libs/tdb/src/inc/tdbPage.h | 2 +- source/libs/tdb/src/page/tdbPage.c | 28 ++++++++++++------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 67b11f8ef4..a1f879c729 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -187,7 +187,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p } // Insert the cell to the index - ret = tdbPageInsertCell(pCur->pPage, idx, pCell, szCell); + ret = tdbPageInsertCell(pCur->pPage, idx, pCell, szCell, 0); if (ret < 0) { return -1; } @@ -490,7 +490,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { SCell *pDivCell[2] = {0}; int szDivCell[2]; int sIdx; - u8 childLeaf; + u8 childNotLeaf; { // Find 3 child pages at most to do balance int nCells = TDB_PAGE_TOTAL_CELLS(pParent); @@ -529,14 +529,21 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } // copy the parent key out if child pages are not leaf page - childLeaf = TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); - if (!childLeaf) { + childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); + if (childNotLeaf) { for (int i = 0; i < nOlds - 1; i++) { pCell = tdbPageGetCell(pParent, sIdx + i); szDivCell[i] = tdbBtreeCellSize(pParent, pCell); pDivCell[i] = malloc(szDivCell[i]); memcpy(pDivCell, pCell, szDivCell[i]); + + ((SPgno *)pDivCell)[0] = ((SIntHdr *)pOlds[i]->pData)->pgno; + ((SIntHdr *)pOlds[i]->pData)->pgno = 0; + + // here we insert the cell as an overflow cell to avoid + // the slow defragment process + tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } } // drop the cells on parent page @@ -575,7 +582,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // page is full, use a new page nNews++; // for an internal leaf case, this cell is used as the new divider cell to parent - if (!childLeaf) continue; + if (childNotLeaf) continue; } infoNews[nNews].cnt++; infoNews[nNews].size += cellBytes; @@ -584,7 +591,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } // For internal pages - if (!childLeaf && oPage < nOlds - 1) { + if (childNotLeaf && oPage < nOlds - 1) { if (infoNews[nNews].size + szDivCell[oPage] + TDB_PAGE_OFFSET_SIZE(pPage) > TDB_PAGE_USABLE_SIZE(pPage)) { nNews++; } @@ -607,7 +614,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { pPage = pOlds[infoNews[iNew - 1].oPage]; nCells = TDB_PAGE_TOTAL_CELLS(pPage); - if (childLeaf) { // child leaf + if (!childNotLeaf) { // child leaf for (;;) { pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); @@ -729,7 +736,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); tdbBtreeZeroPage(pTPage[tPage], &iarg); tdbPageCopy(pOlds[iOld], pTPage[tPage]); - if (!childLeaf) { + if (childNotLeaf) { ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; } @@ -746,7 +753,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { tIdx++; break; } else { - if (!childLeaf) { + if (childNotLeaf) { if (iOld < nOlds - 1) { pCell = pDivCell[iOld]; szCell = szDivCell[iOld]; @@ -780,18 +787,18 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell); + tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell, 0); } // fill right-most child pgno if internal page - if (!childLeaf) { + if (childNotLeaf) { if (tIdx < nCells) { pCell = tdbPageGetCell(pTPage[tPage], tIdx); szCell = tdbBtreeCellSize(pTPage[tPage], pCell); tIdx++; break; } else { - if (!childLeaf) { + if (!childNotLeaf) { if (iOld < nOlds - 1) { pCell = pDivCell[iOld]; szCell = szDivCell[iOld]; @@ -836,7 +843,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, &szCell); // TODO: the cell here may be used by pParent as an overflow cell - tdbPageInsertCell(pParent, sIdx++, pCell, szCell); + tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); } } diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index 0ba7cf236b..a6f9fbf615 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -108,7 +108,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); -int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell); +int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); int tdbPageDropCell(SPage *pPage, int idx); void tdbPageCopy(SPage *pFromPage, SPage *pToPage); diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 14960de45d..ee1a021a1b 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -114,7 +114,7 @@ void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell ASSERT(pPage->pFreeEnd - pPage->pFreeStart <= TDB_PAGE_NFREE(pPage)); } -int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { +int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl) { int nFree; int nCells; int iOvfl; @@ -135,7 +135,19 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { lidx = idx - iOvfl; - if (nFree >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { + if (asOvfl || nFree < szCell + TDB_PAGE_OFFSET_SIZE(pPage)) { + // TODO: make it extensible + // add the cell as an overflow cell + for (int i = pPage->nOverflow; i > iOvfl; i--) { + pPage->apOvfl[i] = pPage->apOvfl[i - 1]; + pPage->aiOvfl[i] = pPage->aiOvfl[i - 1]; + } + + pPage->apOvfl[iOvfl] = pCell; + pPage->aiOvfl[iOvfl] = idx; + pPage->nOverflow++; + iOvfl++; + } else { // page must has enough space to hold the cell locally tdbPageAllocate(pPage, szCell, &pNewCell); @@ -149,18 +161,6 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { TDB_PAGE_NCELLS_SET(pPage, nCells + 1); ASSERT(pPage->pFreeStart == pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * (nCells + 1)); - } else { - // TODO: make it extensible - // add the cell as an overflow cell - for (int i = pPage->nOverflow; i > iOvfl; i--) { - pPage->apOvfl[i] = pPage->apOvfl[i - 1]; - pPage->aiOvfl[i] = pPage->aiOvfl[i - 1]; - } - - pPage->apOvfl[iOvfl] = pCell; - pPage->aiOvfl[iOvfl] = idx; - pPage->nOverflow++; - iOvfl++; } for (; iOvfl < pPage->nOverflow; iOvfl++) { From 5c9e63e5018f42af709ac3a75fa831fb7bacff86 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 06:56:53 +0000 Subject: [PATCH 047/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 327 +++++++++++++++++------------- source/libs/tdb/src/inc/tdbInt.h | 4 +- 2 files changed, 183 insertions(+), 148 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a1f879c729..459154e9fb 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -451,13 +451,15 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { SPage *pChild; SPgno pgnoChild; int ret; + u8 flags; SIntHdr *pIntHdr; SBtreeInitPageArg zArg; pPager = pRoot->pPager; + flags = TDB_BTREE_PAGE_GET_FLAGS(pRoot); // Allocate a new child page - zArg.flags = TDB_BTREE_LEAF; + zArg.flags = TDB_FLAG_REMOVE(flags, TDB_BTREE_ROOT); zArg.pBt = pBt; ret = tdbPagerNewPage(pPager, &pgnoChild, &pChild, tdbBtreeZeroPage, &zArg); if (ret < 0) { @@ -559,10 +561,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nNews = 0; struct { - int cnt; - int size; - int oPage; - int oIdx; + int cnt; + int size; + SPage *pPage; + int oIdx; } infoNews[5] = {0}; { // Get how many new pages are needed and the new distribution @@ -581,31 +583,63 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (infoNews[nNews].size + cellBytes > TDB_PAGE_USABLE_SIZE(pPage)) { // page is full, use a new page nNews++; - // for an internal leaf case, this cell is used as the new divider cell to parent - if (childNotLeaf) continue; - } - infoNews[nNews].cnt++; - infoNews[nNews].size += cellBytes; - infoNews[nNews].oPage = oPage; - infoNews[nNews].oIdx = oIdx; - } - // For internal pages - if (childNotLeaf && oPage < nOlds - 1) { - if (infoNews[nNews].size + szDivCell[oPage] + TDB_PAGE_OFFSET_SIZE(pPage) > TDB_PAGE_USABLE_SIZE(pPage)) { - nNews++; + ASSERT(infoNews[nNews].size + cellBytes <= TDB_PAGE_USABLE_SIZE(pPage)); + + if (childNotLeaf) { + // for non-child page, this cell is used as the right-most child, + // the divider cell to parent as well + continue; + } } infoNews[nNews].cnt++; infoNews[nNews].size += cellBytes; - infoNews[nNews].oPage = oPage; + infoNews[nNews].pPage = pPage; infoNews[nNews].oIdx = oIdx; } } - nNews = nNews + 1; + nNews++; // back loop to make the distribution even for (int iNew = nNews - 1; iNew > 0; iNew--) { + SCell *pLCell, pRCell; + int szLCell, szRCell; + + for (;;) { + if (childNotLeaf) { + pLCell = pRCell = tdbPageGetCell(infoNews[iNew - 1].pPage, infoNews[iNew - 1].oIdx); + szLCell = szRCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pLCell); + } else { + // For internal page, find the left cell + // TODO: fill pLCell, pRCell, szLCell, szRCell + } + + ASSERT(infoNews[iNew - 1].cnt > 0); + + if (infoNews[iNew].size + szRCell >= infoNews[iNew - 1].size - szRCell) { + break; + } + + // move cell divider left + infoNews[iNew].cnt++; + infoNews[iNew].size += szRCell; + { + // TODO + // infoNews[iNew].oPage = ; + // infoNews[iNew].oIdx = ; + } + + infoNews[iNew - 1].cnt--; + infoNews[iNew - 1].size -= szLCell; + { + // TODO + // infoNews[iNew-1].oPage = ; + // infoNews[iNew-1].oIdx = ; + } + } + +#if 0 SCell *pCell; SPage *pPage; int nCells; @@ -685,6 +719,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } +#endif } } @@ -713,146 +748,146 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // TODO: sort the page according to the page number } - { // Do the real cell distribution + // { // Do the real cell distribution - SPage *pTPage[2]; - int tPage, tIdx, iOld; - SCell *pCell; - int szCell; - int nCells; - SCellDecoder cd; - SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt}; + // SPage *pTPage[2]; + // int tPage, tIdx, iOld; + // SCell *pCell; + // int szCell; + // int nCells; + // SCellDecoder cd; + // SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt}; - for (int i = 0; i < 2; i++) { - ret = tdbPageCreate(pOlds[0]->pageSize, &pTPage[i], NULL, NULL); - if (ret < 0) { - ASSERT(0); - } - } + // for (int i = 0; i < 2; i++) { + // ret = tdbPageCreate(pOlds[0]->pageSize, &pTPage[i], NULL, NULL); + // if (ret < 0) { + // ASSERT(0); + // } + // } - tPage = 0; - tIdx = 0; - iOld = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - if (childNotLeaf) { - ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - } + // tPage = 0; + // tIdx = 0; + // iOld = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // if (childNotLeaf) { + // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // } - for (int iNew = 0; iNew < nNews; iNew++) { - // fill the iNew page - // TODO: copy current page to tmp space - tdbBtreeZeroPage(pNews[iNew], &iarg); + // for (int iNew = 0; iNew < nNews; iNew++) { + // // fill the iNew page + // // TODO: copy current page to tmp space + // tdbBtreeZeroPage(pNews[iNew], &iarg); - for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) { - for (;;) { // loop to find the next available cell - if (tIdx < nCells) { - pCell = tdbPageGetCell(pTPage[tPage], tIdx); - szCell = tdbBtreeCellSize(pTPage[tPage], pCell); - tIdx++; - break; - } else { - if (childNotLeaf) { - if (iOld < nOlds - 1) { - pCell = pDivCell[iOld]; - szCell = szDivCell[iOld]; - ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) { + // for (;;) { // loop to find the next available cell + // if (tIdx < nCells) { + // pCell = tdbPageGetCell(pTPage[tPage], tIdx); + // szCell = tdbBtreeCellSize(pTPage[tPage], pCell); + // tIdx++; + // break; + // } else { + // if (childNotLeaf) { + // if (iOld < nOlds - 1) { + // pCell = pDivCell[iOld]; + // szCell = szDivCell[iOld]; + // ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - break; - } else { - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - } - } else { - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - } - } - } + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // break; + // } else { + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // } + // } else { + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // } + // } + // } - tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell, 0); - } + // tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell, 0); + // } - // fill right-most child pgno if internal page - if (childNotLeaf) { - if (tIdx < nCells) { - pCell = tdbPageGetCell(pTPage[tPage], tIdx); - szCell = tdbBtreeCellSize(pTPage[tPage], pCell); - tIdx++; - break; - } else { - if (!childNotLeaf) { - if (iOld < nOlds - 1) { - pCell = pDivCell[iOld]; - szCell = szDivCell[iOld]; - ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // // fill right-most child pgno if internal page + // if (childNotLeaf) { + // if (tIdx < nCells) { + // pCell = tdbPageGetCell(pTPage[tPage], tIdx); + // szCell = tdbBtreeCellSize(pTPage[tPage], pCell); + // tIdx++; + // break; + // } else { + // if (!childNotLeaf) { + // if (iOld < nOlds - 1) { + // pCell = pDivCell[iOld]; + // szCell = szDivCell[iOld]; + // ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - break; - } else { - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - } - } else { - iOld++; - tPage = (tPage + 1) % 2; - tIdx = 0; - nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - tdbBtreeZeroPage(pTPage[tPage], &iarg); - tdbPageCopy(pOlds[iOld], pTPage[tPage]); - } - } + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // break; + // } else { + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // } + // } else { + // iOld++; + // tPage = (tPage + 1) % 2; + // tIdx = 0; + // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); + // tdbBtreeZeroPage(pTPage[tPage], &iarg); + // tdbPageCopy(pOlds[iOld], pTPage[tPage]); + // } + // } - ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; - } + // ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; + // } - // insert divider cell into the parent page - SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; - if (iNew == nNews - 1 && pIntHdr->pgno == 0) { - pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); - } else { - tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); - tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, - &szCell); - // TODO: the cell here may be used by pParent as an overflow cell - tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); - } - } + // // insert divider cell into the parent page + // SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + // if (iNew == nNews - 1 && pIntHdr->pgno == 0) { + // pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + // } else { + // tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); + // tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, + // &szCell); + // // TODO: the cell here may be used by pParent as an overflow cell + // tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); + // } + // } - for (int i = 0; i < 2; i++) { - tdbPageDestroy(pTPage[i], NULL, NULL); - } - } + // for (int i = 0; i < 2; i++) { + // tdbPageDestroy(pTPage[i], NULL, NULL); + // } +} - return 0; +return 0; } static int tdbBtreeBalance(SBtCursor *pCur) { diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 5902a6a716..3ebba0a4b5 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -141,8 +141,8 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i #define TDB_FLAG_IS(flags, flag) ((flags) == (flag)) #define TDB_FLAG_HAS(flags, flag) (((flags) & (flag)) != 0) #define TDB_FLAG_NO(flags, flag) ((flags) & (flag) == 0) -#define TDB_FLAG_ADD(flags, flag) ((flags) |= (flag)) -#define TDB_FLAG_REMOVE(flags, flag) ((flags) &= (~(flag))) +#define TDB_FLAG_ADD(flags, flag) ((flags) | (flag)) +#define TDB_FLAG_REMOVE(flags, flag) ((flags) & (~(flag))) typedef struct SPager SPager; typedef struct SPCache SPCache; From 9b8a8f12871a85b12d351e4e707c593e3254d770 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 07:17:26 +0000 Subject: [PATCH 048/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 119 +++++++----------------------- 1 file changed, 25 insertions(+), 94 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 459154e9fb..f649a8e9f6 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -603,16 +603,30 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // back loop to make the distribution even for (int iNew = nNews - 1; iNew > 0; iNew--) { - SCell *pLCell, pRCell; + SCell *pCell; int szLCell, szRCell; for (;;) { + pCell = tdbPageGetCell(infoNews[iNew - 1].pPage, infoNews[iNew - 1].oIdx); + if (childNotLeaf) { - pLCell = pRCell = tdbPageGetCell(infoNews[iNew - 1].pPage, infoNews[iNew - 1].oIdx); - szLCell = szRCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pLCell); + szLCell = szRCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pCell); } else { - // For internal page, find the left cell - // TODO: fill pLCell, pRCell, szLCell, szRCell + szLCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pCell); + + SPage *pPage = infoNews[iNew - 1].pPage; + int oIdx = infoNews[iNew - 1].oIdx + 1; + for (;;) { + if (oIdx < TDB_PAGE_TOTAL_CELLS(pPage)) { + break; + } + + pPage++; + oIdx = 0; + } + + pCell = tdbPageGetCell(pPage, oIdx); + szRCell = tdbBtreeCellSize(pPage, pCell); } ASSERT(infoNews[iNew - 1].cnt > 0); @@ -621,105 +635,22 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { break; } - // move cell divider left - infoNews[iNew].cnt++; - infoNews[iNew].size += szRCell; - { - // TODO - // infoNews[iNew].oPage = ; - // infoNews[iNew].oIdx = ; - } - + // Move a cell right forward infoNews[iNew - 1].cnt--; infoNews[iNew - 1].size -= szLCell; - { - // TODO - // infoNews[iNew-1].oPage = ; - // infoNews[iNew-1].oIdx = ; - } - } - -#if 0 - SCell *pCell; - SPage *pPage; - int nCells; - int cellBytes; - - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); - - if (!childNotLeaf) { // child leaf + infoNews[iNew - 1].oIdx--; for (;;) { - pCell = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); - cellBytes = TDB_BYTES_CELL_TAKEN(pPage, pCell); - - infoNews[iNew].cnt++; - infoNews[iNew].size += cellBytes; - infoNews[iNew - 1].cnt--; - infoNews[iNew - 1].size -= cellBytes; - if ((infoNews[iNew - 1].oIdx--) == 0) { - infoNews[iNew - 1].oPage--; - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); - infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pPage); - } - - if (infoNews[iNew].size > infoNews[iNew - 1].size) { + if (infoNews[iNew - 1].oIdx >= 0) { break; } - } - } else { // internal leaf - SCell *pCellRight; - SCell *pCellLeft; - int szCellRight, szCellLeft; - // get pCellLeft, szCellLeft - if (infoNews[iNew - 1].oIdx == nCells) { - ASSERT(infoNews[iNew - 1].oPage < nOlds - 1); - pCellLeft = pDivCell[infoNews[iNew - 1].oPage]; - szCellLeft = szDivCell[infoNews[iNew - 1].oPage]; - } else { - pCellLeft = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx); - szCellLeft = tdbBtreeCellSize(pPage, pCellLeft); + infoNews[iNew - 1].pPage--; + infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(infoNews[iNew - 1].pPage) - 1; } - // get pCellRight, szCellRight - if (infoNews[iNew - 1].oIdx + 1 < nCells) { - pCellRight = tdbPageGetCell(pPage, infoNews[iNew - 1].oIdx + 1); - szCellRight = tdbBtreeCellSize(pPage, pCellRight); - } else { - if (infoNews[iNew - 1].oPage < nOlds - 1) { - pCellRight = pDivCell[infoNews[iNew - 1].oPage]; - szCellRight = szDivCell[infoNews[iNew - 1].oPage]; - } else { - // TODO: what if the next old page is empty? - pCellRight = tdbPageGetCell(pOlds[infoNews[iNew - 1].oPage + 1], 0); - szCellRight = tdbBtreeCellSize(pPage, pCellRight); - } - } - - if (infoNews[iNew - 1].size - szCellLeft - TDB_PAGE_OFFSET_SIZE(pPage) <= - infoNews[iNew].size + szCellRight + TDB_PAGE_OFFSET_SIZE(pPage)) { - break; - } - - // TODO: ASSERT(infoNews[iNew].size < PAGE_MAX_CAPACITY); infoNews[iNew].cnt++; - infoNews[iNew].size += szCellRight; - infoNews[iNew - 1].cnt--; - infoNews[iNew - 1].size -= szCellLeft; - if ((infoNews[iNew - 1].oIdx--) == 0) { - infoNews[iNew - 1].oPage--; - pPage = pOlds[infoNews[iNew - 1].oPage]; - nCells = TDB_PAGE_TOTAL_CELLS(pPage); - if (infoNews[iNew - 1].oPage < nOlds - 1) { - infoNews[iNew - 1].oIdx = nCells; - } else { - infoNews[iNew - 1].oIdx = nCells - 1; - } - } + infoNews[iNew].size += szRCell; } -#endif } } From 15fa64ebaab2f3f8237105b83d060cc57c5c3089 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 07:39:57 +0000 Subject: [PATCH 049/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 177 ++++++++---------------------- 1 file changed, 48 insertions(+), 129 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index f649a8e9f6..8912a765fd 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -679,146 +679,65 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // TODO: sort the page according to the page number } - // { // Do the real cell distribution + { // Do the real cell distribution + SPage *pOldsCopy[3]; + SCell *pCell; + int szCell; + SBtreeInitPageArg iarg; + int iNew, nNewCells; - // SPage *pTPage[2]; - // int tPage, tIdx, iOld; - // SCell *pCell; - // int szCell; - // int nCells; - // SCellDecoder cd; - // SBtreeInitPageArg iarg = {.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]), .pBt = pBt}; + iarg.pBt = pBt; + iarg.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]); + for (int i = 0; i < nOlds; i++) { + tdbPageCreate(pOlds[0]->pageSize, pOldsCopy + i, NULL, NULL); + tdbBtreeZeroPage(pOldsCopy[i], &iarg); + tdbPageCopy(pOlds[i], pOldsCopy[i]); + } + iNew = 0; + nNewCells = 0; - // for (int i = 0; i < 2; i++) { - // ret = tdbPageCreate(pOlds[0]->pageSize, &pTPage[i], NULL, NULL); - // if (ret < 0) { - // ASSERT(0); - // } - // } + for (int iOld = 0; iOld < nOlds; iOld++) { + SPage *pPage; - // tPage = 0; - // tIdx = 0; - // iOld = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // if (childNotLeaf) { - // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - // } + pPage = pOldsCopy[iOld]; - // for (int iNew = 0; iNew < nNews; iNew++) { - // // fill the iNew page - // // TODO: copy current page to tmp space - // tdbBtreeZeroPage(pNews[iNew], &iarg); + for (int oIdx = 0; oIdx < TDB_PAGE_TOTAL_CELLS(pPage); oIdx++) { + pCell = tdbPageGetCell(pPage, oIdx); + szCell = tdbBtreeCellSize(pPage, pCell); - // for (int iCell = 0; iCell < infoNews[iNew].cnt; iCell++) { - // for (;;) { // loop to find the next available cell - // if (tIdx < nCells) { - // pCell = tdbPageGetCell(pTPage[tPage], tIdx); - // szCell = tdbBtreeCellSize(pTPage[tPage], pCell); - // tIdx++; - // break; - // } else { - // if (childNotLeaf) { - // if (iOld < nOlds - 1) { - // pCell = pDivCell[iOld]; - // szCell = szDivCell[iOld]; - // ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + ASSERT(nNewCells <= infoNews[iNew].cnt); - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - // break; - // } else { - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - // } - // } else { - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // } - // } - // } + if (nNewCells < infoNews[iNew].cnt) { + tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); + nNewCells++; + } else { + if (childNotLeaf) { + // set current new page right-most child - // tdbPageInsertCell(pNews[iNew], iCell, pCell, szCell, 0); - // } + // move to next new page + } else { + // move to next new page - // // fill right-most child pgno if internal page - // if (childNotLeaf) { - // if (tIdx < nCells) { - // pCell = tdbPageGetCell(pTPage[tPage], tIdx); - // szCell = tdbBtreeCellSize(pTPage[tPage], pCell); - // tIdx++; - // break; - // } else { - // if (!childNotLeaf) { - // if (iOld < nOlds - 1) { - // pCell = pDivCell[iOld]; - // szCell = szDivCell[iOld]; - // ((SPgno *)pCell)[0] = ((SIntHdr *)pOlds[iOld]->pData)->pgno; + // insert the cell to the new page + } + } - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - // break; - // } else { - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // ((SIntHdr *)pTPage[tPage]->pData)->pgno = ((SIntHdr *)pOlds[iOld]->pData)->pgno; - // } - // } else { - // iOld++; - // tPage = (tPage + 1) % 2; - // tIdx = 0; - // nCells = TDB_PAGE_TOTAL_CELLS(pOlds[iOld]); - // tdbBtreeZeroPage(pTPage[tPage], &iarg); - // tdbPageCopy(pOlds[iOld], pTPage[tPage]); - // } - // } + if (nNewCells == infoNews[iNew].cnt) { + if (childNotLeaf) { + // TODO + } else { + // TODO + } + } + } + } - // ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; - // } + for (int i = 0; i < nOlds; i++) { + tdbPageDestroy(pOldsCopy[i], NULL, NULL); + } + } - // // insert divider cell into the parent page - // SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; - // if (iNew == nNews - 1 && pIntHdr->pgno == 0) { - // pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); - // } else { - // tdbBtreeDecodeCell(pNews[iNew], tdbPageGetCell(pNews[iNew], TDB_PAGE_TOTAL_CELLS(pNews[iNew]) - 1), &cd); - // tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&TDB_PAGE_PGNO(pNews[iNew]), sizeof(SPgno), pCell, - // &szCell); - // // TODO: the cell here may be used by pParent as an overflow cell - // tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); - // } - // } - - // for (int i = 0; i < 2; i++) { - // tdbPageDestroy(pTPage[i], NULL, NULL); - // } -} - -return 0; + return 0; } static int tdbBtreeBalance(SBtCursor *pCur) { From f8fc05c76e035de6c0fe2ffa0dbec1eec7b10987 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 07:48:08 +0000 Subject: [PATCH 050/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 8912a765fd..98b9455d13 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -712,13 +712,25 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { nNewCells++; } else { if (childNotLeaf) { + // Insert to parent + // set current new page right-most child + ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; // move to next new page + iNew++; + nNewCells = 0; } else { + // TODO: Insert to parent max key and current page number or the right most child + // move to next new page + iNew++; + nNewCells = 0; // insert the cell to the new page + ASSERT(nNewCells < infoNews[iNew].cnt); + tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); + nNewCells++; } } From 7b89447239f1971547d44adfede31d113066784f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 07:57:15 +0000 Subject: [PATCH 051/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 98b9455d13..c6270d6047 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -733,14 +733,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { nNewCells++; } } - - if (nNewCells == infoNews[iNew].cnt) { - if (childNotLeaf) { - // TODO - } else { - // TODO - } - } } } From 09833d2244a0da316a34d3b342513d55fc2a8753 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 08:21:09 +0000 Subject: [PATCH 052/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 49 ++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index c6270d6047..ca50631e90 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -710,28 +710,43 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (nNewCells < infoNews[iNew].cnt) { tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); nNewCells++; - } else { - if (childNotLeaf) { - // Insert to parent - // set current new page right-most child - ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; + // insert parent page + if (!childNotLeaf && nNewCells == infoNews[iNew].cnt) { + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + + if (iNew == nNews - 1 && pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + } else { + // TODO: + ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); + // TODO: pCell here may be inserted as an overflow cell, handle it + tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); + } // move to next new page iNew++; - nNewCells = 0; - } else { - // TODO: Insert to parent max key and current page number or the right most child - - // move to next new page - iNew++; - nNewCells = 0; - - // insert the cell to the new page - ASSERT(nNewCells < infoNews[iNew].cnt); - tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); - nNewCells++; + nNews = 0; } + } else { + ASSERT(childNotLeaf); + + // set current new page right-most child + ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; + + // insert to parent as divider cell + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + + if (iNew == nNews - 1 && pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); + } else { + ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); + tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); + } + + // move to next new page + iNew++; + nNewCells = 0; } } } From d5a1c7a31f9ea48c7b41a1b7f23f3769b1683123 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 08:25:57 +0000 Subject: [PATCH 053/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index ca50631e90..a6747e8903 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -685,6 +685,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int szCell; SBtreeInitPageArg iarg; int iNew, nNewCells; + SCellDecoder cd; iarg.pBt = pBt; iarg.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]); @@ -718,10 +719,15 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (iNew == nNews - 1 && pIntHdr->pgno == 0) { pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); } else { - // TODO: - ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); + tdbBtreeDecodeCell(pPage, pCell, &cd); + // TODO: pCell here may be inserted as an overflow cell, handle it - tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); + SCell *pNewCell = malloc(cd.kLen + 9); + int szNewCell; + SPgno pgno; + pgno = TDB_PAGE_PGNO(pNews[iNew]); + tdbBtreeEncodeCell(pPage, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); + tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); } // move to next new page From 72aed8997dfcf56f4a1942b4b58ee651b201bf1a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 08:39:22 +0000 Subject: [PATCH 054/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a6747e8903..68be6ec8cd 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -493,6 +493,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int szDivCell[2]; int sIdx; u8 childNotLeaf; + SPgno rPgno; { // Find 3 child pages at most to do balance int nCells = TDB_PAGE_TOTAL_CELLS(pParent); @@ -547,6 +548,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // the slow defragment process tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } + rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno; } // drop the cells on parent page for (int i = 0; i < nOlds; i++) { @@ -741,14 +743,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; // insert to parent as divider cell - SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; - - if (iNew == nNews - 1 && pIntHdr->pgno == 0) { - pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); - } else { - ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); - tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); - } + ASSERT(iNew < nNews - 1); + ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]); + tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0); // move to next new page iNew++; From 795981feae04c4c470768c8de9cff682e10336f4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 08:54:38 +0000 Subject: [PATCH 055/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 68be6ec8cd..1503d68575 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -737,6 +737,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { nNews = 0; } } else { + ASSERT(0); ASSERT(childNotLeaf); // set current new page right-most child From 2bb84eeb2becf4e636d06fff26d9a2443e8903ae Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 08:59:10 +0000 Subject: [PATCH 056/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 1503d68575..50f585ebd3 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -698,6 +698,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } iNew = 0; nNewCells = 0; + tdbBtreeZeroPage(pNews[iNew], &iarg); for (int iOld = 0; iOld < nOlds; iOld++) { SPage *pPage; @@ -735,6 +736,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // move to next new page iNew++; nNews = 0; + tdbBtreeZeroPage(pNews[iNew], &iarg); } } else { ASSERT(0); @@ -751,6 +753,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // move to next new page iNew++; nNewCells = 0; + tdbBtreeZeroPage(pNews[iNew], &iarg); } } } From 1fba9d5d3d162085f4dabf76ca79a1d009492c93 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 09:03:01 +0000 Subject: [PATCH 057/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 50f585ebd3..81b8be3588 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -735,8 +735,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // move to next new page iNew++; - nNews = 0; - tdbBtreeZeroPage(pNews[iNew], &iarg); + nNewCells = 0; + if (iNew < nNews) { + tdbBtreeZeroPage(pNews[iNew], &iarg); + } } } else { ASSERT(0); @@ -753,7 +755,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // move to next new page iNew++; nNewCells = 0; - tdbBtreeZeroPage(pNews[iNew], &iarg); + if (iNew < nNews) { + tdbBtreeZeroPage(pNews[iNew], &iarg); + } } } } From 33e119e9c037c63136bc3729de300e5bc9527e79 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 09:12:21 +0000 Subject: [PATCH 058/149] fix another TDB bug --- source/libs/tdb/src/db/tdbBtree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 81b8be3588..f0055723b6 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -729,7 +729,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int szNewCell; SPgno pgno; pgno = TDB_PAGE_PGNO(pNews[iNew]); - tdbBtreeEncodeCell(pPage, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); + tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); } From 48306365aed114b632fdf3ce76e7077da130692d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 09:35:25 +0000 Subject: [PATCH 059/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index f0055723b6..0f5e6733ed 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -563,10 +563,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nNews = 0; struct { - int cnt; - int size; - SPage *pPage; - int oIdx; + int cnt; + int size; + int iPage; + int oIdx; } infoNews[5] = {0}; { // Get how many new pages are needed and the new distribution @@ -596,7 +596,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } infoNews[nNews].cnt++; infoNews[nNews].size += cellBytes; - infoNews[nNews].pPage = pPage; + infoNews[nNews].iPage = oPage; infoNews[nNews].oIdx = oIdx; } } @@ -609,21 +609,23 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int szLCell, szRCell; for (;;) { - pCell = tdbPageGetCell(infoNews[iNew - 1].pPage, infoNews[iNew - 1].oIdx); + pCell = tdbPageGetCell(pOlds[infoNews[iNew - 1].iPage], infoNews[iNew - 1].oIdx); if (childNotLeaf) { - szLCell = szRCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pCell); + szLCell = szRCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell); } else { - szLCell = tdbBtreeCellSize(infoNews[iNew - 1].pPage, pCell); + szLCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell); - SPage *pPage = infoNews[iNew - 1].pPage; + int iPage = infoNews[iNew - 1].iPage; int oIdx = infoNews[iNew - 1].oIdx + 1; + SPage *pPage; for (;;) { + pPage = pOlds[iPage]; if (oIdx < TDB_PAGE_TOTAL_CELLS(pPage)) { break; } - pPage++; + iPage++; oIdx = 0; } @@ -646,8 +648,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { break; } - infoNews[iNew - 1].pPage--; - infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(infoNews[iNew - 1].pPage) - 1; + infoNews[iNew - 1].iPage--; + infoNews[iNew - 1].oIdx = TDB_PAGE_TOTAL_CELLS(pOlds[infoNews[iNew - 1].iPage]) - 1; } infoNews[iNew].cnt++; From 27bcf222cec34b67d40b90d33c0d934f6fffb611 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 10:12:43 +0000 Subject: [PATCH 060/149] fix another bug --- source/libs/tdb/src/page/tdbPage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index ee1a021a1b..5253a1fd67 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -288,8 +288,6 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { } else { TDB_PAGE_FCELL_SET(pPage, pFreeCell - pPage->pData); } - - goto _alloc_finish; } else { if (pPrevFreeCell) { pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, nxFreeCell); @@ -297,6 +295,8 @@ static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) { TDB_PAGE_FCELL_SET(pPage, nxFreeCell); } } + + goto _alloc_finish; } else { pPrevFreeCell = pFreeCell; szPrevFreeCell = szFreeCell; From b633a96bed37bececfe62551f005a79cedd90644 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 10:17:23 +0000 Subject: [PATCH 061/149] more TDB --- source/libs/tdb/test/tdbTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 7bdcc38173..63b53b1732 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -8,7 +8,7 @@ TEST(tdb_test, simple_test) { STDb *pDb; // Open Env - ret = tdbEnvOpen("tdb", 1024, 20, &pEnv); + ret = tdbEnvOpen("tdb", 1024, 256, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database From 2aa6d7e38482a76211f265c6edbc31d52ba7e387 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 23 Mar 2022 10:30:52 +0000 Subject: [PATCH 062/149] start the query --- source/libs/tdb/src/db/tdbDb.c | 5 +++++ source/libs/tdb/src/inc/tdbDb.h | 1 + source/libs/tdb/test/tdbTest.cpp | 35 ++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 00f38a19bb..27cbaeaa01 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -85,5 +85,10 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v return -1; } + return 0; +} + +int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen) { + // TODO return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 06ea74a83e..fdf4c4aca5 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -26,6 +26,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF int tdbDbClose(STDb *pDb); int tdbDbDrop(STDb *pDb); int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); +int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen); #ifdef __cplusplus } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 63b53b1732..c5a2787aaf 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,6 +6,7 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; + int nData = 1000; // Open Env ret = tdbEnvOpen("tdb", 1024, 256, &pEnv); @@ -15,15 +16,33 @@ TEST(tdb_test, simple_test) { ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); - { // Insert some data - char key[64]; - char val[64]; + { + char key[64]; + char val[64]; + void *pVal; + int vLen; - for (int i = 1; i <= 1000; i++) { - sprintf(key, "key%d", i); - sprintf(val, "value%d", i); - ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); - GTEST_ASSERT_EQ(ret, 0); + { // Insert some data + + for (int i = 1; i <= nData; i++) { + sprintf(key, "key%d", i); + sprintf(val, "value%d", i); + ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); + GTEST_ASSERT_EQ(ret, 0); + } + } + + { // Query the data + for (int i = 1; i <= nData; i++) { + sprintf(key, "key%d", i); + sprintf(val, "value%d", i); + + ret = tdbDbGet(pDb, key, strlen(key), pVal, &vLen); + GTEST_ASSERT_EQ(ret, 0); + + GTEST_ASSERT_EQ(vLen, strlen(val)); + GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); + } } } From 4383b3b53a45d597b8c2cbcd8a11df46cf923d55 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 02:09:56 +0000 Subject: [PATCH 063/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 28 ++++++++++++++++++++++++++++ source/libs/tdb/src/db/tdbDb.c | 5 ++--- source/libs/tdb/src/inc/tdbBtree.h | 1 + source/libs/tdb/src/inc/tdbDb.h | 2 +- source/libs/tdb/test/tdbTest.cpp | 2 +- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0f5e6733ed..f5715866ed 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -203,6 +203,34 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p return 0; } +int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) { + SBtCursor btc; + SCell *pCell; + int cret; + SCellDecoder cd; + + tdbBtreeCursor(&btc, pBt); + + tdbBtCursorMoveTo(&btc, pKey, kLen, &cret); + + if (cret) { + return cret; + } + + pCell = tdbPageGetCell(btc.pPage, btc.idx); + tdbBtreeDecodeCell(btc.pPage, pCell, &cd); + + *vLen = cd.vLen; + // TODO: here may have memory leak + *ppVal = realloc(*ppVal, *vLen); + if (*ppVal == NULL) { + return -1; + } + + memcpy(*ppVal, cd.pVal, cd.vLen); + return 0; +} + static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) { int ret; diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 27cbaeaa01..2ba9daaa4a 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -88,7 +88,6 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v return 0; } -int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen) { - // TODO - return 0; +int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { + return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index c1fe77c22e..a0b054a6a8 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -37,6 +37,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB int tdbBtreeClose(SBTree *pBt); int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt); int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen); +int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index fdf4c4aca5..6a9d653eac 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -26,7 +26,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF int tdbDbClose(STDb *pDb); int tdbDbDrop(STDb *pDb); int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); -int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen); +int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); #ifdef __cplusplus } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index c5a2787aaf..3d06d568e4 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -37,7 +37,7 @@ TEST(tdb_test, simple_test) { sprintf(key, "key%d", i); sprintf(val, "value%d", i); - ret = tdbDbGet(pDb, key, strlen(key), pVal, &vLen); + ret = tdbDbGet(pDb, key, strlen(key), &pVal, &vLen); GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(vLen, strlen(val)); From 20b1c0d236103f458d356c84d93497dc3858f2bd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 02:27:16 +0000 Subject: [PATCH 064/149] more TDB --- source/libs/tdb/test/tdbTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 3d06d568e4..1acd78f188 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,7 +6,7 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 1000; + int nData = 10000; // Open Env ret = tdbEnvOpen("tdb", 1024, 256, &pEnv); From 820de153a80e5a95e02d91e4dcdf0068103918a9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 05:46:59 +0000 Subject: [PATCH 065/149] fix invalid read --- source/libs/tdb/src/db/tdbBtree.c | 4 ++-- source/libs/tdb/src/page/tdbPage.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index f5715866ed..a733c0d981 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -712,7 +712,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } { // Do the real cell distribution - SPage *pOldsCopy[3]; + SPage *pOldsCopy[3] = {0}; SCell *pCell; int szCell; SBtreeInitPageArg iarg; @@ -722,7 +722,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { iarg.pBt = pBt; iarg.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]); for (int i = 0; i < nOlds; i++) { - tdbPageCreate(pOlds[0]->pageSize, pOldsCopy + i, NULL, NULL); + tdbPageCreate(pOlds[0]->pageSize, &pOldsCopy[i], NULL, NULL); tdbBtreeZeroPage(pOldsCopy[i], &iarg); tdbPageCopy(pOlds[i], pOldsCopy[i]); } diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 5253a1fd67..15b6e218e6 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -52,7 +52,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) } ptr = (u8 *)((*xMalloc)(arg, size)); - if (pPage == NULL) { + if (ptr == NULL) { return -1; } From d59b65fa54d958b2caee0b207687000051e10fc8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 06:00:35 +0000 Subject: [PATCH 066/149] fix memory bug --- source/libs/tdb/test/tdbTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 1acd78f188..653efaa19a 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -19,7 +19,7 @@ TEST(tdb_test, simple_test) { { char key[64]; char val[64]; - void *pVal; + void *pVal = NULL; int vLen; { // Insert some data From 08a270777c72cb90c8453a3d734ee085ba1e0e96 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 06:58:52 +0000 Subject: [PATCH 067/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 48 ++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a733c0d981..0bb50fe937 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -517,8 +517,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int nOlds; SPage *pOlds[3]; - SCell *pDivCell[2] = {0}; - int szDivCell[2]; + SCell *pDivCell[3] = {0}; + int szDivCell[3]; int sIdx; u8 childNotLeaf; SPgno rPgno; @@ -562,18 +562,18 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { // copy the parent key out if child pages are not leaf page childNotLeaf = !TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pOlds[0])); if (childNotLeaf) { - for (int i = 0; i < nOlds - 1; i++) { - pCell = tdbPageGetCell(pParent, sIdx + i); + for (int i = 0; i < nOlds; i++) { + if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { + pCell = tdbPageGetCell(pParent, sIdx + i); + szDivCell[i] = tdbBtreeCellSize(pParent, pCell); + pDivCell[i] = malloc(szDivCell[i]); + memcpy(pDivCell[i], pCell, szDivCell[i]); + } - szDivCell[i] = tdbBtreeCellSize(pParent, pCell); - pDivCell[i] = malloc(szDivCell[i]); - memcpy(pDivCell, pCell, szDivCell[i]); - - ((SPgno *)pDivCell)[0] = ((SIntHdr *)pOlds[i]->pData)->pgno; - ((SIntHdr *)pOlds[i]->pData)->pgno = 0; - - // here we insert the cell as an overflow cell to avoid - // the slow defragment process + if (i < nOlds - 1) { + ((SPgno *)pDivCell[i])[0] = ((SIntHdr *)pOlds[i]->pData)->pgno; + ((SIntHdr *)pOlds[i]->pData)->pgno = 0; + } tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno; @@ -740,6 +740,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { szCell = tdbBtreeCellSize(pPage, pCell); ASSERT(nNewCells <= infoNews[iNew].cnt); + ASSERT(iNew < nNews - 1); if (nNewCells < infoNews[iNew].cnt) { tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); @@ -771,8 +772,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } else { - ASSERT(0); ASSERT(childNotLeaf); + ASSERT(iNew < nNews - 1); // set current new page right-most child ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; @@ -790,6 +791,19 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } + + if (childNotLeaf) { + ASSERT(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt); + ((SIntHdr *)(pNews[nNews - 1]->pData))->pgno = rPgno; + + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + if (pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[nNews - 1]); + } else { + ((SPgno *)pDivCell[nOlds - 1])[0] = TDB_PAGE_PGNO(pNews[nNews - 1]); + tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0); + } + } } for (int i = 0; i < nOlds; i++) { @@ -797,6 +811,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } + for (int i = 0; i < 3; i++) { + if (pDivCell[i]) { + free(pDivCell[i]); + } + } + return 0; } From b6d27d3759c55168626212c425b72407211e01c3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 07:43:19 +0000 Subject: [PATCH 068/149] fix another bug --- source/libs/tdb/src/db/tdbBtree.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0bb50fe937..de2ed60ec7 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -516,7 +516,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { int ret; int nOlds; - SPage *pOlds[3]; + SPage *pOlds[3] = {0}; SCell *pDivCell[3] = {0}; int szDivCell[3]; int sIdx; @@ -573,8 +573,8 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (i < nOlds - 1) { ((SPgno *)pDivCell[i])[0] = ((SIntHdr *)pOlds[i]->pData)->pgno; ((SIntHdr *)pOlds[i]->pData)->pgno = 0; + tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } - tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1); } rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno; } @@ -740,7 +740,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { szCell = tdbBtreeCellSize(pPage, pCell); ASSERT(nNewCells <= infoNews[iNew].cnt); - ASSERT(iNew < nNews - 1); + ASSERT(iNew < nNews); if (nNewCells < infoNews[iNew].cnt) { tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); @@ -791,18 +791,18 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } } + } - if (childNotLeaf) { - ASSERT(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt); - ((SIntHdr *)(pNews[nNews - 1]->pData))->pgno = rPgno; + if (childNotLeaf) { + ASSERT(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt); + ((SIntHdr *)(pNews[nNews - 1]->pData))->pgno = rPgno; - SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; - if (pIntHdr->pgno == 0) { - pIntHdr->pgno = TDB_PAGE_PGNO(pNews[nNews - 1]); - } else { - ((SPgno *)pDivCell[nOlds - 1])[0] = TDB_PAGE_PGNO(pNews[nNews - 1]); - tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0); - } + SIntHdr *pIntHdr = (SIntHdr *)pParent->pData; + if (pIntHdr->pgno == 0) { + pIntHdr->pgno = TDB_PAGE_PGNO(pNews[nNews - 1]); + } else { + ((SPgno *)pDivCell[nOlds - 1])[0] = TDB_PAGE_PGNO(pNews[nNews - 1]); + tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0); } } From 493670d2f0ba7c226af5b00b54c8ef4b0447ee0e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 08:11:07 +0000 Subject: [PATCH 069/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index de2ed60ec7..eec75d3a13 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -482,9 +482,11 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { u8 flags; SIntHdr *pIntHdr; SBtreeInitPageArg zArg; + u8 leaf; pPager = pRoot->pPager; flags = TDB_BTREE_PAGE_GET_FLAGS(pRoot); + leaf = TDB_BTREE_PAGE_IS_LEAF(flags); // Allocate a new child page zArg.flags = TDB_FLAG_REMOVE(flags, TDB_BTREE_ROOT); @@ -494,6 +496,10 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) { return -1; } + if (!leaf) { + ((SIntHdr *)pChild->pData)->pgno = ((SIntHdr *)(pRoot->pData))->pgno; + } + // Copy the root page content to the child page tdbPageCopy(pRoot, pChild); From c9fe5301564e14313331b0231b2c344c3961bbad Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 08:16:14 +0000 Subject: [PATCH 070/149] add more test --- source/libs/tdb/test/tdbTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 653efaa19a..5285a5ee94 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,10 +6,10 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 10000; + int nData = 50000; // Open Env - ret = tdbEnvOpen("tdb", 1024, 256, &pEnv); + ret = tdbEnvOpen("tdb", 1024, 2560, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database From eb9d3f2196581a1c65534766e582e9dbb7d1e121 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 08:40:37 +0000 Subject: [PATCH 071/149] more TDB --- source/libs/tdb/src/inc/tdbDb.h | 3 ++- source/libs/tdb/test/tdbTest.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 6a9d653eac..7a65966be3 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -20,7 +20,8 @@ extern "C" { #endif -typedef struct STDb STDb; +typedef struct STDb STDb; +typedef struct STDbC STDbC; int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb); int tdbDbClose(STDb *pDb); diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 5285a5ee94..79532d07b7 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,10 +6,10 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 50000; + int nData = 200000; // Open Env - ret = tdbEnvOpen("tdb", 1024, 2560, &pEnv); + ret = tdbEnvOpen("tdb", 1024, 25600, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database @@ -44,6 +44,9 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); } } + + { // Loop to query the data + } } ret = tdbDbDrop(pDb); From 347d1e6f9932ddbdfb2e2d352808cad6552b97df Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 09:03:01 +0000 Subject: [PATCH 072/149] start more fix --- source/libs/tdb/test/tdbTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 79532d07b7..cca2082e53 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,7 +6,7 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 200000; + int nData = 160511; // Open Env ret = tdbEnvOpen("tdb", 1024, 25600, &pEnv); From 61b2f52dca24dd7a7ba66b93194aabfa87704c57 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 09:53:34 +0000 Subject: [PATCH 073/149] now TDB can write 1M records --- source/libs/tdb/src/db/tdbBtree.c | 11 ++++++----- source/libs/tdb/test/tdbTest.cpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index eec75d3a13..e244b77f95 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -817,11 +817,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - for (int i = 0; i < 3; i++) { - if (pDivCell[i]) { - free(pDivCell[i]); - } - } + // TODO: here has memory leak + // for (int i = 0; i < 3; i++) { + // if (pDivCell[i]) { + // free(pDivCell[i]); + // } + // } return 0; } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index cca2082e53..0759de54b7 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,10 +6,10 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 160511; + int nData = 1000000; // Open Env - ret = tdbEnvOpen("tdb", 1024, 25600, &pEnv); + ret = tdbEnvOpen("tdb", 4096, 25600, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database From e20e13d2dbb9b3234db44b6539a918c6016dcd02 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 10:01:17 +0000 Subject: [PATCH 074/149] more TDB --- source/libs/tdb/test/tdbTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 0759de54b7..56284f0271 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,7 +6,7 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 1000000; + int nData = 2000000; // Open Env ret = tdbEnvOpen("tdb", 4096, 25600, &pEnv); From 488d44a55515152d0982b1a343591343830b4a9c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 24 Mar 2022 10:14:46 +0000 Subject: [PATCH 075/149] w/r 10M K-V pairs --- source/libs/tdb/test/tdbTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 56284f0271..df96a39943 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -6,10 +6,10 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; STDb *pDb; - int nData = 2000000; + int nData = 10000000; // Open Env - ret = tdbEnvOpen("tdb", 4096, 25600, &pEnv); + ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database From b8ac2d30d5b2658d2dc68560938b07ea55c71b5f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 01:42:03 +0000 Subject: [PATCH 076/149] refact --- source/libs/tdb/src/db/tdbBtree.c | 16 ++++++++-------- source/libs/tdb/src/db/tdbDb.c | 6 +++--- source/libs/tdb/src/inc/tdbBtree.h | 15 ++++++++++----- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index e244b77f95..befc021d28 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -67,7 +67,7 @@ typedef struct { u8 *pTmpSpace; } SCellDecoder; -static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *pCRst); +static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeZeroPage(SPage *pPage, void *arg); @@ -75,7 +75,7 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg); static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); -static int tdbBtreeBalance(SBtCursor *pCur); +static int tdbBtreeBalance(SBTC *pCur); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { @@ -131,7 +131,7 @@ int tdbBtreeClose(SBTree *pBt) { return 0; } -int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt) { +int tdbBtreeCursor(SBTC *pCur, SBTree *pBt) { pCur->pBt = pBt; pCur->iPage = -1; pCur->pPage = NULL; @@ -140,7 +140,7 @@ int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt) { return 0; } -int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen) { +int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen) { int ret; int idx; SPager *pPager; @@ -204,7 +204,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p } int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) { - SBtCursor btc; + SBTC btc; SCell *pCell; int cret; SCellDecoder cd; @@ -231,7 +231,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen return 0; } -static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) { +static int tdbBtCursorMoveToChild(SBTC *pCur, SPgno pgno) { int ret; pCur->pgStack[pCur->iPage] = pCur->pPage; @@ -248,7 +248,7 @@ static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) { return 0; } -static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *pCRst) { +static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) { int ret; SBTree *pBt; SPager *pPager; @@ -827,7 +827,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return 0; } -static int tdbBtreeBalance(SBtCursor *pCur) { +static int tdbBtreeBalance(SBTC *pCur) { int iPage; SPage *pParent; SPage *pPage; diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 2ba9daaa4a..9c5fb551f0 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -70,9 +70,9 @@ int tdbDbDrop(STDb *pDb) { } int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { - SBtCursor btc; - SBtCursor *pCur; - int ret; + SBTC btc; + SBTC *pCur; + int ret; pCur = &btc; ret = tdbBtreeCursor(pCur, pDb->pBt); diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index a0b054a6a8..60078f68f4 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -20,10 +20,15 @@ extern "C" { #endif -typedef struct SBTree SBTree; -typedef struct SBtCursor SBtCursor; +typedef struct SBTree SBTree; +typedef struct SBTC SBTC; +typedef struct SBtInfo { + SPgno root; + int nLevel; + int nData; +} SBtInfo; -struct SBtCursor { +struct SBTC { SBTree *pBt; i8 iPage; SPage *pPage; @@ -35,8 +40,8 @@ struct SBtCursor { int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt); int tdbBtreeClose(SBTree *pBt); -int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt); -int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen); +int tdbBtreeCursor(SBTC *pCur, SBTree *pBt); +int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen); int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); #ifdef __cplusplus From 6276f2c33e84e90d5b427a574b444a4413cfacc9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 01:48:35 +0000 Subject: [PATCH 077/149] refact --- source/libs/tdb/src/db/tdbDb.c | 16 ++++++++-------- source/libs/tdb/src/inc/tdbDb.h | 12 ++++++------ source/libs/tdb/src/inc/tdbInt.h | 2 +- source/libs/tdb/test/tdbTest.cpp | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 9c5fb551f0..e889e8772b 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -15,13 +15,13 @@ #include "tdbInt.h" -struct STDb { +struct STDB { STEnv *pEnv; SBTree *pBt; }; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) { - STDb *pDb; +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) { + STDB *pDb; SPager *pPager; int ret; char fFullName[TDB_FILENAME_LEN]; @@ -30,7 +30,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF *ppDb = NULL; - pDb = (STDb *)calloc(1, sizeof(*pDb)); + pDb = (STDB *)calloc(1, sizeof(*pDb)); if (pDb == NULL) { return -1; } @@ -59,17 +59,17 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF return 0; } -int tdbDbClose(STDb *pDb) { +int tdbDbClose(STDB *pDb) { // TODO return 0; } -int tdbDbDrop(STDb *pDb) { +int tdbDbDrop(STDB *pDb) { // TODO return 0; } -int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { +int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { SBTC btc; SBTC *pCur; int ret; @@ -88,6 +88,6 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v return 0; } -int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { +int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 7a65966be3..e48de5e8c7 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -20,14 +20,14 @@ extern "C" { #endif -typedef struct STDb STDb; +typedef struct STDB STDB; typedef struct STDbC STDbC; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb); -int tdbDbClose(STDb *pDb); -int tdbDbDrop(STDb *pDb); -int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); -int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb); +int tdbDbClose(STDB *pDb); +int tdbDbDrop(STDB *pDb); +int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); +int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 3ebba0a4b5..98845bb66f 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -95,7 +95,7 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { // tdb_log #define tdbError(var) -typedef TD_DLIST(STDb) STDbList; +typedef TD_DLIST(STDB) STDbList; typedef TD_DLIST(SPgFile) SPgFileList; typedef TD_DLIST_NODE(SPgFile) SPgFileListNode; diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index df96a39943..4f6bde3c96 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -5,7 +5,7 @@ TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; - STDb *pDb; + STDB *pDb; int nData = 10000000; // Open Env From 1cd404151aac734c9fcfcf96e0c04927dde4d0fe Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 25 Mar 2022 11:44:40 +0800 Subject: [PATCH 078/149] minor changes --- source/dnode/mgmt/container/inc/dndInt.h | 1 - source/dnode/mgmt/container/src/dndExec.c | 2 +- source/dnode/mgmt/container/src/dndFile.c | 28 +++++++++---------- source/dnode/mgmt/container/src/dndMsg.c | 11 ++++---- .../dnode/mgmt/container/src/dndTransport.c | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/source/dnode/mgmt/container/inc/dndInt.h b/source/dnode/mgmt/container/inc/dndInt.h index d10835b67f..8ea496b2fb 100644 --- a/source/dnode/mgmt/container/inc/dndInt.h +++ b/source/dnode/mgmt/container/inc/dndInt.h @@ -56,7 +56,6 @@ void dndCleanupServer(SDnode *pDnode); int32_t dndInitClient(SDnode *pDnode); void dndCleanupClient(SDnode *pDnode); int32_t dndInitMsgHandle(SDnode *pDnode); -void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 6d07ca1898..1355c4543a 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -138,7 +138,7 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t msgLen, void *pCont, int32_t contLen) { dTrace("msg:%p, get from parent queue", pRsp); pRsp->pCont = pCont; - dndSendRpcRsp(pWrapper, pRsp); + dndSendRsp(pWrapper, pRsp); free(pRsp); } diff --git a/source/dnode/mgmt/container/src/dndFile.c b/source/dnode/mgmt/container/src/dndFile.c index a5f8fb7169..ab04040b57 100644 --- a/source/dnode/mgmt/container/src/dndFile.c +++ b/source/dnode/mgmt/container/src/dndFile.c @@ -16,14 +16,16 @@ #define _DEFAULT_SOURCE #include "dndInt.h" +#define MAXLEN 1024 + int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { - int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; - int32_t len = 0; - int32_t maxLen = 1024; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - char file[PATH_MAX]; - TdFilePtr pFile = NULL; + int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR; + int32_t len = 0; + const int32_t maxLen = MAXLEN; + char content[MAXLEN + 1] = {0}; + cJSON *root = NULL; + char file[PATH_MAX]; + TdFilePtr pFile = NULL; snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); pFile = taosOpenFile(file, TD_FILE_READ); @@ -57,7 +59,6 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); _OVER: - if (content != NULL) free(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); @@ -66,7 +67,7 @@ _OVER: } int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); @@ -76,9 +77,9 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { return -1; } - int32_t len = 0; - int32_t maxLen = 1024; - char *content = calloc(1, maxLen + 1); + int32_t len = 0; + const int32_t maxLen = MAXLEN; + char content[MAXLEN + 1] = {0}; len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); @@ -87,9 +88,8 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { taosWriteFile(pFile, content, len); taosFsyncFile(pFile); taosCloseFile(&pFile); - free(content); - char realfile[PATH_MAX]; + char realfile[PATH_MAX] = {0}; snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); if (taosRenameFile(file, realfile) != 0) { diff --git a/source/dnode/mgmt/container/src/dndMsg.c b/source/dnode/mgmt/container/src/dndMsg.c index 37ff4ebc05..bf3200ffaf 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/container/src/dndMsg.c @@ -43,19 +43,18 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); memcpy(&pMsg->rpcMsg, pRpc, sizeof(SRpcMsg)); - return 0; } void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { - if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) { - dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); - } - int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; + if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) { + dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); + } + if (dndMarkWrapper(pWrapper) != 0) goto _OVER; if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER; if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER; @@ -67,6 +66,8 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { } else if (pWrapper->procType == PROC_PARENT) { code = taosProcPutToChildQueue(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen); } else { + dFatal(" should not be entered in child processes"); + ASSERT(1); } _OVER: diff --git a/source/dnode/mgmt/container/src/dndTransport.c b/source/dnode/mgmt/container/src/dndTransport.c index 4acb1f459e..b7d0cf26c0 100644 --- a/source/dnode/mgmt/container/src/dndTransport.c +++ b/source/dnode/mgmt/container/src/dndTransport.c @@ -348,7 +348,7 @@ int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) { } } -void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) { +static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) { if (pRsp->code == TSDB_CODE_APP_NOT_READY) { SMgmtWrapper *pDnodeWrapper = dndAcquireWrapper(pWrapper->pDnode, DNODE); if (pDnodeWrapper != NULL) { From 212e24dda649b879decfd7bf20c0bb03c7065475 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 04:59:20 +0000 Subject: [PATCH 079/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 1 + source/libs/tdb/test/tdbTest.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index befc021d28..c3adf7d2b6 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -914,6 +914,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, i return 0; } +// TODO: allow vLen = 0 static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell) { u8 flags; diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 4f6bde3c96..05a0f3a6ae 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -17,10 +17,8 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(ret, 0); { - char key[64]; - char val[64]; - void *pVal = NULL; - int vLen; + char key[64]; + char val[64]; { // Insert some data @@ -33,6 +31,9 @@ TEST(tdb_test, simple_test) { } { // Query the data + void *pVal = NULL; + int vLen; + for (int i = 1; i <= nData; i++) { sprintf(key, "key%d", i); sprintf(val, "value%d", i); @@ -46,6 +47,8 @@ TEST(tdb_test, simple_test) { } { // Loop to query the data + // STDbC *pDBC; + // tdbDBNext(pDBC, p) } } From f4359a6fb3c82295ac5b8b752e2804b7dd19ad84 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 06:02:38 +0000 Subject: [PATCH 080/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 7 ++++--- source/libs/tdb/src/inc/tdbUtil.h | 22 ++++++++++++++++++++++ source/libs/tdb/test/tdbTest.cpp | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index c3adf7d2b6..0ef5d64d30 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -207,6 +207,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen SBTC btc; SCell *pCell; int cret; + void *pVal; SCellDecoder cd; tdbBtreeCursor(&btc, pBt); @@ -221,12 +222,12 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen tdbBtreeDecodeCell(btc.pPage, pCell, &cd); *vLen = cd.vLen; - // TODO: here may have memory leak - *ppVal = realloc(*ppVal, *vLen); - if (*ppVal == NULL) { + pVal = TDB_REALLOC(*ppVal, *vLen); + if (pVal == NULL) { return -1; } + *ppVal = pVal; memcpy(*ppVal, cd.pVal, cd.vLen); return 0; } diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 9358aae236..88fc846bf1 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -39,6 +39,28 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); int tdbPRead(int fd, void *pData, int count, i64 offset); +#define TDB_REALLOC(PTR, SIZE) \ + ({ \ + void *nPtr; \ + if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \ + nPtr = realloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \ + if (nPtr) { \ + ((int *)nPtr)[0] = (SIZE); \ + nPtr = (char *)nPtr + sizeof(int); \ + } \ + } else { \ + nPtr = (PTR); \ + } \ + nPtr; \ + }) + +#define TDB_FREE(PTR) \ + do { \ + if (PTR) { \ + free((char *)(PTR) - sizeof(int)); \ + } \ + } while (0) + static inline void *tdbOsMalloc(void *arg, size_t size) { void *ptr; diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 05a0f3a6ae..46437392cd 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -44,6 +44,8 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(vLen, strlen(val)); GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); } + + TDB_FREE(pVal); } { // Loop to query the data From 9ffdf09986e1ee511d12b97e4e39531ef63fa9df Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 06:15:21 +0000 Subject: [PATCH 081/149] design dbc api --- source/libs/tdb/src/db/tdbDb.c | 15 +++++++++++++++ source/libs/tdb/src/inc/tdbDb.h | 8 +++++++- source/libs/tdb/test/tdbTest.cpp | 25 ++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index e889e8772b..98f22e4d25 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -90,4 +90,19 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); +} + +int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc) { + // TODO + return 0; +} + +int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + // TODO + return 0; +} + +int tdbDbcClose(STDBC *pDbc) { + // TODO + return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index e48de5e8c7..4e69de2bfa 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -21,14 +21,20 @@ extern "C" { #endif typedef struct STDB STDB; -typedef struct STDbC STDbC; +typedef struct STDBC STDBC; +// STDB int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb); int tdbDbClose(STDB *pDb); int tdbDbDrop(STDB *pDb); int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); +// STDBC +int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc); +int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbDbcClose(STDBC *pDbc); + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 46437392cd..164b2c0b83 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -48,9 +48,28 @@ TEST(tdb_test, simple_test) { TDB_FREE(pVal); } - { // Loop to query the data - // STDbC *pDBC; - // tdbDBNext(pDBC, p) + { // Iterate to query the DB data + STDBC *pDBC; + void *pKey = NULL; + void *pVal = NULL; + int vLen, kLen; + int count = 0; + + ret = tdbDbcOpen(pDb, &pDBC); + GTEST_ASSERT_EQ(ret, 0); + + for (;;) { + ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen); + if (ret < 0) break; + count++; + } + + GTEST_ASSERT_EQ(count, nData); + + tdbDbcClose(pDBC); + + TDB_FREE(pKey); + TDB_FREE(pVal); } } From cc176b1037ebed74221b6f6d99f63775d2f80987 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 06:42:42 +0000 Subject: [PATCH 082/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 29 +++++++++++++++++++++-- source/libs/tdb/src/db/tdbDb.c | 37 +++++++++++++++++++++++++----- source/libs/tdb/src/inc/tdbBtree.h | 10 +++++++- source/libs/tdb/src/inc/tdbDb.h | 2 +- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0ef5d64d30..2b0ba62ed3 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -131,7 +131,7 @@ int tdbBtreeClose(SBTree *pBt) { return 0; } -int tdbBtreeCursor(SBTC *pCur, SBTree *pBt) { +int tdbBtcOpen(SBTC *pCur, SBTree *pBt) { pCur->pBt = pBt; pCur->iPage = -1; pCur->pPage = NULL; @@ -210,7 +210,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen void *pVal; SCellDecoder cd; - tdbBtreeCursor(&btc, pBt); + tdbBtcOpen(&btc, pBt); tdbBtCursorMoveTo(&btc, pKey, kLen, &cret); @@ -1072,3 +1072,28 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { } #endif + +int tdbBtcMoveToFirst(SBTC *pBtc) { + // TODO + return 0; +} + +int tdbBtcMoveToLast(SBTC *pBtc) { + // TODO + return 0; +} + +int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen) { + // TODO + return 0; +} + +int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + // TODO + return 0; +} + +int tdbBtcClose(SBTC *pBtc) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 98f22e4d25..4e74dc4cbb 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -20,6 +20,10 @@ struct STDB { SBTree *pBt; }; +struct STDBC { + SBTC btc; +}; + int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) { STDB *pDb; SPager *pPager; @@ -75,7 +79,7 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v int ret; pCur = &btc; - ret = tdbBtreeCursor(pCur, pDb->pBt); + ret = tdbBtcOpen(pCur, pDb->pBt); if (ret < 0) { return -1; } @@ -92,17 +96,38 @@ int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); } -int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc) { - // TODO +int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { + int ret; + STDBC *pDbc = NULL; + + *ppDbc = NULL; + pDbc = malloc(sizeof(*pDbc)); + if (pDbc == NULL) { + return -1; + } + + tdbBtcOpen(&pDbc->btc, pDb->pBt); + + // TODO: move to first now, we can move to any key-value + // and in any direction, design new APIs. + ret = tdbBtcMoveToFirst(&pDbc->btc); + if (ret < 0) { + ASSERT(0); + return -1; + } + + *ppDbc = pDbc; return 0; } int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { - // TODO - return 0; + return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen); } int tdbDbcClose(STDBC *pDbc) { - // TODO + if (pDbc) { + free(pDbc); + } + return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index 60078f68f4..e46e8bb78b 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -38,12 +38,20 @@ struct SBTC { void *pBuf; }; +// SBTree int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt); int tdbBtreeClose(SBTree *pBt); -int tdbBtreeCursor(SBTC *pCur, SBTree *pBt); int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen); int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); +// SBTC +int tdbBtcOpen(SBTC *pCur, SBTree *pBt); +int tdbBtcMoveToFirst(SBTC *pBtc); +int tdbBtcMoveToLast(SBTC *pBtc); +int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen); +int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbBtcClose(SBTC *pBtc); + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 4e69de2bfa..b96076b826 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -31,7 +31,7 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); // STDBC -int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc); +int tdbDbcOpen(STDB *pDb, STDBC **ppDbc); int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbDbcClose(STDBC *pDbc); From 07f6d03a5246aaced36ee3272c6852f703779871 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 07:19:48 +0000 Subject: [PATCH 083/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 107 +++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 11 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 2b0ba62ed3..7d925d69f4 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -131,15 +131,6 @@ int tdbBtreeClose(SBTree *pBt) { return 0; } -int tdbBtcOpen(SBTC *pCur, SBTree *pBt) { - pCur->pBt = pBt; - pCur->iPage = -1; - pCur->pPage = NULL; - pCur->idx = -1; - - return 0; -} - int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen) { int ret; int idx; @@ -1073,13 +1064,107 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { #endif +int tdbBtcOpen(SBTC *pCur, SBTree *pBt) { + pCur->pBt = pBt; + pCur->iPage = -1; + pCur->pPage = NULL; + pCur->idx = -1; + + return 0; +} + int tdbBtcMoveToFirst(SBTC *pBtc) { - // TODO + int ret; + SBTree *pBt; + SPager *pPager; + u8 flags; + SCell *pCell; + SPgno pgno; + + pBt = pBtc->pBt; + pPager = pBt->pPager; + + if (pBtc->iPage < 0) { + // move a clean cursor + ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); + if (ret < 0) { + ASSERT(0); + return -1; + } + + pBtc->iPage = 0; + pBtc->idx = 0; + } else { + // move from a position + ASSERT(0); + } + + // move downward + for (;;) { + flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); + + if (TDB_BTREE_PAGE_IS_LEAF(flags)) break; + + pCell = tdbPageGetCell(pBtc->pPage, 0); + pgno = *(SPgno *)pCell; + + ret = tdbBtCursorMoveToChild(pBtc, pgno); + if (ret < 0) { + ASSERT(0); + return -1; + } + + pBtc->idx = 0; + } + return 0; } int tdbBtcMoveToLast(SBTC *pBtc) { - // TODO + int ret; + SBTree *pBt; + SPager *pPager; + u8 flags; + SPgno pgno; + + pBt = pBtc->pBt; + pPager = pBt->pPager; + + if (pBtc->iPage < 0) { + // move a clean cursor + ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); + if (ret < 0) { + ASSERT(0); + return -1; + } + + pBtc->iPage = 0; + } else { + // move from a position + ASSERT(0); + } + + // move downward + for (;;) { + flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); + + if (TDB_BTREE_PAGE_IS_LEAF(flags)) { + // TODO: handle empty case + ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) > 0); + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; + break; + } else { + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; + + ret = tdbBtCursorMoveToChild(pBtc, pgno); + if (ret < 0) { + ASSERT(0); + return -1; + } + } + } + return 0; } From f75cb898663afc37a7c45b964d4b16e462c8d663 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 07:37:41 +0000 Subject: [PATCH 084/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 63 ++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 7d925d69f4..8c86c576c2 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -77,6 +77,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); static int tdbBtreeBalance(SBTC *pCur); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); +static int tdbBtcMoveToNext(SBTC *pBtc); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { SBTree *pBt; @@ -1174,7 +1175,67 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen) { } int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { - // TODO + SCell *pCell; + SCellDecoder cd; + void *pKey, *pVal; + int ret; + + if (0) { + // TODO: no valid data current cursor is pointing to + return -1; + } + + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + + tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd); + + pKey = TDB_REALLOC(*ppKey, cd.kLen); + if (pKey == NULL) { + return -1; + } + + // TODO: vLen may be zero + pVal = TDB_REALLOC(*ppVal, cd.vLen); + if (pVal == NULL) { + TDB_FREE(pKey); + return -1; + } + + *ppKey = pKey; + *ppVal = pVal; + + *kLen = cd.kLen; + *vLen = cd.vLen; + + memcpy(pKey, cd.pKey, cd.kLen); + memcpy(pVal, cd.pVal, cd.vLen); + + ret = tdbBtcMoveToNext(pBtc); + + return 0; +} + +static int tdbBtcMoveToNext(SBTC *pBtc) { + pBtc->idx++; + + if (pBtc->idx < 0) return -1; + + if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { + return 0; + } + + // Move upward + for (;;) { + // TODO: release the page + + /* code */ + } + + // Move downward + for (;;) { + /* code */ + } + return 0; } From af98aa400509287f1f196754f69186bbd0bf582b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 07:48:55 +0000 Subject: [PATCH 085/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 51 ++++++++++++++++------------- source/libs/tdb/src/db/tdbPCache.c | 47 ++++++++++---------------- source/libs/tdb/src/db/tdbPager.c | 4 +++ source/libs/tdb/src/inc/tdbPCache.h | 25 +++++++------- source/libs/tdb/src/inc/tdbPager.h | 19 ++++++----- 5 files changed, 73 insertions(+), 73 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 8c86c576c2..282c5a98a6 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -78,6 +78,8 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD static int tdbBtreeBalance(SBTC *pCur); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); static int tdbBtcMoveToNext(SBTC *pBtc); +static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno); +static int tdbBtcMoveUpward(SBTC *pBtc); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { SBTree *pBt; @@ -224,23 +226,6 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen return 0; } -static int tdbBtCursorMoveToChild(SBTC *pCur, SPgno pgno) { - int ret; - - pCur->pgStack[pCur->iPage] = pCur->pPage; - pCur->idxStack[pCur->iPage] = pCur->idx; - pCur->iPage++; - pCur->pPage = NULL; - pCur->idx = -1; - - ret = tdbPagerFetchPage(pCur->pBt->pPager, pgno, &pCur->pPage, tdbBtreeInitPage, pCur->pBt); - if (ret < 0) { - ASSERT(0); - } - - return 0; -} - static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) { int ret; SBTree *pBt; @@ -318,16 +303,16 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) } else { if (c <= 0) { pCur->idx = midx; - tdbBtCursorMoveToChild(pCur, cd.pgno); + tdbBtcMoveDownward(pCur, cd.pgno); } else { pCur->idx = midx + 1; if (midx == nCells - 1) { /* Move to right-most child */ - tdbBtCursorMoveToChild(pCur, ((SIntHdr *)pCur->pPage->pData)->pgno); + tdbBtcMoveDownward(pCur, ((SIntHdr *)pCur->pPage->pData)->pgno); } else { pCell = tdbPageGetCell(pPage, pCur->idx); tdbBtreeDecodeCell(pPage, pCell, &cd); - tdbBtCursorMoveToChild(pCur, cd.pgno); + tdbBtcMoveDownward(pCur, cd.pgno); } } } @@ -1109,7 +1094,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { pCell = tdbPageGetCell(pBtc->pPage, 0); pgno = *(SPgno *)pCell; - ret = tdbBtCursorMoveToChild(pBtc, pgno); + ret = tdbBtcMoveDownward(pBtc, pgno); if (ret < 0) { ASSERT(0); return -1; @@ -1158,7 +1143,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) { pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; - ret = tdbBtCursorMoveToChild(pBtc, pgno); + ret = tdbBtcMoveDownward(pBtc, pgno); if (ret < 0) { ASSERT(0); return -1; @@ -1242,4 +1227,26 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { int tdbBtcClose(SBTC *pBtc) { // TODO return 0; +} + +static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno) { + int ret; + + pCur->pgStack[pCur->iPage] = pCur->pPage; + pCur->idxStack[pCur->iPage] = pCur->idx; + pCur->iPage++; + pCur->pPage = NULL; + pCur->idx = -1; + + ret = tdbPagerFetchPage(pCur->pBt->pPager, pgno, &pCur->pPage, tdbBtreeInitPage, pCur->pBt); + if (ret < 0) { + ASSERT(0); + } + + return 0; +} + +static int tdbBtcMoveUpward(SBTC *pBtc) { + // TODO + return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 1fc0847b38..3c7d037faa 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -53,10 +53,10 @@ static void tdbPCacheLock(SPCache *pCache); static void tdbPCacheUnlock(SPCache *pCache); static bool tdbPCacheLocked(SPCache *pCache); static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); -static void tdbPCachePinPage(SPage *pPage); -static void tdbPCacheRemovePageFromHash(SPage *pPage); -static void tdbPCacheAddPageToHash(SPage *pPage); -static void tdbPCacheUnpinPage(SPage *pPage); +static void tdbPCachePinPage(SPCache *pCache, SPage *pPage); +static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage); +static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage); +static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage); int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { SPCache *pCache; @@ -100,7 +100,7 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) { return pPage; } -void tdbPCacheRelease(SPage *pPage) { +void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { i32 nRef; nRef = TDB_UNREF_PAGE(pPage); @@ -108,7 +108,7 @@ void tdbPCacheRelease(SPage *pPage) { if (nRef == 0) { if (1 /*TODO: page still clean*/) { - tdbPCacheUnpinPage(pPage); + tdbPCacheUnpinPage(pCache, pPage); } else { // TODO ASSERT(0); @@ -142,7 +142,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe if (pPage || !alcNewPage) { if (pPage) { - tdbPCachePinPage(pPage); + tdbPCachePinPage(pCache, pPage); } return pPage; } @@ -158,8 +158,8 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe // 3. Try to Recycle a page if (!pPage && !pCache->lru.pLruPrev->isAnchor) { pPage = pCache->lru.pLruPrev; - tdbPCacheRemovePageFromHash(pPage); - tdbPCachePinPage(pPage); + tdbPCacheRemovePageFromHash(pCache, pPage); + tdbPCachePinPage(pCache, pPage); } // 4. Try a stress allocation (TODO) @@ -171,16 +171,13 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe memcpy(&(pPage->pgid), pPgid, sizeof(*pPgid)); pPage->pLruNext = NULL; pPage->pPager = NULL; - tdbPCacheAddPageToHash(pPage); + tdbPCacheAddPageToHash(pCache, pPage); } return pPage; } -static void tdbPCachePinPage(SPage *pPage) { - SPCache *pCache; - - pCache = pPage->pCache; +static void tdbPCachePinPage(SPCache *pCache, SPage *pPage) { if (!PAGE_IS_PINNED(pPage)) { pPage->pLruPrev->pLruNext = pPage->pLruNext; pPage->pLruNext->pLruPrev = pPage->pLruPrev; @@ -190,11 +187,8 @@ static void tdbPCachePinPage(SPage *pPage) { } } -static void tdbPCacheUnpinPage(SPage *pPage) { - SPCache *pCache; - i32 nRef; - - pCache = pPage->pCache; +static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { + i32 nRef; tdbPCacheLock(pCache); @@ -215,12 +209,10 @@ static void tdbPCacheUnpinPage(SPage *pPage) { tdbPCacheUnlock(pCache); } -static void tdbPCacheRemovePageFromHash(SPage *pPage) { - SPCache *pCache; - SPage **ppPage; - int h; +static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) { + SPage **ppPage; + int h; - pCache = pPage->pCache; h = PCACHE_PAGE_HASH(&(pPage->pgid)); for (ppPage = &(pCache->pgHash[h % pCache->nHash]); *ppPage != pPage; ppPage = &((*ppPage)->pHashNext)) ; @@ -230,11 +222,9 @@ static void tdbPCacheRemovePageFromHash(SPage *pPage) { pCache->nPage--; } -static void tdbPCacheAddPageToHash(SPage *pPage) { - SPCache *pCache; - int h; +static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) { + int h; - pCache = pPage->pCache; h = PCACHE_PAGE_HASH(&(pPage->pgid)) % pCache->nHash; pPage->pHashNext = pCache->pgHash[h]; @@ -264,7 +254,6 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { // pPage->pgid = 0; pPage->isAnchor = 0; pPage->isLocalPage = 1; - pPage->pCache = pCache; TDB_INIT_PAGE_REF(pPage); pPage->pHashNext = NULL; pPage->pLruNext = NULL; diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index ac0bc15e1d..fe4b9aa123 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -255,6 +255,10 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage return 0; } +void tdbPagerReturnPage(SPager *pPager, SPage *pPage) { + tdbPCacheRelease(pPager->pCache, pPage); +} + static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) { // TODO: Allocate a page from the free list return 0; diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h index ff4f1acbb6..c7fa155615 100644 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ b/source/libs/tdb/src/inc/tdbPCache.h @@ -21,23 +21,22 @@ extern "C" { #endif #define TDB_PCACHE_PAGE \ - u8 isAnchor; \ - u8 isLocalPage; \ - u8 isDirty; \ - i32 nRef; \ - SPCache *pCache; \ - SPage *pFreeNext; \ - SPage *pHashNext; \ - SPage *pLruNext; \ - SPage *pLruPrev; \ - SPage *pDirtyNext; \ - SPager *pPager; \ - SPgid pgid; + u8 isAnchor; \ + u8 isLocalPage; \ + u8 isDirty; \ + i32 nRef; \ + SPage *pFreeNext; \ + SPage *pHashNext; \ + SPage *pLruNext; \ + SPage *pLruPrev; \ + SPage *pDirtyNext; \ + SPager *pPager; \ + SPgid pgid; int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache); int tdbPCacheClose(SPCache *pCache); SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage); -void tdbPCacheRelease(SPage *pPage); +void tdbPCacheRelease(SPCache *pCache, SPage *pPage); int tdbPCacheGetPageSize(SPCache *pCache); #ifdef __cplusplus diff --git a/source/libs/tdb/src/inc/tdbPager.h b/source/libs/tdb/src/inc/tdbPager.h index e4ed8552fd..f4cc822f27 100644 --- a/source/libs/tdb/src/inc/tdbPager.h +++ b/source/libs/tdb/src/inc/tdbPager.h @@ -20,15 +20,16 @@ extern "C" { #endif -int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager); -int tdbPagerClose(SPager *pPager); -int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); -int tdbPagerWrite(SPager *pPager, SPage *pPage); -int tdbPagerBegin(SPager *pPager); -int tdbPagerCommit(SPager *pPager); -int tdbPagerGetPageSize(SPager *pPager); -int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); -int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); +int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager); +int tdbPagerClose(SPager *pPager); +int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); +int tdbPagerWrite(SPager *pPager, SPage *pPage); +int tdbPagerBegin(SPager *pPager); +int tdbPagerCommit(SPager *pPager); +int tdbPagerGetPageSize(SPager *pPager); +int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); +int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg); +void tdbPagerReturnPage(SPager *pPager, SPage *pPage); #ifdef __cplusplus } From b6c6a11972d01c80c8d57a77b8f5e7610022885f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 25 Mar 2022 16:10:01 +0800 Subject: [PATCH 086/149] minor changes --- source/dnode/mgmt/container/src/dndMsg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/dnode/mgmt/container/src/dndMsg.c b/source/dnode/mgmt/container/src/dndMsg.c index bf3200ffaf..b72d085861 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/container/src/dndMsg.c @@ -60,20 +60,23 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER; if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER; - dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); if (pWrapper->procType == PROC_SINGLE) { + dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); code = (*msgFp)(pWrapper->pMgmt, pMsg); } else if (pWrapper->procType == PROC_PARENT) { + dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, + pRpc->ahandle, pMsg->user); code = taosProcPutToChildQueue(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen); } else { - dFatal(" should not be entered in child processes"); + dTrace("msg:%p, should not processed in child process, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, + pMsg->user); ASSERT(1); } _OVER: if (code == 0) { if (pWrapper->procType == PROC_PARENT) { - dTrace("msg:%p, is freed", pMsg); + dTrace("msg:%p, is freed in parent process", pMsg); taosFreeQitem(pMsg); rpcFreeCont(pRpc->pCont); } From cbc8720d293a05ecb3fec048c45bd62d8f470b72 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 08:35:40 +0000 Subject: [PATCH 087/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 51 ++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 282c5a98a6..d135eedb7c 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1201,24 +1201,58 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { } static int tdbBtcMoveToNext(SBTC *pBtc) { - pBtc->idx++; + int nCells; + SPgno pgno; + SCell *pCell; + u8 flags; + + ASSERT(TDB_BTREE_PAGE_IS_LEAF(TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage))); if (pBtc->idx < 0) return -1; + pBtc->idx++; if (pBtc->idx < TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { return 0; } + if (pBtc->iPage == 0) { + pBtc->idx = -1; + return 0; + } + // Move upward for (;;) { - // TODO: release the page + tdbBtcMoveUpward(pBtc); + pBtc->idx++; - /* code */ + nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + if (pBtc->idx <= nCells) { + break; + } + + if (pBtc->iPage == 0) { + pBtc->idx = -1; + return 0; + } } // Move downward for (;;) { - /* code */ + nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + if (pBtc->idx < nCells) { + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + pgno = *(SPgno *)pCell; + } else { + pgno = ((SIntHdr *)pBtc->pPage->pData)->pgno; + } + + tdbBtcMoveDownward(pBtc, pgno); + pBtc->idx = 0; + + flags = TDB_BTREE_PAGE_GET_FLAGS(pBtc->pPage); + if (TDB_BTREE_PAGE_IS_LEAF(flags)) { + break; + } } return 0; @@ -1247,6 +1281,13 @@ static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno) { } static int tdbBtcMoveUpward(SBTC *pBtc) { - // TODO + if (pBtc->iPage == 0) return -1; + + // tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + + pBtc->iPage--; + pBtc->pPage = pBtc->pgStack[pBtc->iPage]; + pBtc->idx = pBtc->idxStack[pBtc->iPage]; + return 0; } \ No newline at end of file From a9acfce8860d6174a734262e010f8108b469b406 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 08:41:00 +0000 Subject: [PATCH 088/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index d135eedb7c..de77fb2649 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1165,8 +1165,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { void *pKey, *pVal; int ret; - if (0) { - // TODO: no valid data current cursor is pointing to + if (pBtc->idx < 0) { return -1; } From f47953797845ae9d17548ef457cee4cb40b3e57f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 09:01:09 +0000 Subject: [PATCH 089/149] more --- source/libs/tdb/test/tdbTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 164b2c0b83..b9ae2dff7d 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -2,6 +2,8 @@ #include "tdbInt.h" +static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); + TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; @@ -61,6 +63,11 @@ TEST(tdb_test, simple_test) { for (;;) { ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen); if (ret < 0) break; + + // std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " "; + // std::cout.write((char *)pVal, vLen) /* << " " << vLen */; + // std::cout << std::endl; + count++; } @@ -82,4 +89,19 @@ TEST(tdb_test, simple_test) { // Close Env ret = tdbEnvClose(pEnv); GTEST_ASSERT_EQ(ret, 0); +} + +static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + int k1, k2; + + k1 = std::strtol((char *)pKey1 + 3, nullptr, kLen1 - 3); + k2 = std::strtol((char *)pKey2 + 3, nullptr, kLen2 - 3); + + if (k1 < k2) { + return -1; + } else if (k1 > k2) { + return 1; + } else { + return 0; + } } \ No newline at end of file From 474939ee4976ec4f8ec538d124363fd0e8cec61b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 25 Mar 2022 17:28:38 +0800 Subject: [PATCH 090/149] shm --- source/dnode/mgmt/container/src/dndExec.c | 1 - source/util/src/tprocess.c | 78 +++++++++++------------ 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 1355c4543a..4dcf7e80ec 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -178,7 +178,6 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { .parentFreeHeadFp = (ProcFreeFp)free, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .testFlag = 0, .pParent = pWrapper, .name = pWrapper->name}; SProcObj *pProc = taosProcInit(&cfg); diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f19a17fdb6..24f3f8a6e4 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -56,7 +56,6 @@ typedef struct SProcObj { int32_t pid; bool isChild; bool stopFlag; - bool testFlag; } SProcObj; static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { @@ -77,7 +76,7 @@ static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { goto _OVER; } - shmid = shmget(IPC_PRIVATE, sizeof(TdThreadMutex), 0600); + shmid = shmget(IPC_PRIVATE, sizeof(TdThreadMutex), IPC_CREAT | 0600); if (shmid <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to init mutex while shmget since %s", terrstr()); @@ -101,8 +100,13 @@ static int32_t taosProcInitMutex(TdThreadMutex **ppMutex, int32_t *pShmid) { _OVER: if (code != 0) { - taosThreadMutexDestroy(pMutex); - shmctl(shmid, IPC_RMID, NULL); + if (pMutex != NULL) { + taosThreadMutexDestroy(pMutex); + shmdt(pMutex); + } + if (shmid >= 0) { + shmctl(shmid, IPC_RMID, NULL); + } } else { *ppMutex = pMutex; *pShmid = shmid; @@ -112,12 +116,12 @@ _OVER: return code; } -static void taosProcDestroyMutex(TdThreadMutex *pMutex, int32_t *pShmid) { +static void taosProcDestroyMutex(TdThreadMutex *pMutex, int32_t shmid) { if (pMutex != NULL) { taosThreadMutexDestroy(pMutex); } - if (*pShmid > 0) { - shmctl(*pShmid, IPC_RMID, NULL); + if (shmid >= 0) { + shmctl(shmid, IPC_RMID, NULL); } } @@ -141,9 +145,10 @@ static int32_t taosProcInitBuffer(void **ppBuffer, int32_t size) { return shmid; } -static void taosProcDestroyBuffer(void *pBuffer, int32_t *pShmid) { - if (*pShmid > 0) { - shmctl(*pShmid, IPC_RMID, NULL); +static void taosProcDestroyBuffer(void *pBuffer, int32_t shmid) { + if (shmid > 0) { + shmdt(pBuffer); + shmctl(shmid, IPC_RMID, NULL); } } @@ -155,29 +160,28 @@ static SProcQueue *taosProcQueueInit(int32_t size) { SProcQueue *pQueue = NULL; int32_t shmId = taosProcInitBuffer((void **)&pQueue, bufSize + headSize); - if (shmId <= 0) { + if (shmId < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - pQueue->bufferShmid = shmId; if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { - free(pQueue); + taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); return NULL; } if (tsem_init(&pQueue->sem, 1, 0) != 0) { - taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); - free(pQueue); + taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); + taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } if (taosProcInitMutex(&pQueue->mutex, &pQueue->mutexShmid) != 0) { - taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); tsem_destroy(&pQueue->sem); - free(pQueue); + taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); + taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); return NULL; } @@ -190,12 +194,12 @@ static SProcQueue *taosProcQueueInit(int32_t size) { return pQueue; } -static void taosProcQueueCleanup(SProcQueue *pQueue) { +static void taosProcCleanupQueue(SProcQueue *pQueue) { if (pQueue != NULL) { uDebug("proc:%s, queue:%p clean up", pQueue->name, pQueue); - taosProcDestroyMutex(pQueue->mutex, &pQueue->mutexShmid); tsem_destroy(&pQueue->sem); - free(pQueue); + taosProcDestroyMutex(pQueue->mutex, pQueue->mutexShmid); + taosProcDestroyBuffer(pQueue, pQueue->bufferShmid); } } @@ -344,12 +348,10 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { } pProc->name = pCfg->name; - pProc->testFlag = pCfg->testFlag; - pProc->pChildQueue = taosProcQueueInit(pCfg->childQueueSize); pProc->pParentQueue = taosProcQueueInit(pCfg->parentQueueSize); if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { - taosProcQueueCleanup(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pChildQueue); free(pProc); return NULL; } @@ -369,17 +371,15 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pParentQueue->freeBodyFp = pCfg->parentFreeBodyFp; pProc->pParentQueue->consumeFp = pCfg->parentConsumeFp; - uDebug("proc:%s, initialized, child queue:%p parent queue:%p", pProc->name, pProc->pChildQueue, pProc->pParentQueue); + uDebug("proc:%s, is initialized, child queue:%p parent queue:%p", pProc->name, pProc->pChildQueue, pProc->pParentQueue); - if (!pProc->testFlag) { - pProc->pid = fork(); - if (pProc->pid == 0) { - pProc->isChild = 1; - uInfo("this is child process, pid:%d", pProc->pid); - } else { - pProc->isChild = 0; - uInfo("this is parent process, pid:%d", pProc->pid); - } + pProc->pid = fork(); + if (pProc->pid == 0) { + pProc->isChild = 1; + uInfo("this is child process, pid:%d", pProc->pid); + } else { + pProc->isChild = 0; + uInfo("this is parent process, child pid:%d", pProc->pid); } return pProc; @@ -398,7 +398,7 @@ static void taosProcThreadLoop(SProcQueue *pQueue) { if (code < 0) { uDebug("proc:%s, get no message from queue:%p and exiting", pQueue->name, pQueue); break; - } else if (code < 0) { + } else if (code == 0) { uTrace("proc:%s, get no message from queue:%p since %s", pQueue->name, pQueue, terrstr()); taosMsleep(1); continue; @@ -413,16 +413,14 @@ int32_t taosProcRun(SProcObj *pProc) { taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - if (pProc->isChild || pProc->testFlag) { + if (pProc->isChild) { if (taosThreadCreate(&pProc->childThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pChildQueue) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to create thread since %s", terrstr()); return -1; } uDebug("proc:%s, child start to consume queue:%p", pProc->name, pProc->pChildQueue); - } - - if (!pProc->isChild || pProc->testFlag) { + } else { if (taosThreadCreate(&pProc->parentThread, &thAttr, (ProcThreadFp)taosProcThreadLoop, pProc->pParentQueue) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); uError("failed to create thread since %s", terrstr()); @@ -445,8 +443,8 @@ void taosProcCleanup(SProcObj *pProc) { if (pProc != NULL) { uDebug("proc:%s, clean up", pProc->name); taosProcStop(pProc); - taosProcQueueCleanup(pProc->pChildQueue); - taosProcQueueCleanup(pProc->pParentQueue); + taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pParentQueue); free(pProc); } } From 4ea8c88810ed1f578f7817e483fd2a7b0751513a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 09:30:07 +0000 Subject: [PATCH 091/149] more TDB --- source/libs/tdb/test/tdbTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index b9ae2dff7d..4c7af58b14 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -15,7 +15,7 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(ret, 0); // Create a database - ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb); + ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, tKeyCmpr, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); { @@ -94,8 +94,8 @@ TEST(tdb_test, simple_test) { static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { int k1, k2; - k1 = std::strtol((char *)pKey1 + 3, nullptr, kLen1 - 3); - k2 = std::strtol((char *)pKey2 + 3, nullptr, kLen2 - 3); + k1 = std::strtol((char *)pKey1 + 3, nullptr, 10); + k2 = std::strtol((char *)pKey2 + 3, nullptr, 10); if (k1 < k2) { return -1; From d7e13ef739236875e63b368dfabd7afe826d4228 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 25 Mar 2022 18:22:59 +0800 Subject: [PATCH 092/149] shm --- include/util/tprocess.h | 1 + source/dnode/mgmt/container/src/dndExec.c | 25 ++++++++++++++--------- source/dnode/mgmt/container/src/dndObj.c | 2 +- source/util/src/tprocess.c | 10 +++++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/util/tprocess.h b/include/util/tprocess.h index 4ce536fd96..a0be38a3ad 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -51,6 +51,7 @@ void taosProcCleanup(SProcObj *pProc); int32_t taosProcRun(SProcObj *pProc); void taosProcStop(SProcObj *pProc); bool taosProcIsChild(SProcObj *pProc); +int32_t taosProcChildId(SProcObj *pProc); int32_t taosProcPutToChildQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen); int32_t taosProcPutToParentQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen); diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 4dcf7e80ec..a6c9852546 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -20,7 +20,7 @@ static void dndResetLog(SMgmtWrapper *pMgmt) { char logname[24] = {0}; snprintf(logname, sizeof(logname), "%slog", pMgmt->name); - dInfo("node:%s, reset log to %s", pMgmt->name, logname); + dInfo("node:%s, reset log to %s in child process", pMgmt->name, logname); taosCloseLog(); taosInitLog(logname, 1); } @@ -51,6 +51,7 @@ int32_t dndOpenNode(SMgmtWrapper *pWrapper) { void dndCloseNode(SMgmtWrapper *pWrapper) { dDebug("node:%s, start to close", pWrapper->name); + pWrapper->required = false; taosWLockLatch(&pWrapper->latch); if (pWrapper->deployed) { (*pWrapper->fp.closeFp)(pWrapper); @@ -199,7 +200,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { dInfo("node:%s, will be initialized in child process", pWrapper->name); dndOpenNode(pWrapper); } else { - dInfo("node:%s, will not start in parent process", pWrapper->name); + dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc)); pWrapper->procType = PROC_PARENT; } @@ -209,16 +210,20 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } } -#if 0 - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE); - if (pWrapper->procType == PROC_PARENT && dmStart(pWrapper->pMgmt) != 0) { - dndReleaseWrapper(pWrapper); - dError("failed to start dnode worker since %s", terrstr()); - return -1; + dndSetStatus(pDnode, DND_STAT_RUNNING); + + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pWrapper->fp.startFp == NULL) continue; + if (pWrapper->procType == PROC_PARENT && n != DNODE) continue; + if (pWrapper->procType == PROC_CHILD && n == DNODE) continue; + if ((*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } } - dndReleaseWrapper(pWrapper); -#endif return 0; } diff --git a/source/dnode/mgmt/container/src/dndObj.c b/source/dnode/mgmt/container/src/dndObj.c index d618f4e503..2123f5946b 100644 --- a/source/dnode/mgmt/container/src/dndObj.c +++ b/source/dnode/mgmt/container/src/dndObj.c @@ -175,7 +175,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { int32_t code = 0; taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { + if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); } else { diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index 24f3f8a6e4..f32f578952 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -208,6 +208,11 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea const int32_t bodyLen = CEIL8(rawBodyLen); const int32_t fullLen = headLen + bodyLen + 8; + if (headLen <= 0 || bodyLen <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } + taosThreadMutexLock(pQueue->mutex); if (fullLen > pQueue->avail) { taosThreadMutexUnlock(pQueue->mutex); @@ -259,7 +264,7 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea taosThreadMutexUnlock(pQueue->mutex); tsem_post(&pQueue->sem); - uTrace("proc:%s, push msg:%p:%d cont:%p:%d to queue:%p", pQueue->name, pHead, rawHeadLen, pBody, rawBodyLen, pQueue); + uTrace("proc:%s, push msg:%p:%d cont:%p:%d to queue:%p", pQueue->name, pHead, headLen, pBody, bodyLen, pQueue); return 0; } @@ -376,7 +381,6 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pid = fork(); if (pProc->pid == 0) { pProc->isChild = 1; - uInfo("this is child process, pid:%d", pProc->pid); } else { pProc->isChild = 0; uInfo("this is parent process, child pid:%d", pProc->pid); @@ -439,6 +443,8 @@ void taosProcStop(SProcObj *pProc) { bool taosProcIsChild(SProcObj *pProc) { return pProc->isChild; } +int32_t taosProcChildId(SProcObj *pProc) { return pProc->pid; } + void taosProcCleanup(SProcObj *pProc) { if (pProc != NULL) { uDebug("proc:%s, clean up", pProc->name); From 72f1719a93254028be4f9d2248557acf7e4c380b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 10:28:23 +0000 Subject: [PATCH 093/149] add btree debug helper function --- source/libs/tdb/src/db/tdbBtree.c | 37 ++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index de77fb2649..45706ae3dc 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1289,4 +1289,39 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { pBtc->idx = pBtc->idxStack[pBtc->iPage]; return 0; -} \ No newline at end of file +} + +#ifndef NODEBUG +typedef struct { + SPgno pgno; + u8 root; + u8 leaf; + SPgno rChild; + int nCells; + int nOvfl; +} SBtPageInfo; + +SBtPageInfo btPageInfos[20]; + +void tdbBtPageInfo(SPage *pPage, int idx) { + u8 flags; + SBtPageInfo *pBtPageInfo; + + pBtPageInfo = btPageInfos + idx; + + pBtPageInfo->pgno = TDB_PAGE_PGNO(pPage); + + flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); + + pBtPageInfo->root = TDB_BTREE_PAGE_IS_ROOT(flags); + pBtPageInfo->leaf = TDB_BTREE_PAGE_IS_LEAF(flags); + + pBtPageInfo->rChild = 0; + if (!pBtPageInfo->leaf) { + pBtPageInfo->rChild = *(SPgno *)(pPage->pData + 1); + } + + pBtPageInfo->nCells = TDB_PAGE_TOTAL_CELLS(pPage) - pPage->nOverflow; + pBtPageInfo->nOvfl = pPage->nOverflow; +} +#endif \ No newline at end of file From fc64a2c72d00464356d2d4f8b7612a98610568fc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Mar 2022 10:54:54 +0000 Subject: [PATCH 094/149] more --- source/libs/tdb/test/tdbTest.cpp | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 4c7af58b14..c256f07cf6 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -3,19 +3,23 @@ #include "tdbInt.h" static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); +static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); TEST(tdb_test, simple_test) { - int ret; - STEnv *pEnv; - STDB *pDb; - int nData = 10000000; + int ret; + STEnv *pEnv; + STDB *pDb; + FKeyComparator compFunc; + int nData = 10000000; + // int nData = 8508; // Open Env ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database - ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, tKeyCmpr, pEnv, &pDb); + compFunc = tKeyCmpr; + ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); { @@ -104,4 +108,24 @@ static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) } else { return 0; } +} + +static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) { + int mlen; + int cret; + + ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL); + + mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2; + cret = memcmp(pKey1, pKey2, mlen); + if (cret == 0) { + if (keyLen1 < keyLen2) { + cret = -1; + } else if (keyLen1 > keyLen2) { + cret = 1; + } else { + cret = 0; + } + } + return cret; } \ No newline at end of file From 0b12117fb263c35179fb85942183e3cad431e313 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 26 Mar 2022 02:53:38 +0000 Subject: [PATCH 095/149] fix a test bug --- source/libs/tdb/test/tdbTest.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index c256f07cf6..52bf26f0ef 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -2,6 +2,8 @@ #include "tdbInt.h" +#include + static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); @@ -11,7 +13,6 @@ TEST(tdb_test, simple_test) { STDB *pDb; FKeyComparator compFunc; int nData = 10000000; - // int nData = 8508; // Open Env ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); @@ -98,8 +99,10 @@ TEST(tdb_test, simple_test) { static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { int k1, k2; - k1 = std::strtol((char *)pKey1 + 3, nullptr, 10); - k2 = std::strtol((char *)pKey2 + 3, nullptr, 10); + std::string s1((char *)pKey1 + 3, kLen1 - 3); + std::string s2((char *)pKey2 + 3, kLen2 - 3); + k1 = stoi(s1); + k2 = stoi(s2); if (k1 < k2) { return -1; From dbec5f1fa4044c4198452b6dcf32b0d0e843ba27 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 26 Mar 2022 09:29:49 +0000 Subject: [PATCH 096/149] fix logical bug with memory leak --- source/libs/tdb/src/db/tdbBtree.c | 12 +-- source/libs/tdb/src/page/tdbPage.c | 6 +- source/libs/tdb/test/tdbTest.cpp | 145 +++++++++++++++++++++-------- 3 files changed, 117 insertions(+), 46 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 45706ae3dc..5980c2b531 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -746,6 +746,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { pgno = TDB_PAGE_PGNO(pNews[iNew]); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); + free(pNewCell); } // move to next new page @@ -795,12 +796,11 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { } } - // TODO: here has memory leak - // for (int i = 0; i < 3; i++) { - // if (pDivCell[i]) { - // free(pDivCell[i]); - // } - // } + for (int i = 0; i < 3; i++) { + if (pDivCell[i]) { + free(pDivCell[i]); + } + } return 0; } diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 15b6e218e6..516330e4e6 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -143,7 +143,11 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl pPage->aiOvfl[i] = pPage->aiOvfl[i - 1]; } - pPage->apOvfl[iOvfl] = pCell; + // TODO: here has memory leak + pNewCell = (SCell *)malloc(szCell); + memcpy(pNewCell, pCell, szCell); + + pPage->apOvfl[iOvfl] = pNewCell; pPage->aiOvfl[iOvfl] = idx; pPage->nOverflow++; iOvfl++; diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 52bf26f0ef..63341e5430 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -4,8 +4,112 @@ #include -static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); -static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); +typedef struct SPoolMem { + int64_t size; + struct SPoolMem *prev; + struct SPoolMem *next; +} SPoolMem; + +static SPoolMem *openPool() { + SPoolMem *pPool = (SPoolMem *)malloc(sizeof(*pPool)); + + pPool->prev = pPool->next = pPool; + pPool->size = 0; + + return pPool; +} + +static void closePool(SPoolMem *pPool) { + SPoolMem *pMem; + + do { + pMem = pPool->next; + + if (pMem == pPool) break; + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + free(pMem); + } while (1); + + assert(pPool->size == 0); + + free(pPool); +} + +static void *poolMalloc(void *arg, int size) { + void *ptr = NULL; + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = (SPoolMem *)malloc(sizeof(*pMem) + size); + if (pMem == NULL) { + assert(0); + } + + pMem->size = sizeof(*pMem) + size; + pMem->next = pPool->next; + pMem->prev = pPool; + + pPool->next->prev = pMem; + pPool->next = pMem; + pPool->size += pMem->size; + + ptr = (void *)(&pMem[1]); + return ptr; +} + +static void poolFree(void *arg, void *ptr) { + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = &(((SPoolMem *)ptr)[-1]); + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + free(pMem); +} + +static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + int k1, k2; + + std::string s1((char *)pKey1 + 3, kLen1 - 3); + std::string s2((char *)pKey2 + 3, kLen2 - 3); + k1 = stoi(s1); + k2 = stoi(s2); + + if (k1 < k2) { + return -1; + } else if (k1 > k2) { + return 1; + } else { + return 0; + } +} + +static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) { + int mlen; + int cret; + + ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL); + + mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2; + cret = memcmp(pKey1, pKey2, mlen); + if (cret == 0) { + if (keyLen1 < keyLen2) { + cret = -1; + } else if (keyLen1 > keyLen2) { + cret = 1; + } else { + cret = 0; + } + } + return cret; +} TEST(tdb_test, simple_test) { int ret; @@ -94,41 +198,4 @@ TEST(tdb_test, simple_test) { // Close Env ret = tdbEnvClose(pEnv); GTEST_ASSERT_EQ(ret, 0); -} - -static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { - int k1, k2; - - std::string s1((char *)pKey1 + 3, kLen1 - 3); - std::string s2((char *)pKey2 + 3, kLen2 - 3); - k1 = stoi(s1); - k2 = stoi(s2); - - if (k1 < k2) { - return -1; - } else if (k1 > k2) { - return 1; - } else { - return 0; - } -} - -static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) { - int mlen; - int cret; - - ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL); - - mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2; - cret = memcmp(pKey1, pKey2, mlen); - if (cret == 0) { - if (keyLen1 < keyLen2) { - cret = -1; - } else if (keyLen1 > keyLen2) { - cret = 1; - } else { - cret = 0; - } - } - return cret; } \ No newline at end of file From 938b3a41d5a0252040e340ffc6ef5076637d64bc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 26 Mar 2022 11:25:18 +0000 Subject: [PATCH 097/149] fix defragment bug --- source/libs/tdb/src/page/tdbPage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 516330e4e6..f1eee48b0e 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -372,11 +372,11 @@ static int tdbPageDefragment(SPage *pPage) { int idx; int iCell; - ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree); - nFree = TDB_PAGE_NFREE(pPage); nCells = TDB_PAGE_NCELLS(pPage); + ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree); + // Loop to compact the page content // Here we use an O(n^2) algorithm to do the job since // this is a low frequency job. From 9c1f71459ee3352a9e12ff1b48a4d44a2409523c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 26 Mar 2022 23:04:51 +0800 Subject: [PATCH 098/149] minor changes --- source/util/src/tprocess.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f32f578952..15708f1cec 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -381,6 +381,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { pProc->pid = fork(); if (pProc->pid == 0) { pProc->isChild = 1; + prctl(PR_SET_NAME, pProc->name, NULL, NULL, NULL); } else { pProc->isChild = 0; uInfo("this is parent process, child pid:%d", pProc->pid); From db2c31cfc49c33bb55c623909f3aed62387785c6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 26 Mar 2022 15:06:17 +0000 Subject: [PATCH 099/149] more TDB --- source/libs/tdb/src/db/tdbPager.c | 100 ++++++++++++++++++++++++++---- source/libs/tdb/src/db/tdbUtil.c | 5 ++ source/libs/tdb/src/inc/tdbUtil.h | 1 + 3 files changed, 95 insertions(+), 11 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index fe4b9aa123..a45a4dad52 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -25,9 +25,7 @@ struct SPager { SPCache *pCache; SPgno dbFileSize; SPgno dbOrigSize; - int nDirty; SPage *pDirty; - SPage *pDirtyTail; u8 inTran; }; @@ -46,6 +44,8 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct") static int tdbPagerReadPage(SPager *pPager, SPage *pPage); static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg); +static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage); +static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage); int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { uint8_t *pPtr; @@ -140,14 +140,25 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { } } - if (pPage->isDirty == 0) { - pPage->isDirty = 1; - // TODO: add the page to the dirty list + if (pPage->isDirty) return 0; - // TODO: write the page to the journal - if (1 /*actually load from the file*/) { + // Set page as dirty + pPage->isDirty = 1; + + // Add page to dirty list + // TODO: sort the list according to the page number + pPage->pDirtyNext = pPager->pDirty; + pPager->pDirty = pPage; + + // Write page to journal + if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize) { + ret = tdbPagerWritePageToJournal(pPager, pPage); + if (ret < 0) { + ASSERT(0); + return -1; } } + return 0; } @@ -170,7 +181,37 @@ int tdbPagerBegin(SPager *pPager) { } int tdbPagerCommit(SPager *pPager) { - // TODO + SPage *pPage; + int ret; + + // Begin commit + { + // TODO: Sync the journal file (Here or when write ?) + } + + for (;;) { + pPage = pPager->pDirty; + + if (pPage == NULL) break; + + ret = tdbPagerWritePageToDB(pPager, pPage); + if (ret < 0) { + ASSERT(0); + return -1; + } + + pPager->pDirty = pPage->pDirtyNext; + pPage->pDirtyNext = NULL; + + // TODO: release the page + } + + fsync(pPager->fd); + + close(pPager->jfd); + remove(pPager->jFileName); + pPager->jfd = -1; + return 0; } @@ -255,9 +296,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage return 0; } -void tdbPagerReturnPage(SPager *pPager, SPage *pPage) { - tdbPCacheRelease(pPager->pCache, pPage); -} +void tdbPagerReturnPage(SPager *pPager, SPage *pPage) { tdbPCacheRelease(pPager->pCache, pPage); } static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) { // TODO: Allocate a page from the free list @@ -328,5 +367,44 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage return -1; } + return 0; +} + +// ---------------------------- Journal manipulation +static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) { + int ret; + SPgno pgno; + + pgno = TDB_PAGE_PGNO(pPage); + + ret = tdbWrite(pPager->jfd, &pgno, sizeof(pgno)); + if (ret < 0) { + return -1; + } + + ret = tdbWrite(pPager->jfd, pPage->pData, pPage->pageSize); + if (ret < 0) { + return -1; + } + + return 0; +} + +static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) { + i64 offset; + int ret; + + offset = pPage->pageSize * TDB_PAGE_PGNO(pPage); + if (lseek(pPager->fd, offset, SEEK_SET) < 0) { + ASSERT(0); + return -1; + } + + ret = tdbWrite(pPager->fd, pPage->pData, pPage->pageSize); + if (ret < 0) { + ASSERT(0); + return -1; + } + return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index c3467c590a..a247e42f32 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -89,4 +89,9 @@ int tdbPRead(int fd, void *pData, int count, i64 offset) { } return count; +} + +int tdbWrite(int fd, void *pData, int count) { + // TODO + return write(fd, pData, count); } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 88fc846bf1..314ede1631 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -38,6 +38,7 @@ int tdbCheckFileAccess(const char *pathname, int mode); int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); int tdbPRead(int fd, void *pData, int count, i64 offset); +int tdbWrite(int fd, void *pData, int count); #define TDB_REALLOC(PTR, SIZE) \ ({ \ From 4693f795261ee4bd4b63b4a68e7291d37c015525 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Sun, 27 Mar 2022 23:26:21 +0800 Subject: [PATCH 100/149] refactor --- include/common/tmsg.h | 2 +- include/util/tdef.h | 2 +- source/libs/parser/src/parInsert.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index d447f11523..bdb6181884 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -208,11 +208,11 @@ typedef struct { typedef struct SSubmitBlk { int64_t uid; // table unique id int64_t suid; // stable id - int32_t padding; // TODO just for padding here int32_t sversion; // data schema version int32_t dataLen; // data part length, not including the SSubmitBlk head int32_t schemaLen; // schema length, if length is 0, no schema exists int16_t numOfRows; // total number of rows in current submit block + int16_t padding; // TODO just for padding here char data[]; } SSubmitBlk; diff --git a/include/util/tdef.h b/include/util/tdef.h index 655deb4625..6c5208ec00 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -209,7 +209,7 @@ typedef enum ELogicConditionType { #define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_FUNC_MAX_RETRIEVE 1024 -#define TSDB_INDEX_NAME_LEN 33 // 32 + 1 '\0' +#define TSDB_INDEX_NAME_LEN 65 // 64 + 1 '\0' #define TSDB_TYPE_STR_MAX_LEN 32 #define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 398e5abaa6..ed67de17e0 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -640,7 +640,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList->numOfBound = 0; pColList->boundNullLen = 0; memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols); - for (int32_t i = 0; i < nCols; ++i) { + for (col_id_t i = 0; i < nCols; ++i) { pColList->cols[i].valStat = VAL_STAT_NONE; } @@ -691,19 +691,19 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* return TSDB_CODE_TSC_OUT_OF_MEMORY; } SBoundIdxInfo* pColIdx = pColList->colIdxInfo; - for (int16_t i = 0; i < pColList->numOfBound; ++i) { + for (col_id_t i = 0; i < pColList->numOfBound; ++i) { pColIdx[i].schemaColIdx = pColList->boundColumns[i]; pColIdx[i].boundIdx = i; } qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar); - for (int16_t i = 0; i < pColList->numOfBound; ++i) { + for (col_id_t i = 0; i < pColList->numOfBound; ++i) { pColIdx[i].finalIdx = i; } qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); } memset(&pColList->boundColumns[pColList->numOfBound], 0, - sizeof(int16_t) * (pColList->numOfCols - pColList->numOfBound)); + sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); return TSDB_CODE_SUCCESS; } From ded8843367436ab2cb68e2a3658de77893e191b3 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 28 Mar 2022 07:35:57 +0800 Subject: [PATCH 101/149] SSDatablock refactor --- source/dnode/vnode/src/tsdb/tsdbSma.c | 102 +++++++++++++++++------- source/dnode/vnode/test/tsdbSmaTest.cpp | 2 +- 2 files changed, 75 insertions(+), 29 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 9d5e132772..07eafd6df0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -38,9 +38,10 @@ typedef enum { } ESmaStorageLevel; typedef struct { - STsdb *pTsdb; - SDBFile dFile; - int32_t interval; // interval with the precision of DB + STsdb *pTsdb; + SDBFile dFile; + SSDataBlock *pData; // sma data + int32_t interval; // interval with the precision of DB } STSmaWriteH; typedef struct { @@ -98,7 +99,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ int32_t nMaxResult); // insert data -static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData); +static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, + int8_t intervalUnit); static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH); static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit); static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit); @@ -800,9 +802,10 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *p return TSDB_CODE_SUCCESS; } -static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData) { +static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, int8_t intervalUnit) { pSmaH->pTsdb = pTsdb; - pSmaH->interval = tsdbGetIntervalByPrecision(pData->interval, pData->intervalUnit, REPO_CFG(pTsdb)->precision); + pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision); + pSmaH->pData = pData; return TSDB_CODE_SUCCESS; } @@ -857,10 +860,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe * @return int32_t */ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { - STsdbCfg *pCfg = REPO_CFG(pTsdb); - STSmaDataWrapper *pData = (STSmaDataWrapper *)msg; - SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); - int64_t indexUid = SMA_TEST_INDEX_UID; + STsdbCfg *pCfg = REPO_CFG(pTsdb); + SSDataBlock *pData = (SSDataBlock *)msg; + SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); + int64_t indexUid = SMA_TEST_INDEX_UID; if (pEnv == NULL) { terrno = TSDB_CODE_INVALID_PTR; @@ -868,15 +871,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { return terrno; } - if (pData->dataLen <= 0) { - TASSERT(0); - terrno = TSDB_CODE_INVALID_PARA; - return TSDB_CODE_FAILED; + if (pData == NULL) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbWarn("vgId:%d insert tSma data failed since pData is NULL", REPO_ID(pTsdb)); + return terrno; } - STSmaWriteH tSmaH = {0}; - - if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData) != 0) { + if (taosArrayGetSize(pData->pDataBlock) <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + tsdbWarn("vgId:%d insert tSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); return TSDB_CODE_FAILED; } @@ -895,6 +898,14 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { return TSDB_CODE_FAILED; } + STSma *pSma = pItem->pSma; + + STSmaWriteH tSmaH = {0}; + + if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { + return TSDB_CODE_FAILED; + } + char rPath[TSDB_FILENAME_LEN] = {0}; char aPath[TSDB_FILENAME_LEN] = {0}; snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid); @@ -907,8 +918,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { } // Step 1: Judge the storage level and days - int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit); + int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); + + +#if 0 int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file @@ -933,7 +947,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { // Step 3: reset the SSmaStat tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey); - +#endif tsdbDestroyTSmaWriteH(&tSmaH); tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_SUCCESS; @@ -999,29 +1013,58 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, } static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { - STsdbCfg *pCfg = REPO_CFG(pTsdb); - STSmaDataWrapper *pData = (STSmaDataWrapper *)msg; - SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); + STsdbCfg *pCfg = REPO_CFG(pTsdb); + SSDataBlock *pData = (SSDataBlock *)msg; + SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); + int64_t indexUid = SMA_TEST_INDEX_UID; if (pEnv == NULL) { terrno = TSDB_CODE_INVALID_PTR; - tsdbWarn("vgId:%d insert tSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); + tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); return terrno; } - if (pData->dataLen <= 0) { - TASSERT(0); + if (pEnv == NULL) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); + return terrno; + } + + if (pData == NULL) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbWarn("vgId:%d insert rSma data failed since pData is NULL", REPO_ID(pTsdb)); + return terrno; + } + + if (taosArrayGetSize(pData->pDataBlock) <= 0) { terrno = TSDB_CODE_INVALID_PARA; + tsdbWarn("vgId:%d insert rSma data failed since pDataBlock is empty", REPO_ID(pTsdb)); return TSDB_CODE_FAILED; } + SSmaStat *pStat = SMA_ENV_STAT(pTsdb->pTSmaEnv); + SSmaStatItem *pItem = NULL; + + tsdbRefSmaStat(pTsdb, pStat); + + if (pStat && pStat->smaStatItems) { + pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid)); + } + + if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) { + terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + + STSma *pSma = pItem->pSma; + STSmaWriteH tSmaH = {0}; - if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData) != 0) { + if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) { return TSDB_CODE_FAILED; } - int64_t indexUid = SMA_TEST_INDEX_UID; char rPath[TSDB_FILENAME_LEN] = {0}; char aPath[TSDB_FILENAME_LEN] = {0}; snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid); @@ -1033,8 +1076,9 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { } // Step 1: Judge the storage level and days - int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit); + int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); + #if 0 int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file @@ -1057,8 +1101,10 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { // Step 3: reset the SSmaStat tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey); +#endif tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 86db3af4dc..29a4b7f552 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -280,7 +280,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { } #endif -#if 1 +#if 0 TEST(testCase, tSma_Data_Insert_Query_Test) { // step 1: prepare meta const char *smaIndexName1 = "sma_index_test_1"; From 77957065068a3f17d4c5b8028df12ee3df2dfa2b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 01:23:10 +0000 Subject: [PATCH 102/149] refact and more --- source/libs/tdb/CMakeLists.txt | 1 + source/libs/tdb/src/db/tdbBtree.c | 112 +++++++++++++++--------------- source/libs/tdb/src/db/tdbTxn.c | 31 +++++++++ source/libs/tdb/src/inc/tdbInt.h | 2 + source/libs/tdb/src/inc/tdbTxn.h | 39 +++++++++++ source/libs/tdb/test/tdbTest.cpp | 27 ++++++- 6 files changed, 154 insertions(+), 58 deletions(-) create mode 100644 source/libs/tdb/src/db/tdbTxn.c create mode 100644 source/libs/tdb/src/inc/tdbTxn.h diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index a9b56d42b8..8612c9dc8f 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -8,6 +8,7 @@ target_sources(tdb "src/db/tdbBtree.c" "src/db/tdbDb.c" "src/db/tdbEnv.c" + "src/db/tdbTxn.c" "src/page/tdbPage.c" "src/page/tdbPageL.c" ) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 5980c2b531..5ead5ac8a4 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -67,7 +67,7 @@ typedef struct { u8 *pTmpSpace; } SCellDecoder; -static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst); +static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeZeroPage(SPage *pPage, void *arg); @@ -75,10 +75,10 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg); static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, int *szCell); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); -static int tdbBtreeBalance(SBTC *pCur); +static int tdbBtreeBalance(SBTC *pBtc); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); static int tdbBtcMoveToNext(SBTC *pBtc); -static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno); +static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno); static int tdbBtcMoveUpward(SBTC *pBtc); int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { @@ -134,7 +134,7 @@ int tdbBtreeClose(SBTree *pBt) { return 0; } -int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen) { +int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal, int vLen) { int ret; int idx; SPager *pPager; @@ -143,20 +143,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int cret; SBTree *pBt; - ret = tdbBtCursorMoveTo(pCur, pKey, kLen, &cret); + ret = tdbBtCursorMoveTo(pBtc, pKey, kLen, &cret); if (ret < 0) { // TODO: handle error return -1; } - if (pCur->idx == -1) { - ASSERT(TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0); + if (pBtc->idx == -1) { + ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0); idx = 0; } else { if (cret > 0) { - idx = pCur->idx + 1; + idx = pBtc->idx + 1; } else if (cret < 0) { - idx = pCur->idx; + idx = pBtc->idx; } else { /* TODO */ ASSERT(0); @@ -164,7 +164,7 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, } // TODO: refact code here - pBt = pCur->pBt; + pBt = pBtc->pBt; if (!pBt->pTmp) { pBt->pTmp = (u8 *)malloc(pBt->pageSize); if (pBt->pTmp == NULL) { @@ -175,20 +175,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, pCell = pBt->pTmp; // Encode the cell - ret = tdbBtreeEncodeCell(pCur->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); + ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); if (ret < 0) { return -1; } // Insert the cell to the index - ret = tdbPageInsertCell(pCur->pPage, idx, pCell, szCell, 0); + ret = tdbPageInsertCell(pBtc->pPage, idx, pCell, szCell, 0); if (ret < 0) { return -1; } // If page is overflow, balance the tree - if (pCur->pPage->nOverflow > 0) { - ret = tdbBtreeBalance(pCur); + if (pBtc->pPage->nOverflow > 0) { + ret = tdbBtreeBalance(pBtc); if (ret < 0) { return -1; } @@ -226,30 +226,30 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen return 0; } -static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) { +static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { int ret; SBTree *pBt; SPager *pPager; - pBt = pCur->pBt; + pBt = pBtc->pBt; pPager = pBt->pPager; - if (pCur->iPage < 0) { - ASSERT(pCur->iPage == -1); - ASSERT(pCur->idx == -1); + if (pBtc->iPage < 0) { + ASSERT(pBtc->iPage == -1); + ASSERT(pBtc->idx == -1); // Move from the root - ret = tdbPagerFetchPage(pPager, pBt->root, &(pCur->pPage), tdbBtreeInitPage, pBt); + ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt); if (ret < 0) { ASSERT(0); return -1; } - pCur->iPage = 0; + pBtc->iPage = 0; - if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) { + if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) { // Current page is empty - // ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); + // ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pBtc->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); return 0; } @@ -259,7 +259,7 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) SPage *pPage; SCellDecoder cd = {0}; - pPage = pCur->pPage; + pPage = pBtc->pPage; nCells = TDB_PAGE_TOTAL_CELLS(pPage); lidx = 0; ridx = nCells - 1; @@ -297,22 +297,22 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); if (leaf) { - pCur->idx = midx; + pBtc->idx = midx; *pCRst = c; break; } else { if (c <= 0) { - pCur->idx = midx; - tdbBtcMoveDownward(pCur, cd.pgno); + pBtc->idx = midx; + tdbBtcMoveDownward(pBtc, cd.pgno); } else { - pCur->idx = midx + 1; + pBtc->idx = midx + 1; if (midx == nCells - 1) { /* Move to right-most child */ - tdbBtcMoveDownward(pCur, ((SIntHdr *)pCur->pPage->pData)->pgno); + tdbBtcMoveDownward(pBtc, ((SIntHdr *)pBtc->pPage->pData)->pgno); } else { - pCell = tdbPageGetCell(pPage, pCur->idx); + pCell = tdbPageGetCell(pPage, pBtc->idx); tdbBtreeDecodeCell(pPage, pCell, &cd); - tdbBtcMoveDownward(pCur, cd.pgno); + tdbBtcMoveDownward(pBtc, cd.pgno); } } } @@ -805,7 +805,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { return 0; } -static int tdbBtreeBalance(SBTC *pCur) { +static int tdbBtreeBalance(SBTC *pBtc) { int iPage; SPage *pParent; SPage *pPage; @@ -816,8 +816,8 @@ static int tdbBtreeBalance(SBTC *pCur) { // Main loop to balance the BTree for (;;) { - iPage = pCur->iPage; - pPage = pCur->pPage; + iPage = pBtc->iPage; + pPage = pBtc->pPage; flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); leaf = TDB_BTREE_PAGE_IS_LEAF(flags); root = TDB_BTREE_PAGE_IS_ROOT(flags); @@ -833,27 +833,27 @@ static int tdbBtreeBalance(SBTC *pCur) { // ignore the case of empty if (pPage->nOverflow == 0) break; - ret = tdbBtreeBalanceDeeper(pCur->pBt, pPage, &(pCur->pgStack[1])); + ret = tdbBtreeBalanceDeeper(pBtc->pBt, pPage, &(pBtc->pgStack[1])); if (ret < 0) { return -1; } - pCur->idx = 0; - pCur->idxStack[0] = 0; - pCur->pgStack[0] = pCur->pPage; - pCur->iPage = 1; - pCur->pPage = pCur->pgStack[1]; + pBtc->idx = 0; + pBtc->idxStack[0] = 0; + pBtc->pgStack[0] = pBtc->pPage; + pBtc->iPage = 1; + pBtc->pPage = pBtc->pgStack[1]; } else { // Generalized balance step - pParent = pCur->pgStack[iPage - 1]; + pParent = pBtc->pgStack[iPage - 1]; - ret = tdbBtreeBalanceNonRoot(pCur->pBt, pParent, pCur->idxStack[pCur->iPage - 1]); + ret = tdbBtreeBalanceNonRoot(pBtc->pBt, pParent, pBtc->idxStack[pBtc->iPage - 1]); if (ret < 0) { return -1; } - pCur->iPage--; - pCur->pPage = pCur->pgStack[pCur->iPage]; + pBtc->iPage--; + pBtc->pPage = pBtc->pgStack[pBtc->iPage]; } } @@ -1050,11 +1050,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { #endif -int tdbBtcOpen(SBTC *pCur, SBTree *pBt) { - pCur->pBt = pBt; - pCur->iPage = -1; - pCur->pPage = NULL; - pCur->idx = -1; +int tdbBtcOpen(SBTC *pBtc, SBTree *pBt) { + pBtc->pBt = pBt; + pBtc->iPage = -1; + pBtc->pPage = NULL; + pBtc->idx = -1; return 0; } @@ -1262,16 +1262,16 @@ int tdbBtcClose(SBTC *pBtc) { return 0; } -static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno) { +static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { int ret; - pCur->pgStack[pCur->iPage] = pCur->pPage; - pCur->idxStack[pCur->iPage] = pCur->idx; - pCur->iPage++; - pCur->pPage = NULL; - pCur->idx = -1; + pBtc->pgStack[pBtc->iPage] = pBtc->pPage; + pBtc->idxStack[pBtc->iPage] = pBtc->idx; + pBtc->iPage++; + pBtc->pPage = NULL; + pBtc->idx = -1; - ret = tdbPagerFetchPage(pCur->pBt->pPager, pgno, &pCur->pPage, tdbBtreeInitPage, pCur->pBt); + ret = tdbPagerFetchPage(pBtc->pBt->pPager, pgno, &pBtc->pPage, tdbBtreeInitPage, pBtc->pBt); if (ret < 0) { ASSERT(0); } diff --git a/source/libs/tdb/src/db/tdbTxn.c b/source/libs/tdb/src/db/tdbTxn.c new file mode 100644 index 0000000000..1a2dfc77cd --- /dev/null +++ b/source/libs/tdb/src/db/tdbTxn.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "tdbInt.h" + +int tdbTxnBegin(STEnv *pEnv) { + // TODO + return 0; +} + +int tdbTxnCommit(STEnv *pEnv) { + // TODO + return 0; +} + +int tdbTxnRollback(STEnv *pEnv) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 98845bb66f..06c09aba3f 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -162,6 +162,8 @@ typedef struct SPage SPage; #include "tdbPage.h" +#include "tdbTxn.h" + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h new file mode 100644 index 0000000000..88d469ac34 --- /dev/null +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TDB_TXN_H_ +#define _TDB_TXN_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct STxn STXN; + +struct STxn { + u64 txnId; + void *(*xMalloc)(void *, int); + void *xArg; +}; + +int tdbTxnBegin(STEnv *pEnv); +int tdbTxnCommit(STEnv *pEnv); +int tdbTxnRollback(STEnv *pEnv); + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_TXN_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 63341e5430..1dc6cf0213 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -39,6 +39,8 @@ static void closePool(SPoolMem *pPool) { free(pPool); } +#define clearPool closePool + static void *poolMalloc(void *arg, int size) { void *ptr = NULL; SPoolMem *pPool = (SPoolMem *)arg; @@ -116,7 +118,7 @@ TEST(tdb_test, simple_test) { STEnv *pEnv; STDB *pDb; FKeyComparator compFunc; - int nData = 10000000; + int nData = 1000000; // Open Env ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); @@ -132,13 +134,34 @@ TEST(tdb_test, simple_test) { char val[64]; { // Insert some data + int i = 1; + SPoolMem *pPool; + int memPoolCapacity = 16 * 1024; + + pPool = openPool(); + + tdbTxnBegin(pEnv); + + for (;;) { + if (i > nData) break; - for (int i = 1; i <= nData; i++) { sprintf(key, "key%d", i); sprintf(val, "value%d", i); ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); GTEST_ASSERT_EQ(ret, 0); + + if (pPool->size >= memPoolCapacity) { + tdbTxnCommit(pEnv); + + clearPool(pPool); + + tdbTxnBegin(pEnv); + } + + i++; } + + closePool(pPool); } { // Query the data From 53e5bfb820af07bfa9b4dc90716b443a269927db Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 10:09:00 +0800 Subject: [PATCH 103/149] minor changes --- source/dnode/mnode/impl/src/mndUser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index ff34c26c4a..7d3f755cd7 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -21,7 +21,7 @@ #include "mndTrans.h" #include "tbase64.h" -#define TSDB_USER_VER_NUMBER 1 +#define TSDB_USER_VER_NUMBER 1 #define TSDB_USER_RESERVE_SIZE 64 static int32_t mndCreateDefaultUsers(SMnode *pMnode); @@ -270,7 +270,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate userObj.updateTime = userObj.createdTime; userObj.superUser = pCreate->superUser; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_CREATE_USER, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; @@ -350,7 +350,7 @@ CREATE_USER_OVER: } static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER,&pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to update since %s", pOld->user, terrstr()); return -1; @@ -511,7 +511,7 @@ ALTER_USER_OVER: } static int32_t mndDropUser(SMnode *pMnode, SNodeMsg *pReq, SUserObj *pUser) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_DROP_USER, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_USER, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to drop since %s", pUser->user, terrstr()); return -1; From 4b5c05334fb2b336616be1ce7441c2fc5602d4bf Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 10:10:06 +0800 Subject: [PATCH 104/149] minor changes --- source/util/src/tprocess.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f170be0844..f5ce88179b 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -152,7 +152,7 @@ static void taosProcDestroyBuffer(void *pBuffer, int32_t shmid) { } } -static SProcQueue *taosProcQueueInit(int32_t size) { +static SProcQueue *taosProcInitQueue(int32_t size) { if (size <= 0) size = SHM_DEFAULT_SIZE; int32_t bufSize = CEIL8(size); @@ -353,10 +353,10 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { } pProc->name = pCfg->name; - pProc->pChildQueue = taosProcQueueInit(pCfg->childQueueSize); - pProc->pParentQueue = taosProcQueueInit(pCfg->parentQueueSize); + pProc->pChildQueue = taosProcInitQueue(pCfg->childQueueSize); + pProc->pParentQueue = taosProcInitQueue(pCfg->parentQueueSize); if (pProc->pChildQueue == NULL || pProc->pParentQueue == NULL) { - taosProcQueueCleanup(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pChildQueue); taosMemoryFree(pProc); return NULL; } @@ -450,8 +450,8 @@ void taosProcCleanup(SProcObj *pProc) { if (pProc != NULL) { uDebug("proc:%s, clean up", pProc->name); taosProcStop(pProc); - taosProcQueueCleanup(pProc->pChildQueue); - taosProcQueueCleanup(pProc->pParentQueue); + taosProcCleanupQueue(pProc->pChildQueue); + taosProcCleanupQueue(pProc->pParentQueue); taosMemoryFree(pProc); } } From d882edd037f151357270b6486df0b8946cb23da9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 10:13:24 +0800 Subject: [PATCH 105/149] minor changes --- source/dnode/mgmt/container/src/dndExec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 24c7ad7968..a7b8ca288b 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -139,7 +139,7 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t msgLen, void *pCont, int32_t contLen) { dTrace("msg:%p, get from parent queue", pRsp); pRsp->pCont = pCont; - dndSendRpcRsp(pWrapper, pRsp); + dndSendRsp(pWrapper, pRsp); taosMemoryFree(pRsp); } From 6d1477e6932dec81860eb3207c1001786276ae58 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 02:26:27 +0000 Subject: [PATCH 106/149] more TDB --- source/libs/CMakeLists.txt | 2 +- source/libs/tdb/src/db/tdbBtree.c | 12 ++--- source/libs/tdb/src/db/tdbDb.c | 4 +- source/libs/tdb/src/db/tdbEnv.c | 2 +- source/libs/tdb/src/db/tdbOs.c | 14 +++++ source/libs/tdb/src/db/tdbPCache.c | 6 +-- source/libs/tdb/src/db/tdbPager.c | 12 ++--- source/libs/tdb/src/inc/tdbInt.h | 2 + source/libs/tdb/src/inc/tdbOs.h | 85 ++++++++++++++++++++++++++++++ source/libs/tdb/src/inc/tdbPage.h | 38 ++++++------- source/libs/tdb/src/inc/tdbUtil.h | 34 ++++++------ source/libs/tdb/src/page/tdbPage.c | 4 +- 12 files changed, 158 insertions(+), 57 deletions(-) create mode 100644 source/libs/tdb/src/db/tdbOs.c create mode 100644 source/libs/tdb/src/inc/tdbOs.h diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index b448a43dcb..a1b9337fa8 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(transport) add_subdirectory(sync) -# add_subdirectory(tdb) +add_subdirectory(tdb) add_subdirectory(index) add_subdirectory(wal) add_subdirectory(parser) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 5ead5ac8a4..0800ebbc49 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -87,7 +87,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S *ppBt = NULL; - pBt = (SBTree *)calloc(1, sizeof(*pBt)); + pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt)); if (pBt == NULL) { return -1; } @@ -121,7 +121,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S // TODO: pBt->root ret = tdbBtreeOpenImpl(pBt); if (ret < 0) { - free(pBt); + tdbOsFree(pBt); return -1; } @@ -550,7 +550,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { pCell = tdbPageGetCell(pParent, sIdx + i); szDivCell[i] = tdbBtreeCellSize(pParent, pCell); - pDivCell[i] = malloc(szDivCell[i]); + pDivCell[i] = tdbOsMalloc(szDivCell[i]); memcpy(pDivCell[i], pCell, szDivCell[i]); } @@ -740,13 +740,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { tdbBtreeDecodeCell(pPage, pCell, &cd); // TODO: pCell here may be inserted as an overflow cell, handle it - SCell *pNewCell = malloc(cd.kLen + 9); + SCell *pNewCell = tdbOsMalloc(cd.kLen + 9); int szNewCell; SPgno pgno; pgno = TDB_PAGE_PGNO(pNews[iNew]); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); - free(pNewCell); + tdbOsFree(pNewCell); } // move to next new page @@ -798,7 +798,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { for (int i = 0; i < 3; i++) { if (pDivCell[i]) { - free(pDivCell[i]); + tdbOsFree(pDivCell[i]); } } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 4e74dc4cbb..1117550ed1 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -34,7 +34,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF *ppDb = NULL; - pDb = (STDB *)calloc(1, sizeof(*pDb)); + pDb = (STDB *)tdbOsCalloc(1, sizeof(*pDb)); if (pDb == NULL) { return -1; } @@ -126,7 +126,7 @@ int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { int tdbDbcClose(STDBC *pDbc) { if (pDbc) { - free(pDbc); + tdbOsFree(pDbc); } return 0; diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 9a4dcdbcd5..ad3b5c41f2 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -27,7 +27,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) dsize = strlen(rootDir); zsize = sizeof(*pEnv) + dsize * 2 + strlen(TDB_JOURNAL_NAME) + 3; - pPtr = (uint8_t *)calloc(1, zsize); + pPtr = (uint8_t *)tdbOsCalloc(1, zsize); if (pPtr == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/libs/tdb/src/db/tdbOs.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 3c7d037faa..1e93d87ab8 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -63,7 +63,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { void *pPtr; SPage *pPgHdr; - pCache = (SPCache *)calloc(1, sizeof(*pCache)); + pCache = (SPCache *)tdbOsCalloc(1, sizeof(*pCache)); if (pCache == NULL) { return -1; } @@ -72,7 +72,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { pCache->cacheSize = cacheSize; if (tdbPCacheOpenImpl(pCache) < 0) { - free(pCache); + tdbOsFree(pCache); return -1; } @@ -268,7 +268,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { // Open the hash table pCache->nPage = 0; pCache->nHash = pCache->cacheSize; - pCache->pgHash = (SPage **)calloc(pCache->nHash, sizeof(SPage *)); + pCache->pgHash = (SPage **)tdbOsCalloc(pCache->nHash, sizeof(SPage *)); if (pCache->pgHash == NULL) { // TODO return -1; diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index a45a4dad52..db2568c5aa 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -20,8 +20,8 @@ struct SPager { char *jFileName; int pageSize; uint8_t fid[TDB_FILE_ID_LEN]; - int fd; - int jfd; + tdb_fd_t fd; + tdb_fd_t jfd; SPCache *pCache; SPgno dbFileSize; SPgno dbOrigSize; @@ -60,7 +60,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { zsize = sizeof(*pPager) /* SPager */ + fsize + 1 /* dbFileName */ + fsize + 8 + 1; /* jFileName */ - pPtr = (uint8_t *)calloc(1, zsize); + pPtr = (uint8_t *)tdbOsCalloc(1, zsize); if (pPtr == NULL) { return -1; } @@ -80,7 +80,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { // pPager->pCache pPager->pCache = pCache; - pPager->fd = open(pPager->dbFileName, O_RDWR | O_CREAT, 0755); + pPager->fd = tdbOsOpen(pPager->dbFileName, O_RDWR | O_CREAT, 0755); if (pPager->fd < 0) { return -1; } @@ -168,7 +168,7 @@ int tdbPagerBegin(SPager *pPager) { } // Open the journal - pPager->jfd = open(pPager->jFileName, O_RDWR | O_CREAT, 0755); + pPager->jfd = tdbOsOpen(pPager->jFileName, O_RDWR | O_CREAT, 0755); if (pPager->jfd < 0) { return -1; } @@ -208,7 +208,7 @@ int tdbPagerCommit(SPager *pPager) { fsync(pPager->fd); - close(pPager->jfd); + tdbOsClose(pPager->jfd); remove(pPager->jFileName); pPager->jfd = -1; diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 06c09aba3f..c926d9358c 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -148,6 +148,8 @@ typedef struct SPager SPager; typedef struct SPCache SPCache; typedef struct SPage SPage; +#include "tdbOs.h" + #include "tdbUtil.h" #include "tdbPCache.h" diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h new file mode 100644 index 0000000000..b05ce47ac5 --- /dev/null +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TDB_OS_H_ +#define _TDB_OS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: kmake +#define TDB_FOR_TDENGINE + +// For memor +#ifdef TDB_FOR_TDENGINE +#define tdbOsMalloc taosMemoryMalloc +#define tdbOsCalloc taosMemoryCalloc +#define tdbOsRealloc taosMemoryRealloc +#define tdbOsFree taosMemoryFree +#else +#define tdbOsMalloc malloc +#define tdbOsCalloc calloc +#define tdbOsRealloc realloc +#define tdbOsFree free +#endif + +// For file +#ifdef TDB_FOR_TDENGINE +typedef TdFilePtr tdb_fd_t; + +#define tdbOsOpen taosOpenFile +#define tdbOsClose taosCloseFile +#define tdbOsRead taosReadFile +#define tdbOsPRead taosPReadFile +#define tdbOsWrite taosWriteFile +#else +#define tdbOsOpen open +#define tdbOsClose close +#define tdbOsRead read +#define tdbOsPRead pread +#define tdbOsWrite write +#endif + +// For threads and lock +#ifdef TDB_FOR_TDENGINE + +// spin lock +typedef TdThreadSpinlock tdb_spinlock_t; + +#define tdbSpinlockInit taosThreadSpinInit +#define tdbSpinlockDestroy taosThreadSpinDestroy +#define tdbSpinlockLock taosThreadSpinLock +#define tdbSpinlockUnlock taosThreadSpinUnlock +#define tdbSpinlockTrylock + +#else + +// spin lock +typedef pthread_spinlock_t tdb_spinlock_t; + +#define tdbSpinlockInit pthread_spin_init +#define tdbSpinlockDestroy pthread_spin_destroy +#define tdbSpinlockLock pthread_spin_lock +#define tdbSpinlockUnlock pthread_spin_unlock +#define tdbSpinlockTrylock pthread_spin_trylock + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TDB_OS_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index a6f9fbf615..49aa9f4398 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -53,10 +53,10 @@ typedef struct __attribute__((__packed__)) { } SPageFtr; struct SPage { - pthread_spinlock_t lock; - int pageSize; - u8 *pData; - SPageMethods *pPageMethods; + tdb_spinlock_t lock; + int pageSize; + u8 *pData; + SPageMethods *pPageMethods; // Fields below used by pager and am u8 *pPageHdr; u8 *pCellIdx; @@ -80,21 +80,21 @@ struct SPage { #define P_LOCK_BUSY 1 #define P_LOCK_FAIL -1 -#define TDB_INIT_PAGE_LOCK(pPage) pthread_spin_init(&((pPage)->lock), 0) -#define TDB_DESTROY_PAGE_LOCK(pPage) pthread_spin_destroy(&((pPage)->lock)) -#define TDB_LOCK_PAGE(pPage) pthread_spin_lock(&((pPage)->lock)) -#define TDB_UNLOCK_PAGE(pPage) pthread_spin_unlock(&((pPage)->lock)) -#define TDB_TRY_LOCK_PAGE(pPage) \ - ({ \ - int ret; \ - if (pthread_spin_trylock(&((pPage)->lock)) == 0) { \ - ret = P_LOCK_SUCC; \ - } else if (errno == EBUSY) { \ - ret = P_LOCK_BUSY; \ - } else { \ - ret = P_LOCK_FAIL; \ - } \ - ret; \ +#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0) +#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock)) +#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock)) +#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock)) +#define TDB_TRY_LOCK_PAGE(pPage) \ + ({ \ + int ret; \ + if (tdbSpinlockTrylock(&((pPage)->lock)) == 0) { \ + ret = P_LOCK_SUCC; \ + } else if (errno == EBUSY) { \ + ret = P_LOCK_BUSY; \ + } else { \ + ret = P_LOCK_FAIL; \ + } \ + ret; \ }) // APIs diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index f7b5a31012..0633d4e48b 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -40,37 +40,37 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); int tdbPRead(int fd, void *pData, int count, i64 offset); int tdbWrite(int fd, void *pData, int count); -#define TDB_REALLOC(PTR, SIZE) \ - ({ \ - void *nPtr; \ - if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \ - nPtr = realloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \ - if (nPtr) { \ - ((int *)nPtr)[0] = (SIZE); \ - nPtr = (char *)nPtr + sizeof(int); \ - } \ - } else { \ - nPtr = (PTR); \ - } \ - nPtr; \ +#define TDB_REALLOC(PTR, SIZE) \ + ({ \ + void *nPtr; \ + if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \ + nPtr = tdbOsRealloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \ + if (nPtr) { \ + ((int *)nPtr)[0] = (SIZE); \ + nPtr = (char *)nPtr + sizeof(int); \ + } \ + } else { \ + nPtr = (PTR); \ + } \ + nPtr; \ }) #define TDB_FREE(PTR) \ do { \ if (PTR) { \ - free((char *)(PTR) - sizeof(int)); \ + tdbOsFree((char *)(PTR) - sizeof(int)); \ } \ } while (0) -static inline void *tdbOsMalloc(void *arg, size_t size) { +static inline void *tdbDefaultMalloc(void *arg, size_t size) { void *ptr; - ptr = malloc(size); + ptr = tdbOsMalloc(size); return ptr; } -static inline void tdbOsFree(void *arg, void *ptr) { free(ptr); } +static inline void tdbDefaultFree(void *arg, void *ptr) { tdbOsFree(ptr); } static inline int tdbPutVarInt(u8 *p, int v) { int n = 0; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index f1eee48b0e..7f92f740da 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -48,7 +48,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) *ppPage = NULL; size = pageSize + sizeof(*pPage); if (xMalloc == NULL) { - xMalloc = tdbOsMalloc; + xMalloc = tdbDefaultMalloc; } ptr = (u8 *)((*xMalloc)(arg, size)); @@ -76,7 +76,7 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) u8 *ptr; if (!xFree) { - xFree = tdbOsFree; + xFree = tdbDefaultFree; } ptr = pPage->pData; From 8f6ba1fc5b05919c0414a02a98ed2bfa958d2901 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 02:40:55 +0000 Subject: [PATCH 107/149] more TDB --- source/libs/tdb/src/db/tdbPCache.c | 28 ++++++++++++++-------------- source/libs/tdb/src/db/tdbPager.c | 2 +- source/libs/tdb/src/inc/tdbOs.h | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 1e93d87ab8..981dd63593 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -15,16 +15,16 @@ #include "tdbInt.h" struct SPCache { - int pageSize; - int cacheSize; - pthread_mutex_t mutex; - int nFree; - SPage *pFree; - int nPage; - int nHash; - SPage **pgHash; - int nRecyclable; - SPage lru; + int pageSize; + int cacheSize; + tdb_mutex_t mutex; + int nFree; + SPage *pFree; + int nPage; + int nHash; + SPage **pgHash; + int nRecyclable; + SPage lru; }; #define PCACHE_PAGE_HASH(pPgid) \ @@ -116,13 +116,13 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { } } -static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); } +static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } -static void tdbPCacheClearLock(SPCache *pCache) { pthread_mutex_destroy(&(pCache->mutex)); } +static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } -static void tdbPCacheLock(SPCache *pCache) { pthread_mutex_lock(&(pCache->mutex)); } +static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } -static void tdbPCacheUnlock(SPCache *pCache) { pthread_mutex_unlock(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } static bool tdbPCacheLocked(SPCache *pCache) { assert(0); diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index db2568c5aa..5f79d60a78 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -206,7 +206,7 @@ int tdbPagerCommit(SPager *pPager) { // TODO: release the page } - fsync(pPager->fd); + tdbOsFSync(pPager->fd); tdbOsClose(pPager->jfd); remove(pPager->jFileName); diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index b05ce47ac5..0d7a3299f1 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -45,12 +45,14 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsRead taosReadFile #define tdbOsPRead taosPReadFile #define tdbOsWrite taosWriteFile +#define tdbOsFSync taosFsyncFile #else #define tdbOsOpen open #define tdbOsClose close #define tdbOsRead read #define tdbOsPRead pread #define tdbOsWrite write +#define tdbOsFSync fsync #endif // For threads and lock @@ -65,6 +67,14 @@ typedef TdThreadSpinlock tdb_spinlock_t; #define tdbSpinlockUnlock taosThreadSpinUnlock #define tdbSpinlockTrylock +// mutex lock +typedef TdThreadMutex tdb_mutex_t; + +#define tdbMutexInit taosThreadMutexInit +#define tdbMutexDestroy taosThreadMutexDestroy +#define tdbMutexLock taosThreadMutexLock +#define tdbMutexUnlock taosThreadMutexUnlock + #else // spin lock @@ -76,6 +86,14 @@ typedef pthread_spinlock_t tdb_spinlock_t; #define tdbSpinlockUnlock pthread_spin_unlock #define tdbSpinlockTrylock pthread_spin_trylock +// mutex lock +typedef pthread_mutex_t tdb_mutex_t; + +#define tdbMutexInit pthread_mutex_init +#define tdbMutexDestroy pthread_mutex_destroy +#define tdbMutexLock pthread_mutex_lock +#define tdbMutexUnlock pthread_mutex_unlock + #endif #ifdef __cplusplus From a8882c5c1469681bba434741bdeaf2dca9039ee2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 02:50:39 +0000 Subject: [PATCH 108/149] more TDB --- source/libs/tdb/src/db/tdbBtree.c | 2 +- source/libs/tdb/src/db/tdbDb.c | 2 +- source/libs/tdb/src/db/tdbPager.c | 2 +- source/libs/tdb/src/inc/tdbOs.h | 8 ++++---- source/libs/tdb/src/page/tdbPage.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0800ebbc49..faced8e839 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -166,7 +166,7 @@ int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal, // TODO: refact code here pBt = pBtc->pBt; if (!pBt->pTmp) { - pBt->pTmp = (u8 *)malloc(pBt->pageSize); + pBt->pTmp = (u8 *)tdbOsMalloc(pBt->pageSize); if (pBt->pTmp == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 1117550ed1..499116f091 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -101,7 +101,7 @@ int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { STDBC *pDbc = NULL; *ppDbc = NULL; - pDbc = malloc(sizeof(*pDbc)); + pDbc = (STDBC *)tdbOsMalloc(sizeof(*pDbc)); if (pDbc == NULL) { return -1; } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 5f79d60a78..f55f427b36 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -222,7 +222,7 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) { ASSERT(memcmp(pPager->fid, pPage->pgid.fileid, TDB_FILE_ID_LEN) == 0); offset = (pPage->pgid.pgno - 1) * (i64)(pPager->pageSize); - ret = tdbPRead(pPager->fd, pPage->pData, pPager->pageSize, offset); + ret = tdbOsPRead(pPager->fd, pPage->pData, pPager->pageSize, offset); if (ret < 0) { // TODO: handle error return -1; diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 0d7a3299f1..ac538341f1 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -49,9 +49,9 @@ typedef TdFilePtr tdb_fd_t; #else #define tdbOsOpen open #define tdbOsClose close -#define tdbOsRead read -#define tdbOsPRead pread -#define tdbOsWrite write +#define tdbOsRead read // TODO +#define tdbOsPRead pread // TODO +#define tdbOsWrite write // TODO #define tdbOsFSync fsync #endif @@ -65,7 +65,7 @@ typedef TdThreadSpinlock tdb_spinlock_t; #define tdbSpinlockDestroy taosThreadSpinDestroy #define tdbSpinlockLock taosThreadSpinLock #define tdbSpinlockUnlock taosThreadSpinUnlock -#define tdbSpinlockTrylock +#define tdbSpinlockTrylock pthread_spin_trylock // TODO // mutex lock typedef TdThreadMutex tdb_mutex_t; diff --git a/source/libs/tdb/src/page/tdbPage.c b/source/libs/tdb/src/page/tdbPage.c index 7f92f740da..3301202a33 100644 --- a/source/libs/tdb/src/page/tdbPage.c +++ b/source/libs/tdb/src/page/tdbPage.c @@ -144,7 +144,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl } // TODO: here has memory leak - pNewCell = (SCell *)malloc(szCell); + pNewCell = (SCell *)tdbOsMalloc(szCell); memcpy(pNewCell, pCell, szCell); pPage->apOvfl[iOvfl] = pNewCell; From 3146ac2d3b33cbc8b908de0e11d62cd531fe78c3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:00:02 +0000 Subject: [PATCH 109/149] more TDB --- source/libs/tdb/src/db/tdbPager.c | 8 ++++---- source/libs/tdb/src/inc/tdbOs.h | 32 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index f55f427b36..b811fcb135 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -80,7 +80,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { // pPager->pCache pPager->pCache = pCache; - pPager->fd = tdbOsOpen(pPager->dbFileName, O_RDWR | O_CREAT, 0755); + pPager->fd = tdbOsOpen(pPager->dbFileName, O_RDWR | O_CREAT); if (pPager->fd < 0) { return -1; } @@ -90,7 +90,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { return -1; } - pPager->jfd = -1; + // pPager->jfd = -1; pPager->pageSize = tdbPCacheGetPageSize(pCache); *ppPager = pPager; @@ -168,7 +168,7 @@ int tdbPagerBegin(SPager *pPager) { } // Open the journal - pPager->jfd = tdbOsOpen(pPager->jFileName, O_RDWR | O_CREAT, 0755); + pPager->jfd = tdbOsOpen(pPager->jFileName, O_RDWR | O_CREAT); if (pPager->jfd < 0) { return -1; } @@ -210,7 +210,7 @@ int tdbPagerCommit(SPager *pPager) { tdbOsClose(pPager->jfd); remove(pPager->jFileName); - pPager->jfd = -1; + // pPager->jfd = -1; return 0; } diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index ac538341f1..12d81e3fcc 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -20,10 +20,10 @@ extern "C" { #endif -// TODO: kmake +// TODO: use cmake to control the option #define TDB_FOR_TDENGINE -// For memor +// For memory #ifdef TDB_FOR_TDENGINE #define tdbOsMalloc taosMemoryMalloc #define tdbOsCalloc taosMemoryCalloc @@ -36,8 +36,10 @@ extern "C" { #define tdbOsFree free #endif -// For file +// For file and directory #ifdef TDB_FOR_TDENGINE + +// file typedef TdFilePtr tdb_fd_t; #define tdbOsOpen taosOpenFile @@ -46,28 +48,42 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsPRead taosPReadFile #define tdbOsWrite taosWriteFile #define tdbOsFSync taosFsyncFile + +// directory +#define tdbOsMkdir taosMkDir +#define tdbOsRmdir taosRemoveDir + #else + +// file +typedef int tdb_fd_t; + #define tdbOsOpen open #define tdbOsClose close #define tdbOsRead read // TODO #define tdbOsPRead pread // TODO #define tdbOsWrite write // TODO #define tdbOsFSync fsync + +// directory +#define tdbOsMkdir mkdir +#define tdbOsRmdir rmdir + #endif // For threads and lock #ifdef TDB_FOR_TDENGINE -// spin lock +/* spin lock */ typedef TdThreadSpinlock tdb_spinlock_t; #define tdbSpinlockInit taosThreadSpinInit #define tdbSpinlockDestroy taosThreadSpinDestroy #define tdbSpinlockLock taosThreadSpinLock #define tdbSpinlockUnlock taosThreadSpinUnlock -#define tdbSpinlockTrylock pthread_spin_trylock // TODO +#define tdbSpinlockTrylock pthread_spin_trylock -// mutex lock +/* mutex lock */ typedef TdThreadMutex tdb_mutex_t; #define tdbMutexInit taosThreadMutexInit @@ -77,7 +93,7 @@ typedef TdThreadMutex tdb_mutex_t; #else -// spin lock +/* spin lock */ typedef pthread_spinlock_t tdb_spinlock_t; #define tdbSpinlockInit pthread_spin_init @@ -86,7 +102,7 @@ typedef pthread_spinlock_t tdb_spinlock_t; #define tdbSpinlockUnlock pthread_spin_unlock #define tdbSpinlockTrylock pthread_spin_trylock -// mutex lock +/* mutex lock */ typedef pthread_mutex_t tdb_mutex_t; #define tdbMutexInit pthread_mutex_init From ca8e40687e8e4f65512fcb9bf53ee9257bffd1d1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:13:59 +0000 Subject: [PATCH 110/149] more TDB --- source/libs/tdb/src/inc/tdbOs.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 12d81e3fcc..c737ed867d 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -25,21 +25,25 @@ extern "C" { // For memory #ifdef TDB_FOR_TDENGINE + #define tdbOsMalloc taosMemoryMalloc #define tdbOsCalloc taosMemoryCalloc #define tdbOsRealloc taosMemoryRealloc #define tdbOsFree taosMemoryFree + #else + #define tdbOsMalloc malloc #define tdbOsCalloc calloc #define tdbOsRealloc realloc #define tdbOsFree free + #endif // For file and directory #ifdef TDB_FOR_TDENGINE -// file +/* file */ typedef TdFilePtr tdb_fd_t; #define tdbOsOpen taosOpenFile @@ -49,13 +53,13 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsWrite taosWriteFile #define tdbOsFSync taosFsyncFile -// directory +/* directory */ #define tdbOsMkdir taosMkDir #define tdbOsRmdir taosRemoveDir #else -// file +/* file */ typedef int tdb_fd_t; #define tdbOsOpen open @@ -65,7 +69,7 @@ typedef int tdb_fd_t; #define tdbOsWrite write // TODO #define tdbOsFSync fsync -// directory +/* directory */ #define tdbOsMkdir mkdir #define tdbOsRmdir rmdir From b704fa2354bdddb78219a5d0f31a85835e911f32 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:33:25 +0000 Subject: [PATCH 111/149] more TDB --- source/libs/tdb/inc/tdb.h | 37 ------------------------------- source/libs/tdb/src/db/tdbPager.c | 8 +++---- source/libs/tdb/src/inc/tdbInt.h | 3 ++- source/libs/tdb/src/inc/tdbOs.h | 20 +++++++++-------- 4 files changed, 17 insertions(+), 51 deletions(-) diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 467e40325e..71ac3d97ed 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -22,43 +22,6 @@ extern "C" { #endif -// typedef struct STDb TDB; -// typedef struct STDbEnv TENV; -// typedef struct STDbCurosr TDBC; - -// typedef int32_t pgsz_t; -// typedef int32_t cachesz_t; - -// typedef int (*TdbKeyCmprFn)(int keyLen1, const void *pKey1, int keyLen2, const void *pKey2); - -// // TEVN -// int tdbEnvCreate(TENV **ppEnv, const char *rootDir); -// int tdbEnvOpen(TENV *ppEnv); -// int tdbEnvClose(TENV *pEnv); - -// int tdbEnvSetCache(TENV *pEnv, pgsz_t pgSize, cachesz_t cacheSize); -// pgsz_t tdbEnvGetPageSize(TENV *pEnv); -// cachesz_t tdbEnvGetCacheSize(TENV *pEnv); - -// int tdbEnvBeginTxn(TENV *pEnv); -// int tdbEnvCommit(TENV *pEnv); - -// // TDB -// int tdbCreate(TDB **ppDb); -// int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv); -// int tdbClose(TDB *pDb); -// int tdbDrop(TDB *pDb); - -// int tdbSetKeyLen(TDB *pDb, int klen); -// int tdbSetValLen(TDB *pDb, int vlen); -// int tdbSetDup(TDB *pDb, int dup); -// int tdbSetCmprFunc(TDB *pDb, TdbKeyCmprFn fn); -// int tdbGetKeyLen(TDB *pDb); -// int tdbGetValLen(TDB *pDb); -// int tdbGetDup(TDB *pDb); - -// int tdbInsert(TDB *pDb, const void *pKey, int nKey, const void *pData, int nData); - #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index b811fcb135..0abc64d0b0 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -377,12 +377,12 @@ static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) { pgno = TDB_PAGE_PGNO(pPage); - ret = tdbWrite(pPager->jfd, &pgno, sizeof(pgno)); + ret = tdbOsWrite(pPager->jfd, &pgno, sizeof(pgno)); if (ret < 0) { return -1; } - ret = tdbWrite(pPager->jfd, pPage->pData, pPage->pageSize); + ret = tdbOsWrite(pPager->jfd, pPage->pData, pPage->pageSize); if (ret < 0) { return -1; } @@ -395,12 +395,12 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) { int ret; offset = pPage->pageSize * TDB_PAGE_PGNO(pPage); - if (lseek(pPager->fd, offset, SEEK_SET) < 0) { + if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) { ASSERT(0); return -1; } - ret = tdbWrite(pPager->fd, pPage->pData, pPage->pageSize); + ret = tdbOsWrite(pPager->fd, pPage->pData, pPage->pageSize); if (ret < 0) { ASSERT(0); return -1; diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index c926d9358c..84c92f896c 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -16,10 +16,11 @@ #ifndef _TD_TDB_INTERNAL_H_ #define _TD_TDB_INTERNAL_H_ +#include "os.h" #include "tlist.h" #include "tlockfree.h" -// #include "tdb.h" +#include "tdb.h" #ifdef __cplusplus extern "C" { diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index c737ed867d..fd51136957 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -23,7 +23,7 @@ extern "C" { // TODO: use cmake to control the option #define TDB_FOR_TDENGINE -// For memory +// For memory ----------------- #ifdef TDB_FOR_TDENGINE #define tdbOsMalloc taosMemoryMalloc @@ -40,18 +40,19 @@ extern "C" { #endif -// For file and directory +// For file and directory ----------------- #ifdef TDB_FOR_TDENGINE /* file */ typedef TdFilePtr tdb_fd_t; -#define tdbOsOpen taosOpenFile -#define tdbOsClose taosCloseFile -#define tdbOsRead taosReadFile -#define tdbOsPRead taosPReadFile -#define tdbOsWrite taosWriteFile -#define tdbOsFSync taosFsyncFile +#define tdbOsOpen taosOpenFile +#define tdbOsClose(FD) taosCloseFile(&(FD)) +#define tdbOsRead taosReadFile +#define tdbOsPRead taosPReadFile +#define tdbOsWrite taosWriteFile +#define tdbOsFSync taosFsyncFile +#define tdbOsLSeek taosLSeekFile /* directory */ #define tdbOsMkdir taosMkDir @@ -68,6 +69,7 @@ typedef int tdb_fd_t; #define tdbOsPRead pread // TODO #define tdbOsWrite write // TODO #define tdbOsFSync fsync +#define tdbOsLSeek lseek /* directory */ #define tdbOsMkdir mkdir @@ -75,7 +77,7 @@ typedef int tdb_fd_t; #endif -// For threads and lock +// For threads and lock ----------------- #ifdef TDB_FOR_TDENGINE /* spin lock */ From 5c9c9695e5700b5e9fbadf1921163d9f59dc19e5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:41:27 +0000 Subject: [PATCH 112/149] more TDB --- source/libs/tdb/CMakeLists.txt | 1 + source/libs/tdb/src/db/tdbOs.c | 25 ++++++++++++++++++++++++- source/libs/tdb/src/inc/tdbOs.h | 8 +++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/CMakeLists.txt b/source/libs/tdb/CMakeLists.txt index 8612c9dc8f..0b1378dc5a 100644 --- a/source/libs/tdb/CMakeLists.txt +++ b/source/libs/tdb/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(tdb "src/db/tdbDb.c" "src/db/tdbEnv.c" "src/db/tdbTxn.c" + "src/db/tdbOs.c" "src/page/tdbPage.c" "src/page/tdbPageL.c" ) diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c index 6dea4a4e57..d8df761069 100644 --- a/source/libs/tdb/src/db/tdbOs.c +++ b/source/libs/tdb/src/db/tdbOs.c @@ -11,4 +11,27 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - */ \ No newline at end of file + */ + +#include "tdbInt.h" + +// tdbOsRead +i64 tdbOsRead(tdb_fd_t fd, void *pBuf, i64 nBytes) { + // TODO + ASSERT(0); + return 0; +} + +// tdbOsPRead +i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset) { + // TODO + ASSERT(0); + return 0; +} + +// tdbOsWrite +i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes) { + // TODO + ASSERT(0); + return 0; +} \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index fd51136957..851dd69c29 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -65,9 +65,11 @@ typedef int tdb_fd_t; #define tdbOsOpen open #define tdbOsClose close -#define tdbOsRead read // TODO -#define tdbOsPRead pread // TODO -#define tdbOsWrite write // TODO + +i64 tdbOsRead(tdb_fd_t fd, void *pBuf, i64 nBytes); +i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset); +i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes); + #define tdbOsFSync fsync #define tdbOsLSeek lseek From e0f192046c634431798a4989fef45551606efe55 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 11:47:39 +0800 Subject: [PATCH 113/149] multiple level stream schedule --- example/src/tstream.c | 2 +- include/client/taos.h | 4 +-- include/libs/stream/tstream.h | 3 +- source/client/src/tmq.c | 25 +++++++------- source/dnode/mgmt/vnode/src/vmWorker.c | 20 +++++++++++- source/dnode/mnode/impl/src/mndScheduler.c | 1 + source/dnode/vnode/src/tq/tq.c | 16 +++++---- source/dnode/vnode/src/vnd/vnodeQuery.c | 2 ++ source/libs/stream/src/tstream.c | 8 +++-- source/libs/wal/src/walMeta.c | 10 +++--- source/libs/wal/src/walSeek.c | 5 ++- tests/test/c/tmqDemo.c | 38 +++------------------- 12 files changed, 67 insertions(+), 67 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 51578bd27b..8ffa932bd2 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -25,7 +25,7 @@ int32_t init_env() { return -1; } - TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; diff --git a/include/client/taos.h b/include/client/taos.h index 55e1d1c422..dc54b89d04 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -217,7 +217,6 @@ DLL_EXPORT void tmq_list_destroy(tmq_list_t *); DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen); -DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); /* ------------------------TMQ CONSUMER INTERFACE------------------------ */ @@ -258,7 +257,8 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message); -DLL_EXPORT char *tmq_get_topic_schema(tmq_t *tmq, const char *topic); +DLL_EXPORT void *tmq_get_topic_schema(tmq_t *tmq, const char *topic); +DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); /* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 177fe39397..4efddde935 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -62,10 +62,11 @@ typedef struct { } STaskExec; typedef struct { - int8_t reserved; + int32_t taskId; } STaskDispatcherInplace; typedef struct { + int32_t taskId; int32_t nodeId; SEpSet epSet; } STaskDispatcherFixedEp; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 2a9b3cdf64..8eaca6853d 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -186,23 +186,23 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } } - if (strcmp(key, "connection.ip") == 0) { + if (strcmp(key, "td.connect.ip") == 0) { conf->ip = strdup(value); return TMQ_CONF_OK; } - if (strcmp(key, "connection.user") == 0) { + if (strcmp(key, "td.connect.user") == 0) { conf->user = strdup(value); return TMQ_CONF_OK; } - if (strcmp(key, "connection.pass") == 0) { + if (strcmp(key, "td.connect.pass") == 0) { conf->pass = strdup(value); return TMQ_CONF_OK; } - if (strcmp(key, "connection.port") == 0) { + if (strcmp(key, "td.connect.port") == 0) { conf->port = atoi(value); return TMQ_CONF_OK; } - if (strcmp(key, "connection.db") == 0) { + if (strcmp(key, "td.connect.db") == 0) { conf->db = strdup(value); return TMQ_CONF_OK; } @@ -223,13 +223,13 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) { } void tmq_list_destroy(tmq_list_t* list) { - SArray* container = (SArray*)list; + SArray* container = &list->container; /*taosArrayDestroy(container);*/ taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree); } void tmqClearUnhandleMsg(tmq_t* tmq) { - tmq_message_t* msg; + tmq_message_t* msg = NULL; while (1) { taosGetQitem(tmq->qall, (void**)&msg); if (msg) @@ -807,7 +807,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqClientVg* pVg = pParam->pVg; tmq_t* tmq = pParam->tmq; if (code != 0) { - printf("msg discard %x\n", code); + printf("msg discard, code:%x\n", code); goto WRITE_QUEUE_FAIL; } @@ -877,10 +877,10 @@ WRITE_QUEUE_FAIL: } bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { + printf("call update ep %d\n", epoch); bool set = false; int32_t sz = taosArrayGetSize(pRsp->topics); - if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics); - tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); + SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); for (int32_t i = 0; i < sz; i++) { SMqClientTopic topic = {0}; SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i); @@ -899,8 +899,10 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { taosArrayPush(topic.vgs, &clientVg); set = true; } - taosArrayPush(tmq->clientTopics, &topic); + taosArrayPush(newTopics, &topic); } + if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics); + tmq->clientTopics = newTopics; atomic_store_32(&tmq->epoch, epoch); return set; } @@ -1219,6 +1221,7 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese if (rspMsg->msg.head.epoch == atomic_load_32(&tmq->epoch)) { /*printf("epoch match\n");*/ SMqClientVg* pVg = rspMsg->vg; + /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ pVg->currentOffset = rspMsg->msg.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); return rspMsg; diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vnode/src/vmWorker.c index e97d6e7f11..7b6d78a60c 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vnode/src/vmWorker.c @@ -160,6 +160,24 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf } } +static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { + SVnodeObj *pVnode = pInfo->ahandle; + SNodeMsg *pMsg = NULL; + + for (int32_t i = 0; i < numOfMsgs; ++i) { + taosGetQitem(qall, (void **)&pMsg); + + dTrace("msg:%p, will be processed in vnode-merge queue", pMsg); + int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg); + if (code != 0) { + vmSendRsp(pVnode->pWrapper, pMsg, code); + dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + rpcFreeCont(pMsg->rpcMsg.pCont); + taosFreeQitem(pMsg); + } + } +} + static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueType qtype) { SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; @@ -308,7 +326,7 @@ int32_t vmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype) { int32_t vmAllocQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) { pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessWriteQueue); pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessApplyQueue); - pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeMsg); + pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeQueue); pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue); pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue); pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index a4dfd293de..69ee1a5696 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -185,6 +185,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC; pTask->dispatchType = TASK_DISPATCH__FIXED; + pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId; pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId; pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 91cbc2cff8..4661668cbe 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -42,8 +42,8 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STq // TODO: error code of buffer pool } #endif - pTq->tqMeta = - tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, (FTqDelete)taosMemoryFree, 0); + pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, + (FTqDelete)taosMemoryFree, 0); if (pTq->tqMeta == NULL) { taosMemoryFree(pTq); #if 0 @@ -498,12 +498,16 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { } int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) { - SStreamTaskExecReq* pReq = msg->pCont; - int32_t taskId = pReq->taskId; - SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + char* msgstr = POINTER_SHIFT(msg->pCont, sizeof(SMsgHead)); + + SStreamTaskExecReq req; + tDecodeSStreamTaskExecReq(msgstr, &req); + + int32_t taskId = req.taskId; + SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); ASSERT(pTask); - if (streamExecTask(pTask, &pTq->pVnode->msgCb, pReq->data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) { + if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) { // TODO } return 0; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 1db17f37cb..94e183f525 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -66,6 +66,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { case TDMT_VND_CONSUME: return tqProcessPollReq(pVnode->pTq, pMsg); case TDMT_VND_TASK_EXEC: + case TDMT_VND_TASK_PIPE_EXEC: + case TDMT_VND_TASK_MERGE_EXEC: return tqProcessTaskExec(pVnode->pTq, pMsg); case TDMT_VND_STREAM_TRIGGER: return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 3ec6603673..31a06a9d9a 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -121,7 +121,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { SStreamTaskExecReq req = { .streamId = pTask->streamId, - .taskId = pTask->taskId, + .taskId = pTask->fixedEpDispatcher.taskId, .data = pRes, }; @@ -211,8 +211,9 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { } if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - if (tEncodeI8(pEncoder, pTask->inplaceDispatcher.reserved) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->inplaceDispatcher.taskId) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.taskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { @@ -248,8 +249,9 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { } if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - if (tDecodeI8(pDecoder, &pTask->inplaceDispatcher.reserved) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->inplaceDispatcher.taskId) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 83c48628a3..36323cdffa 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -19,13 +19,13 @@ #include "tref.h" #include "walInt.h" -int64_t inline walGetFirstVer(SWal* pWal) { return pWal->vers.firstVer; } +int64_t FORCE_INLINE walGetFirstVer(SWal* pWal) { return pWal->vers.firstVer; } -int64_t inline walGetSnaphostVer(SWal* pWal) { return pWal->vers.snapshotVer; } +int64_t FORCE_INLINE walGetSnaphostVer(SWal* pWal) { return pWal->vers.snapshotVer; } -int64_t inline walGetLastVer(SWal* pWal) { return pWal->vers.lastVer; } +int64_t FORCE_INLINE walGetLastVer(SWal* pWal) { return pWal->vers.lastVer; } -static inline int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { +static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { return sprintf(buf, "%s/meta-ver%d", pWal->path, metaVer); } @@ -46,7 +46,7 @@ void* tmemmem(char* haystack, int hlen, char* needle, int nlen) { return NULL; } -static inline int64_t walScanLogGetLastVer(SWal* pWal) { +static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { ASSERT(pWal->fileInfoSet != NULL); int sz = taosArrayGetSize(pWal->fileInfoSet); ASSERT(sz > 0); diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index 140b7ddc32..413dcb47f0 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -74,9 +74,9 @@ int walSetWrite(SWal* pWal) { } int walChangeWrite(SWal* pWal, int64_t ver) { - int code = 0; + int code; TdFilePtr pIdxTFile, pLogTFile; - char fnameStr[WAL_FILE_LEN]; + char fnameStr[WAL_FILE_LEN]; if (pWal->pWriteLogTFile != NULL) { code = taosCloseFile(&pWal->pWriteLogTFile); if (code != 0) { @@ -133,7 +133,6 @@ int walSeekWriteVer(SWal* pWal, int64_t ver) { return -1; } if (ver < pWal->vers.snapshotVer) { - } if (ver < walGetCurFileFirstVer(pWal) || (ver > walGetCurFileLastVer(pWal))) { code = walChangeWrite(pWal, ver); diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 1690a5fb3e..fd362e9705 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -314,7 +314,7 @@ int32_t init_env() { } //const char* sql = "select * from tu1"; - sprintf(sqlStr, "create topic test_stb_topic_1 as select * from %s0", g_stConfInfo.stbName); + sprintf(sqlStr, "create topic test_stb_topic_1 as select ts,c0 from %s", g_stConfInfo.stbName); /*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sqlStr, strlen(sqlStr));*/ pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { @@ -351,36 +351,6 @@ tmq_list_t* build_topic_list() { return topic_list; } -void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { - tmq_resp_err_t err; - - if ((err = tmq_subscribe(tmq, topics))) { - fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); - printf("subscribe err\n"); - return; - } - int32_t cnt = 0; - /*clock_t startTime = clock();*/ - while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); - if (tmqmessage) { - cnt++; - msg_process(tmqmessage); - tmq_message_destroy(tmqmessage); - /*} else {*/ - /*break;*/ - } - } - /*clock_t endTime = clock();*/ - /*printf("log cnt: %d %f s\n", cnt, (double)(endTime - startTime) / CLOCKS_PER_SEC);*/ - - err = tmq_consumer_close(tmq); - if (err) - fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); - else - fprintf(stderr, "%% Consumer closed\n"); -} - void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { static const int MIN_COMMIT_COUNT = 1000; @@ -438,7 +408,7 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog if (batchCnt != totalMsgs) { printf("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC); - exit(-1); + /*exit(-1);*/ } if (0 == g_stConfInfo.simCase) { @@ -693,8 +663,8 @@ int main(int32_t argc, char *argv[]) { walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); if (walLogSize <= 0) { - printf("vnode2/wal size incorrect!"); - /*exit(-1);*/ + printf("vnode2/wal size incorrect!\n"); + /*exit(-1);*/ } else { if (0 == g_stConfInfo.simCase) { pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize/(1024 * 1024.0)); From 5f90bae8bbce6eaef907a084d8e60fce979fdd47 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:51:02 +0000 Subject: [PATCH 114/149] more TDB --- source/libs/tdb/src/db/tdbOs.c | 40 ++++++++++++++++++++++--- source/libs/tdb/src/db/tdbPager.c | 2 +- source/libs/tdb/src/db/tdbUtil.c | 50 +------------------------------ source/libs/tdb/src/inc/tdbOs.h | 10 ++++--- source/libs/tdb/src/inc/tdbUtil.h | 16 +++------- 5 files changed, 48 insertions(+), 70 deletions(-) diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c index d8df761069..210d582b92 100644 --- a/source/libs/tdb/src/db/tdbOs.c +++ b/source/libs/tdb/src/db/tdbOs.c @@ -31,7 +31,39 @@ i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset) { // tdbOsWrite i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes) { - // TODO - ASSERT(0); - return 0; -} \ No newline at end of file + // TODO + ASSERT(0); + return 0; +} + +#if 0 +int tdbPRead(int fd, void *pData, int count, i64 offset) { + void *pBuf; + int nbytes; + i64 ioffset; + int iread; + + pBuf = pData; + nbytes = count; + ioffset = offset; + while (nbytes > 0) { + iread = pread(fd, pBuf, nbytes, ioffset); + if (iread < 0) { + /* TODO */ + } else if (iread == 0) { + return (count - iread); + } + + nbytes = nbytes - iread; + pBuf = (void *)((u8 *)pBuf + iread); + ioffset += iread; + } + + return count; +} + +int tdbWrite(int fd, void *pData, int count) { + // TODO + return write(fd, pData, count); +} +#endif \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 0abc64d0b0..4fac00d5ad 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -209,7 +209,7 @@ int tdbPagerCommit(SPager *pPager) { tdbOsFSync(pPager->fd); tdbOsClose(pPager->jfd); - remove(pPager->jFileName); + tdbOsRemove(pPager->jFileName); // pPager->jfd = -1; return 0; diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index e7de0a859a..4abc890f94 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -33,28 +33,10 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { return 0; } -// int tdbCheckFileAccess(const char *pathname, int mode) { -// int flags = 0; - -// if (mode & TDB_F_OK) { -// flags |= F_OK; -// } - -// if (mode & TDB_R_OK) { -// flags |= R_OK; -// } - -// if (mode & TDB_W_OK) { -// flags |= W_OK; -// } - -// return access(pathname, flags); -// } - int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize) { struct stat st; int ret; - int64_t file_size = 0; + int64_t file_size = 0; ret = taosStatFile(fname, &file_size, NULL); if (ret != 0) { return -1; @@ -64,34 +46,4 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize) { *pSize = file_size / pgSize; return 0; -} - -int tdbPRead(int fd, void *pData, int count, i64 offset) { - void *pBuf; - int nbytes; - i64 ioffset; - int iread; - - pBuf = pData; - nbytes = count; - ioffset = offset; - while (nbytes > 0) { - iread = pread(fd, pBuf, nbytes, ioffset); - if (iread < 0) { - /* TODO */ - } else if (iread == 0) { - return (count - iread); - } - - nbytes = nbytes - iread; - pBuf = (void *)((u8 *)pBuf + iread); - ioffset += iread; - } - - return count; -} - -int tdbWrite(int fd, void *pData, int count) { - // TODO - return write(fd, pData, count); } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 851dd69c29..98a4a190e0 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -53,6 +53,7 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsWrite taosWriteFile #define tdbOsFSync taosFsyncFile #define tdbOsLSeek taosLSeekFile +#define tdbOsRemove remove /* directory */ #define tdbOsMkdir taosMkDir @@ -70,12 +71,13 @@ i64 tdbOsRead(tdb_fd_t fd, void *pBuf, i64 nBytes); i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset); i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes); -#define tdbOsFSync fsync -#define tdbOsLSeek lseek +#define tdbOsFSync fsync +#define tdbOsLSeek lseek +#define tdbOsRemove remove /* directory */ -#define tdbOsMkdir mkdir -#define tdbOsRmdir rmdir +#define tdbOsMkdir mkdir +#define tdbOsRmdir rmdir #endif diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 0633d4e48b..6e6faf9b74 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -30,16 +30,8 @@ extern "C" { int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); -// #define TDB_F_OK 0x1 -// #define TDB_R_OK 0x2 -// #define TDB_W_OK 0x4 -// int tdbCheckFileAccess(const char *pathname, int mode); - int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); -int tdbPRead(int fd, void *pData, int count, i64 offset); -int tdbWrite(int fd, void *pData, int count); - #define TDB_REALLOC(PTR, SIZE) \ ({ \ void *nPtr; \ @@ -55,11 +47,11 @@ int tdbWrite(int fd, void *pData, int count); nPtr; \ }) -#define TDB_FREE(PTR) \ - do { \ - if (PTR) { \ +#define TDB_FREE(PTR) \ + do { \ + if (PTR) { \ tdbOsFree((char *)(PTR) - sizeof(int)); \ - } \ + } \ } while (0) static inline void *tdbDefaultMalloc(void *arg, size_t size) { From 54ca6c4e8cd06c390a9df303cfd3446983f6addd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 03:55:37 +0000 Subject: [PATCH 115/149] make TDB can compile --- source/libs/tdb/src/db/tdbUtil.c | 15 --------------- source/libs/tdb/src/inc/tdbUtil.h | 2 -- 2 files changed, 17 deletions(-) diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index 4abc890f94..fc299b3fc1 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -30,20 +30,5 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { ((uint64_t *)fileid)[2] = taosRand(); } - return 0; -} - -int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize) { - struct stat st; - int ret; - int64_t file_size = 0; - ret = taosStatFile(fname, &file_size, NULL); - if (ret != 0) { - return -1; - } - - ASSERT(file_size % pgSize == 0); - - *pSize = file_size / pgSize; return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index 6e6faf9b74..c06d9d18c9 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -30,8 +30,6 @@ extern "C" { int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); -int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); - #define TDB_REALLOC(PTR, SIZE) \ ({ \ void *nPtr; \ From a942717855cb75931b8617f533ab2a703e6ff326 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 28 Mar 2022 11:56:01 +0800 Subject: [PATCH 116/149] [del walSize check] --- tests/test/c/tmqDemo.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 1690a5fb3e..63a3962d0e 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -691,12 +691,12 @@ int main(int32_t argc, char *argv[]) { float rowsSpeed = totalRows / seconds; float msgsSpeed = totalMsgs / seconds; - walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); - if (walLogSize <= 0) { - printf("vnode2/wal size incorrect!"); - /*exit(-1);*/ - } else { - if (0 == g_stConfInfo.simCase) { + if (0 == g_stConfInfo.simCase) { + walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); + if (walLogSize <= 0) { + printf("%s size incorrect!", g_stConfInfo.vnodeWalPath); + exit(-1); + } else { pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize/(1024 * 1024.0)); } } From 47fe8bd902c5547bf6d041fc28aa71fdedb983ae Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 28 Mar 2022 13:32:13 +0800 Subject: [PATCH 117/149] [modify] --- tests/script/tsim/tmq/basic.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/tmq/basic.sim b/tests/script/tsim/tmq/basic.sim index 876cf7e266..1eeec46d53 100644 --- a/tests/script/tsim/tmq/basic.sim +++ b/tests/script/tsim/tmq/basic.sim @@ -45,7 +45,7 @@ print cmd===> system_content ../../debug/tests/test/c/tmq_demo -sim 1 -b 100 -c system_content ../../debug/tests/test/c/tmq_demo -sim 1 -b 100 -c ../../sim/tsim/cfg -w ../../sim/dnode1/data/vnode/vnode4/wal print cmd result----> $system_content if $system_content != @{consume success: 100}@ then - print not match in pos000 + return -1 endi sql show databases From c1ce323ad0ba75ec7a2b8ad1a80d4faeb78f6d7e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 13:35:36 +0800 Subject: [PATCH 118/149] create usser --- include/common/tmsg.h | 4 ++-- source/dnode/mnode/impl/src/mndUser.c | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bdb6181884..f224f6d94c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -363,7 +363,7 @@ typedef struct { int8_t createType; int8_t superUser; // denote if it is a super user or not char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_USET_PASSWORD_LEN]; } SCreateUserReq; int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq); @@ -373,7 +373,7 @@ typedef struct { int8_t alterType; int8_t superUser; char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; + char pass[TSDB_USET_PASSWORD_LEN]; char dbname[TSDB_DB_FNAME_LEN]; } SAlterUserReq; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 7d3f755cd7..469805387f 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -87,12 +87,6 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) { return -1; } -#if 0 - if (mndCreateDefaultUser(pMnode, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { - return -1; - } -#endif - return 0; } From 4c43901c44f371fa4ce8aea6d3883f83cc27f9d4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 05:40:54 +0000 Subject: [PATCH 119/149] more TDB --- source/libs/tdb/src/db/tdbOs.c | 101 ++++++++++++++++++++------------ source/libs/tdb/src/inc/tdbOs.h | 8 +-- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c index 210d582b92..e52f788da9 100644 --- a/source/libs/tdb/src/db/tdbOs.c +++ b/source/libs/tdb/src/db/tdbOs.c @@ -15,55 +15,84 @@ #include "tdbInt.h" +#ifndef TDB_FOR_TDENGINE + // tdbOsRead -i64 tdbOsRead(tdb_fd_t fd, void *pBuf, i64 nBytes) { - // TODO - ASSERT(0); - return 0; +i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes) { + i64 nRead = 0; + i64 iRead = 0; + u8 *pBuf = (u8 *)pData; + + while (nBytes > 0) { + iRead = read(fd, pBuf, nBytes); + if (iRead < 0) { + if (errno == EINTR) { + continue; + } else { + return -1; + } + } else if (iRead == 0) { + break; + } + + nRead += iRead; + pBuf += iRead; + nBytes -= iRead; + } + + return nRead; } // tdbOsPRead -i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset) { - // TODO - ASSERT(0); - return 0; +i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset) { + i64 nRead = 0; + i64 iRead = 0; + i64 iOffset = offset; + u8 *pBuf = (u8 *)pData; + + while (nBytes > 0) { + iRead = pread(fd, pBuf, nBytes, iOffset); + if (iRead < 0) { + if (errno == EINTR) { + continue; + } else { + return -1; + } + } else if (iRead == 0) { + break; + } + + nRead += iRead; + pBuf += iRead; + iOffset += iRead; + nBytes -= iRead; + } + + return nRead; } // tdbOsWrite -i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes) { - // TODO - ASSERT(0); - return 0; -} +i64 taosWriteFile(tdb_fd_t fd, const void *pData, i64 nBytes) { + i64 nWrite = 0; + i64 iWrite = 0; + u8 *pBuf = (u8 *)pData; -#if 0 -int tdbPRead(int fd, void *pData, int count, i64 offset) { - void *pBuf; - int nbytes; - i64 ioffset; - int iread; + while (nBytes > 0) { + iWrite = write(fd, pBuf, nBytes); + if (iWrite < 0) { + if (errno == EINTR) { + continue; + } - pBuf = pData; - nbytes = count; - ioffset = offset; - while (nbytes > 0) { - iread = pread(fd, pBuf, nbytes, ioffset); - if (iread < 0) { - /* TODO */ - } else if (iread == 0) { - return (count - iread); + return -1; } - nbytes = nbytes - iread; - pBuf = (void *)((u8 *)pBuf + iread); - ioffset += iread; + nWrite += iWrite; + pBuf += iWrite; + nBytes -= iWrite; } - return count; + return nWrite; } -int tdbWrite(int fd, void *pData, int count) { - // TODO - return write(fd, pData, count); -} #endif \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 98a4a190e0..b8ae85ea65 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -21,7 +21,7 @@ extern "C" { #endif // TODO: use cmake to control the option -#define TDB_FOR_TDENGINE +// #define TDB_FOR_TDENGINE // For memory ----------------- #ifdef TDB_FOR_TDENGINE @@ -67,9 +67,9 @@ typedef int tdb_fd_t; #define tdbOsOpen open #define tdbOsClose close -i64 tdbOsRead(tdb_fd_t fd, void *pBuf, i64 nBytes); -i64 tdbOsPRead(tdb_fd_t fd, void *pBuf, i64 nBytes, i64 offset); -i64 taosWriteFile(tdb_fd_t fd, const void *pBuf, i64 nBytes); +i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes); +i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset); +i64 taosWriteFile(tdb_fd_t fd, const void *pData, i64 nBytes); #define tdbOsFSync fsync #define tdbOsLSeek lseek From b23d2c7b6ec3c3e9a332390f52c426d82b38c682 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 05:44:03 +0000 Subject: [PATCH 120/149] make TDB can compile --- source/libs/tdb/src/db/tdbOs.c | 2 +- source/libs/tdb/src/inc/tdbOs.h | 4 ++-- source/libs/tdb/test/tdbTest.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c index e52f788da9..5ca3578985 100644 --- a/source/libs/tdb/src/db/tdbOs.c +++ b/source/libs/tdb/src/db/tdbOs.c @@ -72,7 +72,7 @@ i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset) { } // tdbOsWrite -i64 taosWriteFile(tdb_fd_t fd, const void *pData, i64 nBytes) { +i64 tdbOsWrite(tdb_fd_t fd, const void *pData, i64 nBytes) { i64 nWrite = 0; i64 iWrite = 0; u8 *pBuf = (u8 *)pData; diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index b8ae85ea65..751c105913 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -21,7 +21,7 @@ extern "C" { #endif // TODO: use cmake to control the option -// #define TDB_FOR_TDENGINE +#define TDB_FOR_TDENGINE // For memory ----------------- #ifdef TDB_FOR_TDENGINE @@ -69,7 +69,7 @@ typedef int tdb_fd_t; i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes); i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset); -i64 taosWriteFile(tdb_fd_t fd, const void *pData, i64 nBytes); +i64 tdbOsWrite(tdb_fd_t fd, const void *pData, i64 nBytes); #define tdbOsFSync fsync #define tdbOsLSeek lseek diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 6889e33902..e8c6477de0 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -11,7 +11,7 @@ typedef struct SPoolMem { } SPoolMem; static SPoolMem *openPool() { - SPoolMem *pPool = (SPoolMem *)malloc(sizeof(*pPool)); + SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool)); pPool->prev = pPool->next = pPool; pPool->size = 0; @@ -31,12 +31,12 @@ static void closePool(SPoolMem *pPool) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - free(pMem); + tdbOsFree(pMem); } while (1); assert(pPool->size == 0); - free(pPool); + tdbOsFree(pPool); } #define clearPool closePool @@ -46,7 +46,7 @@ static void *poolMalloc(void *arg, int size) { SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pMem; - pMem = (SPoolMem *)malloc(sizeof(*pMem) + size); + pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size); if (pMem == NULL) { assert(0); } @@ -73,7 +73,7 @@ static void poolFree(void *arg, void *ptr) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - free(pMem); + tdbOsFree(pMem); } static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { From 0a602259fcebea5ddf5524bca4769578c4e6bad7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 06:06:34 +0000 Subject: [PATCH 121/149] more TDB --- source/libs/tdb/src/db/tdbDb.c | 26 +++++++++++++------------- source/libs/tdb/src/inc/tdbDb.h | 24 ++++++++++++------------ source/libs/tdb/src/inc/tdbInt.h | 13 ------------- source/libs/tdb/test/tdbTest.cpp | 12 ++++++------ 4 files changed, 31 insertions(+), 44 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 499116f091..01e457663c 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -24,8 +24,8 @@ struct STDBC { SBTC btc; }; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) { - STDB *pDb; +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, TDB **ppDb) { + TDB *pDb; SPager *pPager; int ret; char fFullName[TDB_FILENAME_LEN]; @@ -34,7 +34,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF *ppDb = NULL; - pDb = (STDB *)tdbOsCalloc(1, sizeof(*pDb)); + pDb = (TDB *)tdbOsCalloc(1, sizeof(*pDb)); if (pDb == NULL) { return -1; } @@ -63,17 +63,17 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF return 0; } -int tdbDbClose(STDB *pDb) { +int tdbDbClose(TDB *pDb) { // TODO return 0; } -int tdbDbDrop(STDB *pDb) { +int tdbDbDrop(TDB *pDb) { // TODO return 0; } -int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { +int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { SBTC btc; SBTC *pCur; int ret; @@ -92,16 +92,16 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v return 0; } -int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { +int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); } -int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { - int ret; - STDBC *pDbc = NULL; +int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) { + int ret; + TDBC *pDbc = NULL; *ppDbc = NULL; - pDbc = (STDBC *)tdbOsMalloc(sizeof(*pDbc)); + pDbc = (TDBC *)tdbOsMalloc(sizeof(*pDbc)); if (pDbc == NULL) { return -1; } @@ -120,11 +120,11 @@ int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { return 0; } -int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { +int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen); } -int tdbDbcClose(STDBC *pDbc) { +int tdbDbcClose(TDBC *pDbc) { if (pDbc) { tdbOsFree(pDbc); } diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index b96076b826..8b9fad96b5 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -20,20 +20,20 @@ extern "C" { #endif -typedef struct STDB STDB; -typedef struct STDBC STDBC; +typedef struct STDB TDB; +typedef struct STDBC TDBC; -// STDB -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb); -int tdbDbClose(STDB *pDb); -int tdbDbDrop(STDB *pDb); -int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); -int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); +// TDB +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, TDB **ppDb); +int tdbDbClose(TDB *pDb); +int tdbDbDrop(TDB *pDb); +int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); +int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); -// STDBC -int tdbDbcOpen(STDB *pDb, STDBC **ppDbc); -int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); -int tdbDbcClose(STDBC *pDbc); +// TDBC +int tdbDbcOpen(TDB *pDb, TDBC **ppDbc); +int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbDbcClose(TDBC *pDbc); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 84c92f896c..9ae424a6b6 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -116,19 +116,6 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode; #define TDB_VARIANT_LEN ((int)-1) -// page payload format -// + + [key] + [value] -#define TDB_DECODE_PAYLOAD(pPayload, keyLen, pKey, valLen, pVal) \ - do { \ - if ((keyLen) == TDB_VARIANT_LEN) { \ - /* TODO: decode the keyLen */ \ - } \ - if ((valLen) == TDB_VARIANT_LEN) { \ - /* TODO: decode the valLen */ \ - } \ - /* TODO */ \ - } while (0) - typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2); #define TDB_JOURNAL_NAME "tdb.journal" diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index e8c6477de0..19d61a6cdf 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -116,7 +116,7 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in TEST(tdb_test, simple_test) { int ret; STEnv *pEnv; - STDB *pDb; + TDB *pDb; FKeyComparator compFunc; int nData = 1000000; @@ -183,11 +183,11 @@ TEST(tdb_test, simple_test) { } { // Iterate to query the DB data - STDBC *pDBC; - void *pKey = NULL; - void *pVal = NULL; - int vLen, kLen; - int count = 0; + TDBC *pDBC; + void *pKey = NULL; + void *pVal = NULL; + int vLen, kLen; + int count = 0; ret = tdbDbcOpen(pDb, &pDBC); GTEST_ASSERT_EQ(ret, 0); From 4fed357adf5c78d4f205a8ae13a2a2b74af69874 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 06:12:14 +0000 Subject: [PATCH 122/149] refact TDB --- source/libs/tdb/src/inc/tdbInt.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 9ae424a6b6..361a460cef 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -17,8 +17,6 @@ #define _TD_TDB_INTERNAL_H_ #include "os.h" -#include "tlist.h" -#include "tlockfree.h" #include "tdb.h" @@ -52,18 +50,18 @@ typedef u32 SPgno; // fileid #define TDB_FILE_ID_LEN 24 -// pgid_t +// SPgid typedef struct { uint8_t fileid[TDB_FILE_ID_LEN]; SPgno pgno; -} pgid_t, SPgid; +} SPgid; -#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO}; +#define TDB_IVLD_PGID (SPgid){0, TDB_IVLD_PGNO}; static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { - pgid_t *pgid1 = (pgid_t *)p1; - pgid_t *pgid2 = (pgid_t *)p2; - int rcode; + SPgid *pgid1 = (SPgid *)p1; + SPgid *pgid2 = (SPgid *)p2; + int rcode; rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN); if (rcode) { @@ -96,10 +94,6 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { // tdb_log #define tdbError(var) -typedef TD_DLIST(STDB) STDbList; -typedef TD_DLIST(SPgFile) SPgFileList; -typedef TD_DLIST_NODE(SPgFile) SPgFileListNode; - #define TERR_A(val, op, flag) \ do { \ if (((val) = (op)) != 0) { \ From 3934427cbe125cad8acc824772fb933fb47fb20e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 06:15:52 +0000 Subject: [PATCH 123/149] refact TDB --- source/libs/tdb/src/db/tdbDb.c | 4 ++-- source/libs/tdb/src/db/tdbEnv.c | 18 +++++++++--------- source/libs/tdb/src/db/tdbTxn.c | 6 +++--- source/libs/tdb/src/inc/tdbDb.h | 2 +- source/libs/tdb/src/inc/tdbEnv.h | 12 ++++++------ source/libs/tdb/src/inc/tdbTxn.h | 6 +++--- source/libs/tdb/test/tdbTest.cpp | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 01e457663c..1a66306b15 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -16,7 +16,7 @@ #include "tdbInt.h" struct STDB { - STEnv *pEnv; + TEnv *pEnv; SBTree *pBt; }; @@ -24,7 +24,7 @@ struct STDBC { SBTC btc; }; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, TDB **ppDb) { +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TEnv *pEnv, TDB **ppDb) { TDB *pDb; SPager *pPager; int ret; diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index ad3b5c41f2..1fb2486a2b 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -15,12 +15,12 @@ #include "tdbInt.h" -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) { - STEnv *pEnv; - int dsize; - int zsize; - u8 *pPtr; - int ret; +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv) { + TEnv *pEnv; + int dsize; + int zsize; + u8 *pPtr; + int ret; *ppEnv = NULL; @@ -32,7 +32,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) return -1; } - pEnv = (STEnv *)pPtr; + pEnv = (TEnv *)pPtr; pPtr += sizeof(*pEnv); // pEnv->rootDir pEnv->rootDir = pPtr; @@ -59,12 +59,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) return 0; } -int tdbEnvClose(STEnv *pEnv) { +int tdbEnvClose(TEnv *pEnv) { // TODO return 0; } -SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname) { +SPager *tdbEnvGetPager(TEnv *pEnv, const char *fname) { // TODO return NULL; } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbTxn.c b/source/libs/tdb/src/db/tdbTxn.c index 1a2dfc77cd..5c7ac0678e 100644 --- a/source/libs/tdb/src/db/tdbTxn.c +++ b/source/libs/tdb/src/db/tdbTxn.c @@ -15,17 +15,17 @@ #include "tdbInt.h" -int tdbTxnBegin(STEnv *pEnv) { +int tdbTxnBegin(TEnv *pEnv) { // TODO return 0; } -int tdbTxnCommit(STEnv *pEnv) { +int tdbTxnCommit(TEnv *pEnv) { // TODO return 0; } -int tdbTxnRollback(STEnv *pEnv) { +int tdbTxnRollback(TEnv *pEnv) { // TODO return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index 8b9fad96b5..bbeabf4d3e 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -24,7 +24,7 @@ typedef struct STDB TDB; typedef struct STDBC TDBC; // TDB -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, TDB **ppDb); +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TEnv *pEnv, TDB **ppDb); int tdbDbClose(TDB *pDb); int tdbDbDrop(TDB *pDb); int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 959b963a07..80ee2e8b07 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -21,16 +21,16 @@ extern "C" { #endif typedef struct STEnv { - char * rootDir; - char * jfname; + char *rootDir; + char *jfname; int jfd; SPCache *pCache; -} STEnv; +} TEnv; -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv); -int tdbEnvClose(STEnv *pEnv); +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv); +int tdbEnvClose(TEnv *pEnv); -SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname); +SPager *tdbEnvGetPager(TEnv *pEnv, const char *fname); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h index 88d469ac34..06b31879de 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -28,9 +28,9 @@ struct STxn { void *xArg; }; -int tdbTxnBegin(STEnv *pEnv); -int tdbTxnCommit(STEnv *pEnv); -int tdbTxnRollback(STEnv *pEnv); +int tdbTxnBegin(TEnv *pEnv); +int tdbTxnCommit(TEnv *pEnv); +int tdbTxnRollback(TEnv *pEnv); #ifdef __cplusplus } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 19d61a6cdf..f4a170f2c0 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -115,7 +115,7 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in TEST(tdb_test, simple_test) { int ret; - STEnv *pEnv; + TEnv *pEnv; TDB *pDb; FKeyComparator compFunc; int nData = 1000000; From 90e4cab2af624ecb5e3680d4bf8b203c4157444e Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 14:16:58 +0800 Subject: [PATCH 124/149] fix stream serialization --- include/common/tmsgdef.h | 1 - source/dnode/mgmt/vnode/src/vmMsg.c | 1 - source/dnode/mnode/impl/src/mndDef.c | 17 +++++++++-------- source/dnode/vnode/src/inc/vnd.h | 2 +- source/dnode/vnode/src/tq/tq.c | 6 ++---- source/dnode/vnode/src/vnd/vnodeQuery.c | 5 +++-- source/dnode/vnode/src/vnd/vnodeWrite.c | 5 +++++ source/libs/stream/src/tstream.c | 21 ++++++++++++++++++--- 8 files changed, 38 insertions(+), 20 deletions(-) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 051ee34644..36a489eb59 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -192,7 +192,6 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp) TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqCVConsumeReq, SMqCVConsumeRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) - TD_DEF_MSG_TYPE(TDMT_VND_TASK_EXEC, "vnode-task-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_PIPE_EXEC, "vnode-task-pipe-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_MERGE_EXEC, "vnode-task-merge-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_WRITE_EXEC, "vnode-task-write-exec", SStreamTaskExecReq, SStreamTaskExecRsp) diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index 97d829571f..1682c6043d 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -279,7 +279,6 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 24f2a5df22..1b3564924a 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -36,11 +36,11 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { if (tEncodeI32(pEncoder, sz) < 0) return -1; for (int32_t i = 0; i < sz; i++) { - SArray *pArray = taosArrayGet(pObj->tasks, i); + SArray *pArray = taosArrayGetP(pObj->tasks, i); int32_t innerSz = taosArrayGetSize(pArray); if (tEncodeI32(pEncoder, innerSz) < 0) return -1; for (int32_t j = 0; j < innerSz; j++) { - SStreamTask *pTask = taosArrayGet(pArray, j); + SStreamTask *pTask = taosArrayGetP(pArray, j); if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1; } } @@ -76,17 +76,18 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { int32_t sz; if (tDecodeI32(pDecoder, &sz) < 0) return -1; if (sz != 0) { - pObj->tasks = taosArrayInit(sz, sizeof(SArray)); + pObj->tasks = taosArrayInit(sz, sizeof(void *)); for (int32_t i = 0; i < sz; i++) { int32_t innerSz; if (tDecodeI32(pDecoder, &innerSz) < 0) return -1; - SArray *pArray = taosArrayInit(innerSz, sizeof(SStreamTask)); + SArray *pArray = taosArrayInit(innerSz, sizeof(void *)); for (int32_t j = 0; j < innerSz; j++) { - SStreamTask task; - if (tDecodeSStreamTask(pDecoder, &task) < 0) return -1; - taosArrayPush(pArray, &task); + SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); + if (pTask == NULL) return -1; + if (tDecodeSStreamTask(pDecoder, pTask) < 0) return -1; + taosArrayPush(pArray, &pTask); } - taosArrayPush(pObj->tasks, pArray); + taosArrayPush(pObj->tasks, &pArray); } } diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 8d256995c6..3309686bb7 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -198,7 +198,7 @@ int tqCommit(STQ*); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg); -int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); +int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 4661668cbe..c354b01501 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -497,11 +497,9 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { return 0; } -int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) { - char* msgstr = POINTER_SHIFT(msg->pCont, sizeof(SMsgHead)); - +int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { SStreamTaskExecReq req; - tDecodeSStreamTaskExecReq(msgstr, &req); + tDecodeSStreamTaskExecReq(msg, &req); int32_t taskId = req.taskId; SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 94e183f525..74d7558e0d 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -43,6 +43,8 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { vTrace("message in fetch queue is processing"); + char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); switch (pMsg->msgType) { case TDMT_VND_FETCH: return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); @@ -65,10 +67,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { return vnodeGetTableMeta(pVnode, pMsg); case TDMT_VND_CONSUME: return tqProcessPollReq(pVnode->pTq, pMsg); - case TDMT_VND_TASK_EXEC: case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_MERGE_EXEC: - return tqProcessTaskExec(pVnode->pTq, pMsg); + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen); case TDMT_VND_STREAM_TRIGGER: return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); case TDMT_VND_QUERY_HEARTBEAT: diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index a14828cc22..279926747f 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -167,6 +167,11 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pMsg->contLen - sizeof(SMsgHead)) < 0) { } } break; + case TDMT_VND_TASK_WRITE_EXEC: { + if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), + pMsg->contLen - sizeof(SMsgHead)) < 0) { + } + } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA #if 0 SSmaCfg vCreateSmaReq = {0}; diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 31a06a9d9a..6d69a8960e 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -205,9 +205,16 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; } - if (pTask->sinkType != TASK_SINK__NONE) { - // TODO: wrap + if (pTask->sinkType == TASK_SINK__TABLE) { if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SMA) { + if (tEncodeI8(pEncoder, pTask->smaSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__FETCH) { + if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SHOW) { + if (tEncodeI8(pEncoder, pTask->showSink.reserved) < 0) return -1; + } else { + ASSERT(pTask->sinkType == TASK_SINK__NONE); } if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { @@ -244,8 +251,16 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; } - if (pTask->sinkType != TASK_SINK__NONE) { + if (pTask->sinkType == TASK_SINK__TABLE) { if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SMA) { + if (tDecodeI8(pDecoder, &pTask->smaSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__FETCH) { + if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SHOW) { + if (tDecodeI8(pDecoder, &pTask->showSink.reserved) < 0) return -1; + } else { + ASSERT(pTask->sinkType == TASK_SINK__NONE); } if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { From 78313467e762019d16b52df64e7ba30b83708aa6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 06:17:40 +0000 Subject: [PATCH 125/149] refact --- source/libs/tdb/src/db/tdbDb.c | 4 ++-- source/libs/tdb/src/db/tdbEnv.c | 10 +++++----- source/libs/tdb/src/db/tdbTxn.c | 6 +++--- source/libs/tdb/src/inc/tdbDb.h | 2 +- source/libs/tdb/src/inc/tdbEnv.h | 8 ++++---- source/libs/tdb/src/inc/tdbTxn.h | 6 +++--- source/libs/tdb/test/tdbTest.cpp | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 1a66306b15..68adb7ccfc 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -16,7 +16,7 @@ #include "tdbInt.h" struct STDB { - TEnv *pEnv; + TENV *pEnv; SBTree *pBt; }; @@ -24,7 +24,7 @@ struct STDBC { SBTC btc; }; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TEnv *pEnv, TDB **ppDb) { +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb) { TDB *pDb; SPager *pPager; int ret; diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 1fb2486a2b..4439147e09 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -15,8 +15,8 @@ #include "tdbInt.h" -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv) { - TEnv *pEnv; +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) { + TENV *pEnv; int dsize; int zsize; u8 *pPtr; @@ -32,7 +32,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv) { return -1; } - pEnv = (TEnv *)pPtr; + pEnv = (TENV *)pPtr; pPtr += sizeof(*pEnv); // pEnv->rootDir pEnv->rootDir = pPtr; @@ -59,12 +59,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv) { return 0; } -int tdbEnvClose(TEnv *pEnv) { +int tdbEnvClose(TENV *pEnv) { // TODO return 0; } -SPager *tdbEnvGetPager(TEnv *pEnv, const char *fname) { +SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) { // TODO return NULL; } \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbTxn.c b/source/libs/tdb/src/db/tdbTxn.c index 5c7ac0678e..fd4d5de60e 100644 --- a/source/libs/tdb/src/db/tdbTxn.c +++ b/source/libs/tdb/src/db/tdbTxn.c @@ -15,17 +15,17 @@ #include "tdbInt.h" -int tdbTxnBegin(TEnv *pEnv) { +int tdbTxnBegin(TENV *pEnv) { // TODO return 0; } -int tdbTxnCommit(TEnv *pEnv) { +int tdbTxnCommit(TENV *pEnv) { // TODO return 0; } -int tdbTxnRollback(TEnv *pEnv) { +int tdbTxnRollback(TENV *pEnv) { // TODO return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h index bbeabf4d3e..4fbf65829d 100644 --- a/source/libs/tdb/src/inc/tdbDb.h +++ b/source/libs/tdb/src/inc/tdbDb.h @@ -24,7 +24,7 @@ typedef struct STDB TDB; typedef struct STDBC TDBC; // TDB -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TEnv *pEnv, TDB **ppDb); +int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb); int tdbDbClose(TDB *pDb); int tdbDbDrop(TDB *pDb); int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/source/libs/tdb/src/inc/tdbEnv.h index 80ee2e8b07..a651c3a12e 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/source/libs/tdb/src/inc/tdbEnv.h @@ -25,12 +25,12 @@ typedef struct STEnv { char *jfname; int jfd; SPCache *pCache; -} TEnv; +} TENV; -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TEnv **ppEnv); -int tdbEnvClose(TEnv *pEnv); +int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv); +int tdbEnvClose(TENV *pEnv); -SPager *tdbEnvGetPager(TEnv *pEnv, const char *fname); +SPager *tdbEnvGetPager(TENV *pEnv, const char *fname); #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/tdb/src/inc/tdbTxn.h index 06b31879de..4300dc8324 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/tdb/src/inc/tdbTxn.h @@ -28,9 +28,9 @@ struct STxn { void *xArg; }; -int tdbTxnBegin(TEnv *pEnv); -int tdbTxnCommit(TEnv *pEnv); -int tdbTxnRollback(TEnv *pEnv); +int tdbTxnBegin(TENV *pEnv); +int tdbTxnCommit(TENV *pEnv); +int tdbTxnRollback(TENV *pEnv); #ifdef __cplusplus } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index f4a170f2c0..f41e2bcbee 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -115,7 +115,7 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in TEST(tdb_test, simple_test) { int ret; - TEnv *pEnv; + TENV *pEnv; TDB *pDb; FKeyComparator compFunc; int nData = 1000000; From a3b4de6631a33cf8df4cbc4b6106aeb9fe1f7835 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 14:40:22 +0800 Subject: [PATCH 126/149] stream support sma --- include/libs/stream/tstream.h | 9 +++++++-- source/client/src/tmq.c | 2 +- source/dnode/mnode/impl/inc/mndScheduler.h | 2 +- source/dnode/mnode/impl/inc/mndStream.h | 2 +- source/dnode/mnode/impl/src/mndScheduler.c | 6 +++++- source/dnode/mnode/impl/src/mndSma.c | 7 ++++--- source/dnode/mnode/impl/src/mndStream.c | 6 +++--- source/dnode/vnode/src/inc/vnd.h | 3 +++ source/dnode/vnode/src/tq/tq.c | 1 + source/libs/stream/src/tstream.c | 5 +++-- 10 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 4efddde935..8be9bbbebd 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -82,8 +82,12 @@ typedef struct { SHashObj* pHash; // groupId to tbuid } STaskSinkTb; +typedef void FSmaHandle(void* vnode, int64_t smaId, const SArray* data); + typedef struct { - int8_t reserved; + int64_t smaId; + // following are not applicable to encoder and decoder + FSmaHandle* smaHandle; } STaskSinkSma; typedef struct { @@ -156,7 +160,8 @@ typedef struct { STaskDispatcherShuffle shuffleDispatcher; }; - // state storage + // application storage + void* ahandle; } SStreamTask; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 8eaca6853d..5d00cca76e 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -877,7 +877,7 @@ WRITE_QUEUE_FAIL: } bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { - printf("call update ep %d\n", epoch); + /*printf("call update ep %d\n", epoch);*/ bool set = false; int32_t sz = taosArrayGetSize(pRsp->topics); SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 42951beca2..416061bf34 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -27,7 +27,7 @@ void mndCleanupScheduler(SMnode* pMnode); int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub); -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index b5d22cb7a5..e7cdd34a7e 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw); -int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans); +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 69ee1a5696..697811cd04 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -119,7 +119,7 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) { return pVgroup; } -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { +int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) { SSdb* pSdb = pMnode->pSdb; SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); if (pPlan == NULL) { @@ -164,6 +164,10 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // only for inplace pTask->sinkType = TASK_SINK__SHOW; pTask->showSink.reserved = 0; + if (smaId != -1) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = smaId; + } } else { pTask->sinkType = TASK_SINK__NONE; } diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 146975aa38..5c62cfa0f2 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -69,7 +69,8 @@ void mndCleanupSma(SMnode *pMnode) {} static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) { terrno = TSDB_CODE_OUT_OF_MEMORY; - int32_t size = sizeof(SSmaObj) + pSma->exprLen + pSma->tagsFilterLen + pSma->sqlLen + pSma->astLen + TSDB_SMA_RESERVE_SIZE; + int32_t size = + sizeof(SSmaObj) + pSma->exprLen + pSma->tagsFilterLen + pSma->sqlLen + pSma->astLen + TSDB_SMA_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_SMA, TSDB_SMA_VER_NUMBER, size); if (pRaw == NULL) goto _OVER; @@ -427,7 +428,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; - if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER; + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, smaObj.uid) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -491,7 +492,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); goto _OVER; } - + pStream = mndAcquireStream(pMnode, createReq.name); if (pStream != NULL) { mError("sma:%s, failed to create since stream:%s already exist", createReq.name, createReq.name); diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index c02fec0a5f..bbb2f64282 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -246,7 +246,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) { return code; } -int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) { +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId) { SNode *pAst = NULL; if (nodesStringToNode(ast, &pAst) < 0) { @@ -271,7 +271,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast return -1; } - if (mndScheduleStream(pMnode, pTrans, pStream) < 0) { + if (mndScheduleStream(pMnode, pTrans, pStream, smaId) < 0) { mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr()); return -1; } @@ -310,7 +310,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe } mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); - if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) { + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, -1) != 0) { mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); return -1; diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 3309686bb7..7b0606512c 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -202,6 +202,9 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); +// sma +void smaHandleRes(SVnode* pVnode, int64_t smaId, const SArray* data); + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index c354b01501..55202335e0 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -476,6 +476,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { if (tqExpandTask(pTq, pTask, 4) < 0) { ASSERT(0); } + pTask->ahandle = pTq->pVnode; taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask)); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 6d69a8960e..028e310a25 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -72,6 +72,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in if (pTask->sinkType == TASK_SINK__TABLE) { // } else if (pTask->sinkType == TASK_SINK__SMA) { + pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes); // } else if (pTask->sinkType == TASK_SINK__FETCH) { // @@ -208,7 +209,7 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (pTask->sinkType == TASK_SINK__TABLE) { if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__SMA) { - if (tEncodeI8(pEncoder, pTask->smaSink.reserved) < 0) return -1; + if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__FETCH) { if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__SHOW) { @@ -254,7 +255,7 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (pTask->sinkType == TASK_SINK__TABLE) { if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__SMA) { - if (tDecodeI8(pDecoder, &pTask->smaSink.reserved) < 0) return -1; + if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__FETCH) { if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__SHOW) { From 8529bf709e3baef05e7ec1b6a0f91806c4d8ae7c Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 28 Mar 2022 14:45:19 +0800 Subject: [PATCH 127/149] definition refactor --- source/dnode/vnode/src/inc/tsdbReadImpl.h | 18 ++++++++++-------- source/dnode/vnode/src/vnd/vnodeWrite.c | 6 +++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdbReadImpl.h b/source/dnode/vnode/src/inc/tsdbReadImpl.h index cd24358b27..d25ac1d194 100644 --- a/source/dnode/vnode/src/inc/tsdbReadImpl.h +++ b/source/dnode/vnode/src/inc/tsdbReadImpl.h @@ -64,18 +64,20 @@ typedef enum { #define SBlockVerLatest TSDB_SBLK_VER_0 typedef struct { + uint8_t blkVer : 4; + uint8_t algorithm : 4; uint8_t last : 1; - uint8_t blkVer : 7; - uint8_t numOfSubBlocks; - int16_t numOfCols; // not including timestamp column - uint32_t len; // data block length - uint32_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols - uint32_t reserve : 8; - int32_t algorithm : 8; - int32_t numOfRows : 24; + uint8_t numOfSubBlocks : 7; + col_id_t numOfCols; // not including timestamp column + uint32_t len; // data block length + uint64_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + uint64_t colSpan : 8; // columns split span(0~255. 0: no split; other: +1(e.g. 63->64, 127->128, 255->256)) + uint64_t schemaVer : 16; // 0~65535 + uint64_t numOfRows : 16; // 0~65535 int64_t offset; uint64_t aggrStat : 1; uint64_t aggrOffset : 63; + uint64_t reserve; // TODO: use compact mode or reserve for future use? TSKEY keyFirst; TSKEY keyLast; } SBlockV0; diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index 02d4524bce..94cbe776bc 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -179,12 +179,16 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA -#if 0 +#if 1 + SSmaCfg vCreateSmaReq = {0}; if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; + vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, terrstr(terrno)); return -1; } + vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName, + vCreateSmaReq.tSma.indexUid); // record current timezone of server side tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); From 6baa845db313b52211d31f3f719ecc560b019a52 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Mon, 28 Mar 2022 14:48:57 +0800 Subject: [PATCH 128/149] [TD-13758]: add memory option. --- source/os/CMakeLists.txt | 3 +++ source/os/src/osMemory.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index eea3903911..c467ab5fa3 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -13,6 +13,9 @@ find_path(IconvApiIncludes iconv.h PATHS) if(NOT IconvApiIncludes) add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) endif () +if(USE_TD_MEMORY) + add_definitions(-DUSE_TD_MEMORY) +endif () target_link_libraries( os pthread dl rt m ) diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 12e89fdd73..3a76399812 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -14,6 +14,7 @@ */ #define ALLOW_FORBID_FUNC +#include #include "os.h" #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') @@ -68,6 +69,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { // } void *taosMemoryMalloc(int32_t size) { +#ifdef USE_TD_MEMORY void *tmp = malloc(size + sizeof(TdMemoryInfo)); if (tmp == NULL) return NULL; @@ -77,9 +79,13 @@ void *taosMemoryMalloc(int32_t size) { taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); return (char*)tmp + sizeof(TdMemoryInfo); +#else + return malloc(size); +#endif } void *taosMemoryCalloc(int32_t num, int32_t size) { +#ifdef USE_TD_MEMORY int32_t memorySize = num * size; char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1); if (tmp == NULL) return NULL; @@ -90,9 +96,13 @@ void *taosMemoryCalloc(int32_t num, int32_t size) { taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); return (char*)tmp + sizeof(TdMemoryInfo); +#else + return calloc(num, size); +#endif } void *taosMemoryRealloc(void *ptr, int32_t size) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return taosMemoryMalloc(size); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); @@ -108,9 +118,13 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { ((TdMemoryInfoPtr)tmp)->memorySize = size; return (char*)tmp + sizeof(TdMemoryInfo); +#else + return realloc(ptr, size); +#endif } void taosMemoryFree(const void *ptr) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return; TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); @@ -121,13 +135,20 @@ void taosMemoryFree(const void *ptr) { } else { free((void*)ptr); } +#else + return free((void*)ptr); +#endif } int32_t taosMemorySize(void *ptr) { +#ifdef USE_TD_MEMORY if (ptr == NULL) return 0; TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); return pTdMemoryInfo->memorySize; +#else + return malloc_usable_size(ptr); +#endif } From 9a08ac3c5fcce27a1c004cf9b85a5d3323039126 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 14:55:15 +0800 Subject: [PATCH 129/149] stream support sma --- source/dnode/vnode/src/inc/vnd.h | 7 +++---- source/dnode/vnode/src/tq/tq.c | 6 ++++++ source/dnode/vnode/src/vnd/vnodeWrite.c | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 7b0606512c..5ec5b1d58f 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -19,15 +19,14 @@ #include "tmallocator.h" // #include "sync.h" #include "tcoding.h" +#include "tdatablock.h" #include "tfs.h" #include "tlist.h" #include "tlockfree.h" #include "tmacro.h" -#include "wal.h" - #include "vnode.h" - #include "vnodeQuery.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -203,7 +202,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); // sma -void smaHandleRes(SVnode* pVnode, int64_t smaId, const SArray* data); +void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 55202335e0..efc7ac80e9 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -473,10 +473,16 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { } tCoderClear(&decoder); + // exec if (tqExpandTask(pTq, pTask, 4) < 0) { ASSERT(0); } + + // sink pTask->ahandle = pTq->pVnode; + if (pTask->sinkType == TASK_SINK__SMA) { + pTask->smaSink.smaHandle = smaHandleRes; + } taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask)); diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index 98256e6b24..9b1bb61d07 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -15,6 +15,11 @@ #include "vnd.h" +void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { + // TODO + blockDebugShowData(data); +} + void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { SNodeMsg *pMsg; SRpcMsg *pRpc; From 373865a3b0cad2cac8e9e106264f208791ba5941 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Mon, 28 Mar 2022 14:57:42 +0800 Subject: [PATCH 130/149] [TD-13758]: add memory option. --- source/os/src/osMemory.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 3a76399812..daab5817f6 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -33,6 +33,7 @@ typedef struct TdMemoryInfo #else #include + #define STACKCALL __attribute__((regparm(1), noinline)) void **STACKCALL taosGetEbp(void) { void **ebp = NULL; @@ -42,6 +43,7 @@ void **STACKCALL taosGetEbp(void) { : "memory"); /* not affect register */ return (void **)(*ebp); } + int32_t taosBackTrace(void **buffer, int32_t size) { int32_t frame = 0; void **ebp; @@ -60,6 +62,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { } return frame; } + #endif // char **taosBackTraceSymbols(int32_t *size) { From 9d7db266e7319133c3aaa38e2756be1c74ebf538 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 28 Mar 2022 15:28:21 +0800 Subject: [PATCH 131/149] [add cases] --- tests/script/jenkins/basic.txt | 2 + tests/script/tsim/db/basic2.sim | 74 +++++++++++++++++++++++++++++++++ tests/script/tsim/db/basic3.sim | 69 ++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 tests/script/tsim/db/basic2.sim create mode 100644 tests/script/tsim/db/basic3.sim diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index dd44baed27..1b79851c4d 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -6,6 +6,8 @@ # ---- db ./test.sh -f tsim/db/basic1.sim +./test.sh -f tsim/db/basic2.sim +./test.sh -f tsim/db/basic3.sim ./test.sh -f tsim/db/basic6.sim ./test.sh -f tsim/db/basic7.sim ./test.sh -f tsim/db/error1.sim diff --git a/tests/script/tsim/db/basic2.sim b/tests/script/tsim/db/basic2.sim new file mode 100644 index 0000000000..e9222c8d32 --- /dev/null +++ b/tests/script/tsim/db/basic2.sim @@ -0,0 +1,74 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database d1 +sql create database d1 +sql use d1 +sql create table t1 (ts timestamp, i int); +sql create table t2 (ts timestamp, i int); +sql create table t3 (ts timestamp, i int); +sql create table t4 (ts timestamp, i int); + +sql show databases +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +if $rows != 2 then + return -1 +endi + +if $data00 != d1 then + return -1 +endi + +if $data02 != 2 then # vgroups + return -1 +endi + +#if $data03 != 4 then # ntables +# return -1 +#endi + +sql show tables +if $rows != 4 then + return -1 +endi + +print =============== create database d2 +sql create database d2 +sql use d2 +sql create table t1 (ts timestamp, i int); +sql create table t2 (ts timestamp, i int); +sql create table t3 (ts timestamp, i int); + +sql show databases +if $rows != 3 then + return -1 +endi + +sql show tables +if $rows != 3 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/db/basic3.sim b/tests/script/tsim/db/basic3.sim new file mode 100644 index 0000000000..52a587cc16 --- /dev/null +++ b/tests/script/tsim/db/basic3.sim @@ -0,0 +1,69 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database d1 +sql create database d1 +sql create table d1.t1 (ts timestamp, i int); +sql create table d1.t2 (ts timestamp, i int); +sql create table d1.t3 (ts timestamp, i int); +sql create table d1.t4 (ts timestamp, i int); + +sql show databases +if $rows != 2 then + return -1 +endi + +if $data00 != d1 then + return -1 +endi + +if $data02 != 2 then + return -1 +endi + +#if $data03 != 4 then +# return -1 +#endi + +sql show d1.tables +if $rows != 4 then + return -1 +endi + +print =============== create database d2 +sql create database d2 +sql create table d2.t1 (ts timestamp, i int); +sql create table d2.t2 (ts timestamp, i int); +sql create table d2.t3 (ts timestamp, i int); + +sql show databases +if $rows != 3 then + return -1 +endi + +sql show d2.tables +if $rows != 3 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 00357a1cb91747cb0528753ddf9899f56cd71f8a Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 28 Mar 2022 16:06:08 +0800 Subject: [PATCH 132/149] [rm db/basic2.sim db/basic3.sim] --- tests/script/general/db/basic2.sim | 54 ------------------------------ tests/script/general/db/basic3.sim | 52 ---------------------------- 2 files changed, 106 deletions(-) delete mode 100644 tests/script/general/db/basic2.sim delete mode 100644 tests/script/general/db/basic3.sim diff --git a/tests/script/general/db/basic2.sim b/tests/script/general/db/basic2.sim deleted file mode 100644 index acd035bd74..0000000000 --- a/tests/script/general/db/basic2.sim +++ /dev/null @@ -1,54 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start -sleep 2000 -sql connect - -print =============== create database d1 -sql create database d1 -sql use d1 -sql create table t1 (ts timestamp, i int); -sql create table t2 (ts timestamp, i int); -sql create table t3 (ts timestamp, i int); -sql create table t4 (ts timestamp, i int); - -sql show databases -if $rows != 1 then - return -1 -endi - -if $data00 != d1 then - return -1 -endi - -if $data02 != 4 then - return -1 -endi - -if $data03 != 1 then - return -1 -endi - -sql show tables -if $rows != 4 then - return -1 -endi - -print =============== create database d2 -sql create database d2 -sql use d2 -sql create table t1 (ts timestamp, i int); -sql create table t2 (ts timestamp, i int); -sql create table t3 (ts timestamp, i int); - -sql show databases -if $rows != 2 then - return -1 -endi - -sql show tables -if $rows != 3 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/general/db/basic3.sim b/tests/script/general/db/basic3.sim deleted file mode 100644 index fb64476696..0000000000 --- a/tests/script/general/db/basic3.sim +++ /dev/null @@ -1,52 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start -sleep 2000 -sql connect - -print =============== create database d1 -sql create database d1 -sql create table d1.t1 (ts timestamp, i int); -sql create table d1.t2 (ts timestamp, i int); -sql create table d1.t3 (ts timestamp, i int); -sql create table d1.t4 (ts timestamp, i int); - -sql show databases -if $rows != 1 then - return -1 -endi - -if $data00 != d1 then - return -1 -endi - -if $data02 != 4 then - return -1 -endi - -if $data03 != 1 then - return -1 -endi - -sql show d1.tables -if $rows != 4 then - return -1 -endi - -print =============== create database d2 -sql create database d2 -sql create table d2.t1 (ts timestamp, i int); -sql create table d2.t2 (ts timestamp, i int); -sql create table d2.t3 (ts timestamp, i int); - -sql show databases -if $rows != 2 then - return -1 -endi - -sql show d2.tables -if $rows != 3 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From df319ccb8db49d39bc5c2c6e597e05396ff3c37b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 08:06:27 +0000 Subject: [PATCH 133/149] fix more TDB os error --- source/libs/tdb/src/db/tdbPager.c | 4 ++-- source/libs/tdb/src/inc/tdbOs.h | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 4fac00d5ad..748633da34 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -80,7 +80,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { // pPager->pCache pPager->pCache = pCache; - pPager->fd = tdbOsOpen(pPager->dbFileName, O_RDWR | O_CREAT); + pPager->fd = tdbOsOpen(pPager->dbFileName, TDB_O_CREAT | TDB_O_RDWR, 0755); if (pPager->fd < 0) { return -1; } @@ -168,7 +168,7 @@ int tdbPagerBegin(SPager *pPager) { } // Open the journal - pPager->jfd = tdbOsOpen(pPager->jFileName, O_RDWR | O_CREAT); + pPager->jfd = tdbOsOpen(pPager->jFileName, TDB_O_CREAT | TDB_O_RDWR, 0755); if (pPager->jfd < 0) { return -1; } diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 751c105913..bc610917f6 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -46,7 +46,15 @@ extern "C" { /* file */ typedef TdFilePtr tdb_fd_t; -#define tdbOsOpen taosOpenFile +#define TDB_O_CREAT TD_FILE_CTEATE +#define TDB_O_WRITE TD_FILE_WRITE +#define TDB_O_READ TD_FILE_READ +#define TDB_O_TRUNC TD_FILE_TRUNC +#define TDB_O_APPEND TD_FILE_APPEND +#define TDB_O_RDWR (TD_FILE_WRITE) | (TD_FILE_READ) + +#define tdbOsOpen(PATH, OPTION, MODE) taosOpenFile((PATH), (OPTION)) + #define tdbOsClose(FD) taosCloseFile(&(FD)) #define tdbOsRead taosReadFile #define tdbOsPRead taosPReadFile @@ -64,7 +72,15 @@ typedef TdFilePtr tdb_fd_t; /* file */ typedef int tdb_fd_t; -#define tdbOsOpen open +#define TDB_O_CREAT O_CREAT +#define TDB_O_WRITE O_WRONLY +#define TDB_O_READ O_RDONLY +#define TDB_O_TRUNC O_TRUNC +#define TDB_O_APPEND O_APPEND +#define TDB_O_RDWR O_RDWR + +#define tdbOsOpen(PATH, OPTION, MODE) open((PATH), (OPTION), (MODE)) + #define tdbOsClose close i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes); From 249c33763221bf4aec3c999652f557deade7f7be Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 08:22:55 +0000 Subject: [PATCH 134/149] refact TDB --- source/libs/tdb/src/inc/tdbOs.h | 65 ++++++++++++++------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index bc610917f6..794d4c502a 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -23,30 +23,19 @@ extern "C" { // TODO: use cmake to control the option #define TDB_FOR_TDENGINE -// For memory ----------------- #ifdef TDB_FOR_TDENGINE +// For memory ----------------- #define tdbOsMalloc taosMemoryMalloc #define tdbOsCalloc taosMemoryCalloc #define tdbOsRealloc taosMemoryRealloc #define tdbOsFree taosMemoryFree -#else - -#define tdbOsMalloc malloc -#define tdbOsCalloc calloc -#define tdbOsRealloc realloc -#define tdbOsFree free - -#endif - // For file and directory ----------------- -#ifdef TDB_FOR_TDENGINE - /* file */ typedef TdFilePtr tdb_fd_t; -#define TDB_O_CREAT TD_FILE_CTEATE +#define TDB_O_CREAT TD_FILE_CTEATE #define TDB_O_WRITE TD_FILE_WRITE #define TDB_O_READ TD_FILE_READ #define TDB_O_TRUNC TD_FILE_TRUNC @@ -67,12 +56,37 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsMkdir taosMkDir #define tdbOsRmdir taosRemoveDir +// For threads and lock ----------------- +/* spin lock */ +typedef TdThreadSpinlock tdb_spinlock_t; + +#define tdbSpinlockInit taosThreadSpinInit +#define tdbSpinlockDestroy taosThreadSpinDestroy +#define tdbSpinlockLock taosThreadSpinLock +#define tdbSpinlockUnlock taosThreadSpinUnlock +#define tdbSpinlockTrylock pthread_spin_trylock + +/* mutex lock */ +typedef TdThreadMutex tdb_mutex_t; + +#define tdbMutexInit taosThreadMutexInit +#define tdbMutexDestroy taosThreadMutexDestroy +#define tdbMutexLock taosThreadMutexLock +#define tdbMutexUnlock taosThreadMutexUnlock + #else +// For memory ----------------- +#define tdbOsMalloc malloc +#define tdbOsCalloc calloc +#define tdbOsRealloc realloc +#define tdbOsFree free + +// For file and directory ----------------- /* file */ typedef int tdb_fd_t; -#define TDB_O_CREAT O_CREAT +#define TDB_O_CREAT O_CREAT #define TDB_O_WRITE O_WRONLY #define TDB_O_READ O_RDONLY #define TDB_O_TRUNC O_TRUNC @@ -95,30 +109,7 @@ i64 tdbOsWrite(tdb_fd_t fd, const void *pData, i64 nBytes); #define tdbOsMkdir mkdir #define tdbOsRmdir rmdir -#endif - // For threads and lock ----------------- -#ifdef TDB_FOR_TDENGINE - -/* spin lock */ -typedef TdThreadSpinlock tdb_spinlock_t; - -#define tdbSpinlockInit taosThreadSpinInit -#define tdbSpinlockDestroy taosThreadSpinDestroy -#define tdbSpinlockLock taosThreadSpinLock -#define tdbSpinlockUnlock taosThreadSpinUnlock -#define tdbSpinlockTrylock pthread_spin_trylock - -/* mutex lock */ -typedef TdThreadMutex tdb_mutex_t; - -#define tdbMutexInit taosThreadMutexInit -#define tdbMutexDestroy taosThreadMutexDestroy -#define tdbMutexLock taosThreadMutexLock -#define tdbMutexUnlock taosThreadMutexUnlock - -#else - /* spin lock */ typedef pthread_spinlock_t tdb_spinlock_t; From 1e1573359d405ac2fd3c18a3ecc5d6ae6e3b9fac Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 16:43:52 +0800 Subject: [PATCH 135/149] shm --- include/util/tworker.h | 6 +++--- source/dnode/mgmt/bnode/src/bmWorker.c | 2 +- source/dnode/mgmt/container/src/dndExec.c | 21 ++++++++++++--------- source/dnode/mgmt/dnode/src/dmWorker.c | 4 ++-- source/dnode/mgmt/mnode/src/mmWorker.c | 16 ++++++++-------- source/dnode/mgmt/qnode/src/qmWorker.c | 8 ++++---- source/dnode/mgmt/snode/src/smWorker.c | 6 +++--- source/dnode/mgmt/vnode/src/vmWorker.c | 2 +- source/util/src/tprocess.c | 22 ++++++++++++---------- source/util/src/tworker.c | 6 +++--- 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/include/util/tworker.h b/include/util/tworker.h index 92d474c885..3545aeed89 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -70,8 +70,8 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue); typedef struct { const char *name; - int32_t minNum; - int32_t maxNum; + int32_t min; + int32_t max; FItem fp; void *param; } SSingleWorkerCfg; @@ -84,7 +84,7 @@ typedef struct { typedef struct { const char *name; - int32_t maxNum; + int32_t max; FItems fp; void *param; } SMultiWorkerCfg; diff --git a/source/dnode/mgmt/bnode/src/bmWorker.c b/source/dnode/mgmt/bnode/src/bmWorker.c index 7698aa9dbd..1ed9b0d931 100644 --- a/source/dnode/mgmt/bnode/src/bmWorker.c +++ b/source/dnode/mgmt/bnode/src/bmWorker.c @@ -71,7 +71,7 @@ int32_t bmProcessWriteMsg(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { } int32_t bmStartWorker(SBnodeMgmt *pMgmt) { - SMultiWorkerCfg cfg = {.maxNum = 1, .name = "bnode-write", .fp = (FItems)bmProcessQueue, .param = pMgmt}; + SMultiWorkerCfg cfg = {.max = 1, .name = "bnode-write", .fp = (FItems)bmProcessQueue, .param = pMgmt}; if (tMultiWorkerInit(&pMgmt->writeWorker, &cfg) != 0) { dError("failed to start bnode write worker since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index a7b8ca288b..cc1d8e5f24 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -108,21 +108,22 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { } static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { - dndCleanupServer(pDnode); + // dndCleanupServer(pDnode); for (ENodeType n = 0; n < NODE_MAX; ++n) { if (except == n) continue; SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dndCloseNode(pWrapper); + pWrapper->required = false; } } static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t msgLen, void *pCont, int32_t contLen) { - dTrace("msg:%p, get from child queue", pMsg); SRpcMsg *pRpc = &pMsg->rpcMsg; pRpc->pCont = pCont; + dTrace("msg:%p, get from child queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType), pRpc->handle, + pRpc->ahandle); NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; - int32_t code = (*msgFp)(pWrapper, pMsg); + int32_t code = (*msgFp)(pWrapper->pMgmt, pMsg); if (code != 0) { if (pRpc->msgType & 1U) { @@ -136,11 +137,13 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t } } -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t msgLen, void *pCont, int32_t contLen) { - dTrace("msg:%p, get from parent queue", pRsp); - pRsp->pCont = pCont; - dndSendRsp(pWrapper, pRsp); - taosMemoryFree(pRsp); +static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, int32_t msgLen, void *pCont, int32_t contLen) { + pRpc->pCont = pCont; + dTrace("msg:%p, get from parent queue, type:%s handle:%p app:%p", pRpc, TMSG_INFO(pRpc->msgType), pRpc->handle, + pRpc->ahandle); + + dndSendRsp(pWrapper, pRpc); + taosMemoryFree(pRpc); } static int32_t dndRunInMultiProcess(SDnode *pDnode) { diff --git a/source/dnode/mgmt/dnode/src/dmWorker.c b/source/dnode/mgmt/dnode/src/dmWorker.c index d34a26436c..8e560503d0 100644 --- a/source/dnode/mgmt/dnode/src/dmWorker.c +++ b/source/dnode/mgmt/dnode/src/dmWorker.c @@ -101,14 +101,14 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { int32_t dmStartWorker(SDnodeMgmt *pMgmt) { SSingleWorkerCfg mgmtCfg = { - .minNum = 1, .maxNum = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; + .min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) { dError("failed to start dnode mgmt worker since %s", terrstr()); return -1; } SSingleWorkerCfg statusCfg = { - .minNum = 1, .maxNum = 1, .name = "dnode-status", .fp = (FItem)dmProcessQueue, .param = pMgmt}; + .min = 1, .max = 1, .name = "dnode-status", .fp = (FItem)dmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->statusWorker, &statusCfg) != 0) { dError("failed to start dnode status worker since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mnode/src/mmWorker.c index 27489b45d0..d07313410a 100644 --- a/source/dnode/mgmt/mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mnode/src/mmWorker.c @@ -123,27 +123,27 @@ int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { return mmPutRpcMsgToWorker(pMgmt, &pMgmt->queryWorker, pRpc); } - int32_t mmStartWorker(SMnodeMgmt *pMgmt) { - SSingleWorkerCfg cfg = {.minNum = 0, .maxNum = 1, .name = "mnode-read", .fp = (FItem)mmProcessQueue, .param = pMgmt}; - SSingleWorkerCfg queryCfg = {.minNum = 0, .maxNum = 1, .name = "mnode-query", .fp = (FItem)mmProcessQueryQueue, .param = pMgmt}; - - if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) { + SSingleWorkerCfg qCfg = {.min = 0, .max = 1, .name = "mnode-query", .fp = (FItem)mmProcessQueryQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) { dError("failed to start mnode-query worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->readWorker, &cfg) != 0) { + SSingleWorkerCfg rCfg = {.min = 0, .max = 1, .name = "mnode-read", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) { dError("failed to start mnode-read worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->writeWorker, &cfg) != 0) { + SSingleWorkerCfg wCfg = {.min = 0, .max = 1, .name = "mnode-write", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) { dError("failed to start mnode-write worker since %s", terrstr()); return -1; } - if (tSingleWorkerInit(&pMgmt->syncWorker, &cfg) != 0) { + SSingleWorkerCfg sCfg = {.min = 0, .max = 1, .name = "mnode-sync", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) { dError("failed to start mnode sync-worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/qnode/src/qmWorker.c b/source/dnode/mgmt/qnode/src/qmWorker.c index aa4da82790..5923f5c2f4 100644 --- a/source/dnode/mgmt/qnode/src/qmWorker.c +++ b/source/dnode/mgmt/qnode/src/qmWorker.c @@ -110,8 +110,8 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { int32_t minQueryThreads = TMAX((int32_t)(tsNumOfCores * tsRatioOfQueryCores), 1); int32_t maxQueryThreads = minQueryThreads; - SSingleWorkerCfg queryCfg = {.minNum = minQueryThreads, - .maxNum = maxQueryThreads, + SSingleWorkerCfg queryCfg = {.min = minQueryThreads, + .max = maxQueryThreads, .name = "qnode-query", .fp = (FItem)qmProcessQueryQueue, .param = pMgmt}; @@ -121,8 +121,8 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg fetchCfg = {.minNum = minFetchThreads, - .maxNum = maxFetchThreads, + SSingleWorkerCfg fetchCfg = {.min = minFetchThreads, + .max = maxFetchThreads, .name = "qnode-fetch", .fp = (FItem)qmProcessFetchQueue, .param = pMgmt}; diff --git a/source/dnode/mgmt/snode/src/smWorker.c b/source/dnode/mgmt/snode/src/smWorker.c index 5913713ff3..4e46ad5818 100644 --- a/source/dnode/mgmt/snode/src/smWorker.c +++ b/source/dnode/mgmt/snode/src/smWorker.c @@ -57,7 +57,7 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { return -1; } - SMultiWorkerCfg cfg = {.maxNum = 1, .name = "snode-unique", .fp = smProcessUniqueQueue, .param = pMgmt}; + SMultiWorkerCfg cfg = {.max = 1, .name = "snode-unique", .fp = smProcessUniqueQueue, .param = pMgmt}; if (tMultiWorkerInit(pUniqueWorker, &cfg) != 0) { dError("failed to start snode-unique worker since %s", terrstr()); @@ -69,8 +69,8 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { } } - SSingleWorkerCfg cfg = {.minNum = SND_SHARED_THREAD_NUM, - .maxNum = SND_SHARED_THREAD_NUM, + SSingleWorkerCfg cfg = {.min = SND_SHARED_THREAD_NUM, + .max = SND_SHARED_THREAD_NUM, .name = "snode-shared", .fp = (FItem)smProcessSharedQueue, .param = pMgmt}; diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vnode/src/vmWorker.c index 7b6d78a60c..99274ac99b 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vnode/src/vmWorker.c @@ -394,7 +394,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { if (tWWorkerInit(pWPool) != 0) return -1; SSingleWorkerCfg cfg = { - .minNum = 1, .maxNum = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; + .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { dError("failed to start vnode-mgmt worker since %s", terrstr()); return -1; diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index f5ce88179b..d06aab6fda 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -264,7 +264,8 @@ static int32_t taosProcQueuePush(SProcQueue *pQueue, char *pHead, int32_t rawHea taosThreadMutexUnlock(pQueue->mutex); tsem_post(&pQueue->sem); - uTrace("proc:%s, push msg:%p:%d cont:%p:%d to queue:%p", pQueue->name, pHead, headLen, pBody, bodyLen, pQueue); + uTrace("proc:%s, push msg to queue:%p remains:%d, head:%d:%p body:%d:%p", pQueue->name, pQueue, pQueue->items, + headLen, pHead, bodyLen, pBody); return 0; } @@ -277,7 +278,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea taosThreadMutexUnlock(pQueue->mutex); tsem_post(&pQueue->sem); terrno = TSDB_CODE_OUT_OF_SHM_MEM; - return -1; + return 0; } int32_t headLen = 0; @@ -341,8 +342,9 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int32_t *pHea *pHeadLen = headLen; *pBodyLen = bodyLen; - uTrace("proc:%s, get msg:%p:%d cont:%p:%d from queue:%p", pQueue->name, pHead, headLen, pBody, bodyLen, pQueue); - return 0; + uTrace("proc:%s, pop msg from queue:%p remains:%d, head:%d:%p body:%d:%p", pQueue->name, pQueue, pQueue->items, + headLen, pHead, bodyLen, pBody); + return 1; } SProcObj *taosProcInit(const SProcCfg *pCfg) { @@ -396,15 +398,15 @@ static void taosProcThreadLoop(SProcQueue *pQueue) { void *pHead, *pBody; int32_t headLen, bodyLen; - uDebug("proc:%s, start to get message from queue:%p", pQueue->name, pQueue); + uDebug("proc:%s, start to get msg from queue:%p", pQueue->name, pQueue); while (1) { - int32_t code = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen); - if (code < 0) { - uDebug("proc:%s, get no message from queue:%p and exiting", pQueue->name, pQueue); + int32_t numOfMsgs = taosProcQueuePop(pQueue, &pHead, &headLen, &pBody, &bodyLen); + if (numOfMsgs == 0) { + uDebug("proc:%s, get no msg from queue:%p and exit the proc thread", pQueue->name, pQueue); break; - } else if (code == 0) { - uTrace("proc:%s, get no message from queue:%p since %s", pQueue->name, pQueue, terrstr()); + } else if (numOfMsgs < 0) { + uTrace("proc:%s, get no msg from queue:%p since %s", pQueue->name, pQueue, terrstr()); taosMsleep(1); continue; } else { diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 992ec74b5b..7fc390e70b 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -287,8 +287,8 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) { int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) { SQWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; - pPool->min = pCfg->minNum; - pPool->max = pCfg->maxNum; + pPool->min = pCfg->min; + pPool->max = pCfg->max; if (tQWorkerInit(pPool) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -316,7 +316,7 @@ void tSingleWorkerCleanup(SSingleWorker *pWorker) { int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) { SWWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; - pPool->max = pCfg->maxNum; + pPool->max = pCfg->max; if (tWWorkerInit(pPool) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; From 11636180ad5ba0e300309d0214d6c9e3a37b8a32 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Mon, 28 Mar 2022 05:08:48 -0400 Subject: [PATCH 136/149] rollup syntax and msg adjust --- include/common/ttokendef.h | 193 +- include/libs/nodes/cmdnodes.h | 4 + include/util/tdef.h | 8 + source/libs/parser/inc/parAst.h | 3 +- source/libs/parser/inc/sql.y | 3 +- source/libs/parser/src/parAstCreater.c | 73 +- source/libs/parser/src/parTokenizer.c | 5 +- source/libs/parser/src/parTranslater.c | 146 +- source/libs/parser/src/sql.c | 3908 +++++++++++---------- source/libs/parser/test/parserAstTest.cpp | 5 +- 10 files changed, 2269 insertions(+), 2079 deletions(-) diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index da34ca6253..51dd645a30 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -82,102 +82,103 @@ #define TK_SINGLE_STABLE 64 #define TK_STREAM_MODE 65 #define TK_RETENTIONS 66 -#define TK_FILE_FACTOR 67 -#define TK_NK_FLOAT 68 -#define TK_TABLE 69 -#define TK_NK_LP 70 -#define TK_NK_RP 71 -#define TK_STABLE 72 -#define TK_ADD 73 -#define TK_COLUMN 74 -#define TK_MODIFY 75 -#define TK_RENAME 76 -#define TK_TAG 77 -#define TK_SET 78 -#define TK_NK_EQ 79 -#define TK_USING 80 -#define TK_TAGS 81 -#define TK_NK_DOT 82 -#define TK_NK_COMMA 83 -#define TK_COMMENT 84 -#define TK_BOOL 85 -#define TK_TINYINT 86 -#define TK_SMALLINT 87 -#define TK_INT 88 -#define TK_INTEGER 89 -#define TK_BIGINT 90 -#define TK_FLOAT 91 -#define TK_DOUBLE 92 -#define TK_BINARY 93 -#define TK_TIMESTAMP 94 -#define TK_NCHAR 95 -#define TK_UNSIGNED 96 -#define TK_JSON 97 -#define TK_VARCHAR 98 -#define TK_MEDIUMBLOB 99 -#define TK_BLOB 100 -#define TK_VARBINARY 101 -#define TK_DECIMAL 102 -#define TK_SMA 103 -#define TK_ROLLUP 104 -#define TK_SHOW 105 -#define TK_DATABASES 106 -#define TK_TABLES 107 -#define TK_STABLES 108 -#define TK_MNODES 109 -#define TK_MODULES 110 -#define TK_QNODES 111 -#define TK_FUNCTIONS 112 -#define TK_INDEXES 113 -#define TK_FROM 114 -#define TK_LIKE 115 -#define TK_INDEX 116 -#define TK_FULLTEXT 117 -#define TK_FUNCTION 118 -#define TK_INTERVAL 119 -#define TK_TOPIC 120 -#define TK_AS 121 -#define TK_NK_BOOL 122 -#define TK_NK_VARIABLE 123 -#define TK_BETWEEN 124 -#define TK_IS 125 -#define TK_NULL 126 -#define TK_NK_LT 127 -#define TK_NK_GT 128 -#define TK_NK_LE 129 -#define TK_NK_GE 130 -#define TK_NK_NE 131 -#define TK_MATCH 132 -#define TK_NMATCH 133 -#define TK_IN 134 -#define TK_JOIN 135 -#define TK_INNER 136 -#define TK_SELECT 137 -#define TK_DISTINCT 138 -#define TK_WHERE 139 -#define TK_PARTITION 140 -#define TK_BY 141 -#define TK_SESSION 142 -#define TK_STATE_WINDOW 143 -#define TK_SLIDING 144 -#define TK_FILL 145 -#define TK_VALUE 146 -#define TK_NONE 147 -#define TK_PREV 148 -#define TK_LINEAR 149 -#define TK_NEXT 150 -#define TK_GROUP 151 -#define TK_HAVING 152 -#define TK_ORDER 153 -#define TK_SLIMIT 154 -#define TK_SOFFSET 155 -#define TK_LIMIT 156 -#define TK_OFFSET 157 -#define TK_ASC 158 -#define TK_DESC 159 -#define TK_NULLS 160 -#define TK_FIRST 161 -#define TK_LAST 162 +#define TK_TABLE 67 +#define TK_NK_LP 68 +#define TK_NK_RP 69 +#define TK_STABLE 70 +#define TK_ADD 71 +#define TK_COLUMN 72 +#define TK_MODIFY 73 +#define TK_RENAME 74 +#define TK_TAG 75 +#define TK_SET 76 +#define TK_NK_EQ 77 +#define TK_USING 78 +#define TK_TAGS 79 +#define TK_NK_DOT 80 +#define TK_NK_COMMA 81 +#define TK_COMMENT 82 +#define TK_BOOL 83 +#define TK_TINYINT 84 +#define TK_SMALLINT 85 +#define TK_INT 86 +#define TK_INTEGER 87 +#define TK_BIGINT 88 +#define TK_FLOAT 89 +#define TK_DOUBLE 90 +#define TK_BINARY 91 +#define TK_TIMESTAMP 92 +#define TK_NCHAR 93 +#define TK_UNSIGNED 94 +#define TK_JSON 95 +#define TK_VARCHAR 96 +#define TK_MEDIUMBLOB 97 +#define TK_BLOB 98 +#define TK_VARBINARY 99 +#define TK_DECIMAL 100 +#define TK_SMA 101 +#define TK_ROLLUP 102 +#define TK_FILE_FACTOR 103 +#define TK_NK_FLOAT 104 +#define TK_DELAY 105 +#define TK_SHOW 106 +#define TK_DATABASES 107 +#define TK_TABLES 108 +#define TK_STABLES 109 +#define TK_MNODES 110 +#define TK_MODULES 111 +#define TK_QNODES 112 +#define TK_FUNCTIONS 113 +#define TK_INDEXES 114 +#define TK_FROM 115 +#define TK_LIKE 116 +#define TK_INDEX 117 +#define TK_FULLTEXT 118 +#define TK_FUNCTION 119 +#define TK_INTERVAL 120 +#define TK_TOPIC 121 +#define TK_AS 122 +#define TK_NK_BOOL 123 +#define TK_NK_VARIABLE 124 +#define TK_BETWEEN 125 +#define TK_IS 126 +#define TK_NULL 127 +#define TK_NK_LT 128 +#define TK_NK_GT 129 +#define TK_NK_LE 130 +#define TK_NK_GE 131 +#define TK_NK_NE 132 +#define TK_MATCH 133 +#define TK_NMATCH 134 +#define TK_IN 135 +#define TK_JOIN 136 +#define TK_INNER 137 +#define TK_SELECT 138 +#define TK_DISTINCT 139 +#define TK_WHERE 140 +#define TK_PARTITION 141 +#define TK_BY 142 +#define TK_SESSION 143 +#define TK_STATE_WINDOW 144 +#define TK_SLIDING 145 +#define TK_FILL 146 +#define TK_VALUE 147 +#define TK_NONE 148 +#define TK_PREV 149 +#define TK_LINEAR 150 +#define TK_NEXT 151 +#define TK_GROUP 152 +#define TK_HAVING 153 +#define TK_ORDER 154 +#define TK_SLIMIT 155 +#define TK_SOFFSET 156 +#define TK_LIMIT 157 +#define TK_OFFSET 158 +#define TK_ASC 159 +#define TK_DESC 160 +#define TK_NULLS 161 +#define TK_FIRST 162 +#define TK_LAST 163 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 48a3a9bda8..a03c496b4f 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -41,6 +41,7 @@ typedef struct SDatabaseOptions { int32_t numOfVgroups; int8_t singleStable; int8_t streamMode; + SNodeList* pRetentions; } SDatabaseOptions; typedef struct SCreateDatabaseStmt { @@ -73,6 +74,9 @@ typedef struct STableOptions { int32_t ttl; char comments[TSDB_STB_COMMENT_LEN]; SNodeList* pSma; + SNodeList* pFuncs; + float filesFactor; + int32_t delay; } STableOptions; typedef struct SColumnDefNode { diff --git a/include/util/tdef.h b/include/util/tdef.h index 6c5208ec00..9ecb7784ed 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -369,6 +369,14 @@ typedef enum ELogicConditionType { #define TSDB_MAX_DB_CACHE_LAST_ROW 3 #define TSDB_DEFAULT_CACHE_LAST_ROW 0 +#define TSDB_MIN_DB_FILE_FACTOR 0 +#define TSDB_MAX_DB_FILE_FACTOR 1 +#define TSDB_DEFAULT_DB_FILE_FACTOR 0.1 + +#define TSDB_MIN_DB_DELAY 1 +#define TSDB_MAX_DB_DELAY 10 +#define TSDB_DEFAULT_DB_DELAY 2 + #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 358edcb279..0fe5df183d 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -53,7 +53,6 @@ typedef enum EDatabaseOptionType { DB_OPTION_SINGLE_STABLE, DB_OPTION_STREAM_MODE, DB_OPTION_RETENTIONS, - DB_OPTION_FILE_FACTOR, DB_OPTION_MAX } EDatabaseOptionType; @@ -63,6 +62,8 @@ typedef enum ETableOptionType { TABLE_OPTION_TTL, TABLE_OPTION_COMMENT, TABLE_OPTION_SMA, + TABLE_OPTION_FILE_FACTOR, + TABLE_OPTION_DELAY, TABLE_OPTION_MAX } ETableOptionType; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 529fbb55c8..8f07d66a62 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -146,7 +146,6 @@ db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); } db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); } db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); } -db_options(A) ::= db_options(B) FILE_FACTOR NK_FLOAT(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FILE_FACTOR, &C); } alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); } alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); } @@ -263,6 +262,8 @@ table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); } table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); } table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); } +table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); } +table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); } alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); } alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index a958a748e2..c5a632482c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -248,12 +248,37 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio } static SDatabaseOptions* setDbRetentions(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { - // todo - return pOptions; -} + pOptions->pRetentions = nodesMakeList(); + if (NULL == pOptions->pRetentions) { + pCxt->valid = false; + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); + return pOptions; + } + + char val[20] = {0}; + int32_t len = trimString(pVal->z, pVal->n, val, sizeof(val)); + char* pStart = val; + char* pEnd = val + len; + int32_t sepOrder = 1; + while (1) { + char* pPos = strchr(pStart, (0 == sepOrder % 2) ? ',' : ':'); + SToken t = { .type = TK_NK_VARIABLE, .z = pStart, .n = (NULL == pPos ? pEnd - pStart : pPos - pStart)}; + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pOptions->pRetentions, createDurationValueNode(pCxt, &t))) { + pCxt->valid = false; + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); + return pOptions; + } + if (NULL == pPos) { + break; + } + pStart = pPos + 1; + } + + if (LIST_LENGTH(pOptions->pRetentions) % 2 != 0) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option retentions: %s", val); + pCxt->valid = false; + } -static SDatabaseOptions* setDbFileFactor(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { - // todo return pOptions; } @@ -276,7 +301,6 @@ static void initSetDatabaseOptionFp() { setDbOptionFuncs[DB_OPTION_SINGLE_STABLE] = setDbSingleStable; setDbOptionFuncs[DB_OPTION_STREAM_MODE] = setDbStreamMode; setDbOptionFuncs[DB_OPTION_RETENTIONS] = setDbRetentions; - setDbOptionFuncs[DB_OPTION_FILE_FACTOR] = setDbFileFactor; } static STableOptions* setTableKeep(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { @@ -314,10 +338,36 @@ static STableOptions* setTableComment(SAstCreateContext* pCxt, STableOptions* pO return pOptions; } +static STableOptions* setTableFileFactor(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { + double val = strtod(pVal->z, NULL); + if (val < TSDB_MIN_DB_FILE_FACTOR || val > TSDB_MAX_DB_FILE_FACTOR) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, + "invalid table option file_factor: %f valid range: [%d, %d]", val, TSDB_MIN_DB_FILE_FACTOR, TSDB_MAX_DB_FILE_FACTOR); + pCxt->valid = false; + return pOptions; + } + pOptions->filesFactor = val; + return pOptions; +} + +static STableOptions* setTableDelay(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) { + int64_t val = strtol(pVal->z, NULL, 10); + if (val < TSDB_MIN_DB_DELAY || val > TSDB_MAX_DB_DELAY) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, + "invalid table option delay: %"PRId64" valid range: [%d, %d]", val, TSDB_MIN_DB_DELAY, TSDB_MAX_DB_DELAY); + pCxt->valid = false; + return pOptions; + } + pOptions->delay = val; + return pOptions; +} + static void initSetTableOptionFp() { setTableOptionFuncs[TABLE_OPTION_KEEP] = setTableKeep; setTableOptionFuncs[TABLE_OPTION_TTL] = setTableTtl; setTableOptionFuncs[TABLE_OPTION_COMMENT] = setTableComment; + setTableOptionFuncs[TABLE_OPTION_FILE_FACTOR] = setTableFileFactor; + setTableOptionFuncs[TABLE_OPTION_DELAY] = setTableDelay; } void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { @@ -906,6 +956,8 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->keep = TSDB_DEFAULT_KEEP; pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION; + pOptions->filesFactor = TSDB_DEFAULT_DB_FILE_FACTOR; + pOptions->delay = TSDB_DEFAULT_DB_DELAY; return (SNode*)pOptions; } @@ -914,6 +966,8 @@ SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->keep = -1; pOptions->ttl = -1; + pOptions->filesFactor = -1; + pOptions->delay = -1; return (SNode*)pOptions; } @@ -927,7 +981,12 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS } SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pFuncs) { - // todo + if (1 != LIST_LENGTH(pFuncs)) { + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table option rollup: only one function is allowed"); + pCxt->valid = false; + return pOptions; + } + ((STableOptions*)pOptions)->pFuncs = pFuncs; return pOptions; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 79651cd325..766e606823 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -48,6 +48,7 @@ static SKeyword keywordTable[] = { {"DATABASE", TK_DATABASE}, {"DATABASES", TK_DATABASES}, {"DAYS", TK_DAYS}, + {"DELAY", TK_DELAY}, {"DESC", TK_DESC}, {"DISTINCT", TK_DISTINCT}, {"DNODE", TK_DNODE}, @@ -55,7 +56,7 @@ static SKeyword keywordTable[] = { {"DOUBLE", TK_DOUBLE}, {"DROP", TK_DROP}, {"EXISTS", TK_EXISTS}, - // {"FILE", TK_FILE}, + {"FILE_FACTOR", TK_FILE_FACTOR}, {"FILL", TK_FILL}, {"FLOAT", TK_FLOAT}, {"FROM", TK_FROM}, @@ -107,6 +108,8 @@ static SKeyword keywordTable[] = { {"QNODES", TK_QNODES}, {"QUORUM", TK_QUORUM}, {"REPLICA", TK_REPLICA}, + {"RETENTIONS", TK_RETENTIONS}, + {"ROLLUP", TK_ROLLUP}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, {"SHOW", TK_SHOW}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 60ee8be76d..6771eafa09 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -920,7 +920,35 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } -static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) { +static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) { + if (NULL != pRetentions) { + pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions) / 2, sizeof(SRetention)); + if (NULL == pReq->pRetensions) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SValueNode* pFreq = NULL; + SValueNode* pKeep = NULL; + SNode* pNode = NULL; + int32_t index = 0; + FOREACH(pNode, pRetentions) { + if (0 == index % 2) { + pFreq = (SValueNode*)pNode; + } else { + pKeep = (SValueNode*)pNode; + SRetention retention = { + .freq = pFreq->datum.i, + .freqUnit = pFreq->unit, + .keep = pKeep->datum.i, + .keepUnit = pKeep->unit + }; + taosArrayPush(pReq->pRetensions, &retention); + } + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) { SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, pReq->db); @@ -944,27 +972,45 @@ static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt pReq->cacheLastRow = pStmt->pOptions->cachelast; pReq->ignoreExist = pStmt->ignoreExists; pReq->streamMode = pStmt->pOptions->streamMode; - return; + return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); +} + +static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { + if (NULL != pStmt->pOptions->pRetentions) { + SNode* pNode = NULL; + FOREACH(pNode, pStmt->pOptions->pRetentions) { + if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode)) { + return pCxt->errCode; + } + } + } + return TSDB_CODE_SUCCESS; } static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { SCreateDbReq createReq = {0}; - buildCreateDbReq(pCxt, pStmt, &createReq); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = checkCreateDatabase(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = buildCreateDbReq(pCxt, pStmt, &createReq); } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; + pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + } + + return code; } static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { @@ -1035,7 +1081,7 @@ static int32_t calcTypeBytes(SDataType dt) { } } -static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { +static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); SNode* pNode; FOREACH(pNode, pList) { @@ -1047,13 +1093,77 @@ static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { return TSDB_CODE_SUCCESS; } +static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) { + if (NULL == pList) { + return TSDB_CODE_SUCCESS; + } + + *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); + SNode* pNode; + FOREACH(pNode, pList) { + SColumnNode* pCol = (SColumnNode*)pNode; + SField field = { .type = pCol->node.resType.type, .bytes = calcTypeBytes(pCol->node.resType) }; + strcpy(field.name, pCol->colName); + taosArrayPush(*pArray, &field); + } + return TSDB_CODE_SUCCESS; +} + +static const SColumnDefNode* findColDef(const SNodeList* pCols, const SColumnNode* pCol) { + SNode* pColDef = NULL; + FOREACH(pColDef, pCols) { + if (0 == strcmp(pCol->colName, ((SColumnDefNode*)pColDef)->colName)) { + return (SColumnDefNode*)pColDef; + } + } + return NULL; +} + +static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { + if (NULL != pStmt->pOptions->pSma) { + SNode* pNode = NULL; + FOREACH(pNode, pStmt->pOptions->pSma) { + SColumnNode* pSmaCol = (SColumnNode*)pNode; + const SColumnDefNode* pColDef = findColDef(pStmt->pCols, pSmaCol); + if (NULL == pColDef) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pSmaCol->colName); + } + pSmaCol->node.resType = pColDef->dataType; + } + } + if (NULL != pStmt->pOptions->pFuncs) { + SFunctionNode* pFunc = nodesListGetNode(pStmt->pOptions->pFuncs, 0); + if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t getAggregationMethod(SNodeList* pFuncs) { + if (NULL == pFuncs) { + return -1; + } + return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId; +} + static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { + int32_t code = checkCreateTable(pCxt, pStmt); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + SMCreateStbReq createReq = {0}; createReq.igExists = pStmt->ignoreExists; - columnNodeToField(pStmt->pCols, &createReq.pColumns); - columnNodeToField(pStmt->pTags, &createReq.pTags); + createReq.aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs); + createReq.xFilesFactor = pStmt->pOptions->filesFactor; + createReq.delay = pStmt->pOptions->delay; + columnDefNodeToField(pStmt->pCols, &createReq.pColumns); + columnDefNodeToField(pStmt->pTags, &createReq.pTags); + columnNodeToField(pStmt->pOptions->pSma, &createReq.pSmas); createReq.numOfColumns = LIST_LENGTH(pStmt->pCols); createReq.numOfTags = LIST_LENGTH(pStmt->pTags); + createReq.numOfSmas = LIST_LENGTH(pStmt->pOptions->pSma); SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId }; strcpy(tableName.dbname, pStmt->dbName); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 451587c8bf..b64eaee628 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -73,7 +73,7 @@ ** which is ParseTOKENTYPE. The entry in the union ** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If -** zero the stack is dynamically sized using taosMemoryRealloc() +** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument ** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter @@ -99,24 +99,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 258 +#define YYNOCODE 259 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - ENullOrder yy73; - SNodeList* yy136; - SNode* yy140; - EJoinType yy144; - SToken yy149; - EOrder yy158; - int32_t yy160; - SAlterOption yy233; - SDataType yy256; - EFillMode yy306; - EOperatorType yy320; - bool yy497; + SAlterOption yy11; + ENullOrder yy151; + EJoinType yy162; + SToken yy183; + bool yy215; + EOperatorType yy366; + SNode* yy378; + int32_t yy396; + EOrder yy400; + SNodeList* yy404; + EFillMode yy466; + SDataType yy504; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +131,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 430 -#define YYNRULE 337 -#define YYNTOKEN 163 -#define YY_MAX_SHIFT 429 -#define YY_MIN_SHIFTREDUCE 662 -#define YY_MAX_SHIFTREDUCE 998 -#define YY_ERROR_ACTION 999 -#define YY_ACCEPT_ACTION 1000 -#define YY_NO_ACTION 1001 -#define YY_MIN_REDUCE 1002 -#define YY_MAX_REDUCE 1338 +#define YYNSTATE 431 +#define YYNRULE 338 +#define YYNTOKEN 164 +#define YY_MAX_SHIFT 430 +#define YY_MIN_SHIFTREDUCE 664 +#define YY_MAX_SHIFTREDUCE 1001 +#define YY_ERROR_ACTION 1002 +#define YY_ACCEPT_ACTION 1003 +#define YY_NO_ACTION 1004 +#define YY_MIN_REDUCE 1005 +#define YY_MAX_REDUCE 1342 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,398 +208,393 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1263) +#define YY_ACTTAB_COUNT (1230) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1045, 1204, 225, 43, 24, 170, 362, 1200, 1206, 1095, - /* 10 */ 250, 269, 89, 31, 29, 27, 26, 25, 20, 1204, - /* 20 */ 1101, 27, 26, 25, 1084, 1200, 1205, 1106, 31, 29, - /* 30 */ 27, 26, 25, 361, 1000, 78, 209, 869, 77, 76, - /* 40 */ 75, 74, 73, 72, 71, 70, 69, 1091, 211, 414, - /* 50 */ 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, - /* 60 */ 403, 402, 401, 400, 399, 398, 397, 396, 1003, 105, - /* 70 */ 270, 1014, 881, 31, 29, 27, 26, 25, 1231, 132, - /* 80 */ 904, 349, 111, 249, 237, 346, 1216, 1180, 275, 78, - /* 90 */ 131, 22, 77, 76, 75, 74, 73, 72, 71, 70, - /* 100 */ 69, 31, 29, 27, 26, 25, 1231, 1317, 211, 291, - /* 110 */ 320, 286, 270, 346, 290, 44, 905, 289, 129, 287, - /* 120 */ 117, 345, 288, 348, 1315, 23, 232, 1192, 899, 900, - /* 130 */ 901, 902, 903, 907, 908, 909, 1082, 204, 1217, 1220, - /* 140 */ 904, 772, 385, 384, 383, 776, 382, 778, 779, 381, - /* 150 */ 781, 378, 109, 787, 375, 789, 790, 372, 369, 1151, - /* 160 */ 1216, 849, 128, 1144, 305, 224, 125, 43, 326, 189, - /* 170 */ 1149, 361, 1136, 30, 28, 941, 905, 847, 258, 242, - /* 180 */ 1231, 234, 395, 849, 1102, 23, 232, 346, 899, 900, - /* 190 */ 901, 902, 903, 907, 908, 909, 1204, 348, 361, 847, - /* 200 */ 896, 1192, 1200, 1205, 306, 362, 334, 848, 12, 118, - /* 210 */ 66, 61, 1217, 1220, 1256, 1216, 965, 279, 210, 1252, - /* 220 */ 1168, 10, 122, 121, 30, 28, 1106, 120, 1317, 848, - /* 230 */ 1317, 1, 234, 426, 849, 1231, 316, 963, 964, 966, - /* 240 */ 967, 117, 333, 117, 1216, 1315, 245, 1315, 10, 324, - /* 250 */ 847, 337, 348, 1171, 1173, 426, 1192, 349, 699, 12, - /* 260 */ 698, 850, 853, 1181, 1231, 362, 62, 1217, 1220, 1256, - /* 270 */ 66, 333, 283, 227, 1252, 112, 282, 285, 700, 330, - /* 280 */ 848, 348, 1, 850, 853, 1192, 1106, 166, 118, 9, - /* 290 */ 8, 59, 1216, 312, 1283, 62, 1217, 1220, 1256, 284, - /* 300 */ 92, 93, 227, 1252, 112, 1317, 426, 330, 1098, 106, - /* 310 */ 1073, 906, 1231, 31, 29, 27, 26, 25, 1316, 346, - /* 320 */ 21, 1216, 1315, 1284, 395, 1270, 90, 871, 92, 348, - /* 330 */ 910, 422, 421, 1192, 850, 853, 114, 1263, 1264, 870, - /* 340 */ 1268, 1231, 1267, 62, 1217, 1220, 1256, 334, 346, 118, - /* 350 */ 227, 1252, 1329, 698, 90, 1097, 1216, 867, 348, 917, - /* 360 */ 1231, 1290, 1192, 868, 163, 1263, 329, 346, 328, 277, - /* 370 */ 238, 1317, 62, 1217, 1220, 1256, 1231, 362, 104, 227, - /* 380 */ 1252, 1329, 1103, 346, 117, 1216, 1108, 388, 1315, 1025, - /* 390 */ 1313, 1093, 323, 348, 30, 28, 1192, 1192, 1106, 1024, - /* 400 */ 1270, 336, 234, 104, 849, 1231, 1083, 62, 1217, 1220, - /* 410 */ 1256, 1109, 346, 1151, 227, 1252, 1329, 1266, 362, 239, - /* 420 */ 847, 1151, 348, 359, 1149, 1274, 1192, 246, 165, 12, - /* 430 */ 1192, 334, 1149, 30, 28, 1015, 199, 1217, 1220, 1106, - /* 440 */ 1192, 234, 1216, 849, 194, 1023, 1022, 1021, 137, 196, - /* 450 */ 848, 135, 1, 1041, 319, 1317, 30, 28, 347, 847, - /* 460 */ 6, 195, 1231, 392, 234, 1216, 849, 391, 117, 346, - /* 470 */ 1020, 123, 1315, 1151, 118, 292, 426, 325, 321, 348, - /* 480 */ 1019, 1018, 847, 1192, 1172, 1231, 1192, 1192, 1192, 848, - /* 490 */ 393, 7, 346, 63, 1217, 1220, 1256, 1151, 872, 1089, - /* 500 */ 1255, 1252, 348, 1048, 850, 853, 1192, 948, 1150, 390, - /* 510 */ 389, 1192, 848, 869, 7, 426, 63, 1217, 1220, 1256, - /* 520 */ 244, 1192, 1192, 344, 1252, 30, 28, 303, 104, 30, - /* 530 */ 28, 64, 387, 234, 341, 849, 1108, 234, 426, 849, - /* 540 */ 301, 1216, 1270, 850, 853, 1002, 31, 29, 27, 26, - /* 550 */ 25, 847, 291, 936, 286, 847, 1017, 290, 118, 1265, - /* 560 */ 289, 1231, 287, 118, 1216, 288, 850, 853, 346, 87, - /* 570 */ 86, 85, 84, 83, 82, 81, 80, 79, 348, 867, - /* 580 */ 1036, 848, 1192, 7, 1231, 848, 251, 1, 1074, 263, - /* 590 */ 1016, 346, 107, 1217, 1220, 940, 429, 1192, 264, 151, - /* 600 */ 1216, 348, 294, 167, 362, 1192, 247, 426, 342, 360, - /* 610 */ 187, 426, 308, 88, 104, 63, 1217, 1220, 1256, 418, - /* 620 */ 1231, 186, 1108, 1253, 98, 1106, 1013, 346, 317, 335, - /* 630 */ 1330, 1192, 1034, 1012, 1011, 850, 853, 348, 362, 850, - /* 640 */ 853, 1192, 1145, 184, 233, 362, 60, 1010, 1009, 182, - /* 650 */ 248, 205, 1217, 1220, 297, 1008, 160, 1007, 1216, 1106, - /* 660 */ 1275, 936, 1232, 1216, 276, 262, 1106, 1192, 257, 256, - /* 670 */ 255, 254, 253, 338, 1192, 1192, 1006, 856, 1231, 139, - /* 680 */ 358, 1216, 138, 1231, 141, 346, 1216, 140, 1192, 1192, - /* 690 */ 346, 855, 994, 995, 311, 348, 1192, 147, 1192, 1192, - /* 700 */ 348, 1231, 313, 330, 1192, 331, 1231, 859, 346, 205, - /* 710 */ 1217, 1220, 1005, 346, 107, 1217, 1220, 1192, 348, 9, - /* 720 */ 8, 858, 1192, 348, 92, 231, 867, 1192, 1216, 939, - /* 730 */ 235, 1216, 205, 1217, 1220, 1286, 1216, 205, 1217, 1220, - /* 740 */ 31, 29, 27, 26, 25, 339, 330, 1170, 1231, 52, - /* 750 */ 90, 1231, 1331, 1192, 169, 346, 1231, 1081, 346, 332, - /* 760 */ 113, 1263, 1264, 346, 1268, 348, 1099, 92, 348, 1192, - /* 770 */ 2, 119, 1192, 348, 1216, 143, 260, 1192, 142, 203, - /* 780 */ 1217, 1220, 206, 1217, 1220, 962, 156, 197, 1217, 1220, - /* 790 */ 252, 259, 261, 90, 1231, 265, 1216, 41, 154, 881, - /* 800 */ 911, 346, 1216, 115, 1263, 1264, 875, 1268, 997, 998, - /* 810 */ 266, 348, 32, 267, 392, 1192, 1231, 124, 391, 874, - /* 820 */ 878, 58, 1231, 346, 127, 207, 1217, 1220, 1210, 346, - /* 830 */ 1216, 54, 32, 348, 842, 268, 1216, 1192, 271, 348, - /* 840 */ 1208, 393, 42, 1192, 278, 130, 32, 198, 1217, 1220, - /* 850 */ 1231, 873, 68, 208, 1217, 1220, 1231, 346, 175, 280, - /* 860 */ 390, 389, 223, 346, 1216, 1096, 354, 348, 181, 134, - /* 870 */ 173, 1192, 1092, 348, 765, 136, 100, 1192, 95, 101, - /* 880 */ 96, 1228, 1217, 1220, 1231, 1094, 98, 1227, 1217, 1220, - /* 890 */ 760, 346, 1216, 1090, 793, 797, 102, 803, 1216, 802, - /* 900 */ 310, 348, 41, 103, 146, 1192, 367, 96, 99, 97, - /* 910 */ 149, 98, 1231, 307, 309, 1226, 1217, 1220, 1231, 346, - /* 920 */ 96, 872, 318, 1297, 1287, 346, 352, 152, 853, 348, - /* 930 */ 315, 1296, 1216, 1192, 226, 348, 5, 159, 155, 1192, - /* 940 */ 1216, 322, 327, 214, 1217, 1220, 241, 240, 1277, 213, - /* 950 */ 1217, 1220, 1231, 314, 4, 161, 861, 936, 91, 346, - /* 960 */ 1231, 871, 110, 1271, 33, 162, 228, 346, 1216, 348, - /* 970 */ 1332, 340, 854, 1192, 296, 218, 343, 348, 17, 1238, - /* 980 */ 1179, 1192, 168, 215, 1217, 1220, 350, 1314, 1231, 304, - /* 990 */ 351, 212, 1217, 1220, 355, 346, 1178, 283, 356, 236, - /* 1000 */ 177, 282, 857, 145, 357, 348, 299, 179, 53, 1192, - /* 1010 */ 51, 293, 188, 219, 144, 217, 216, 190, 281, 202, - /* 1020 */ 1217, 1220, 1107, 365, 284, 185, 425, 200, 363, 201, - /* 1030 */ 192, 193, 1186, 825, 1163, 1162, 94, 1161, 1160, 40, - /* 1040 */ 1159, 1158, 39, 1157, 1156, 827, 1155, 1154, 1153, 1152, - /* 1050 */ 1047, 1185, 1176, 126, 1085, 711, 862, 853, 1046, 1044, - /* 1060 */ 272, 273, 274, 1033, 1032, 1029, 1087, 67, 133, 808, - /* 1070 */ 1086, 807, 1042, 1037, 740, 806, 1035, 739, 1028, 220, - /* 1080 */ 738, 1027, 221, 737, 222, 1184, 1183, 36, 1175, 150, - /* 1090 */ 300, 302, 3, 736, 735, 65, 45, 32, 14, 153, - /* 1100 */ 295, 37, 15, 158, 19, 298, 1208, 34, 11, 164, - /* 1110 */ 48, 8, 35, 16, 148, 897, 353, 1174, 180, 1001, - /* 1120 */ 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, - /* 1130 */ 983, 982, 229, 987, 986, 230, 863, 1001, 1001, 1001, - /* 1140 */ 1001, 1001, 1001, 178, 1001, 961, 1001, 108, 1001, 157, - /* 1150 */ 1001, 955, 46, 1001, 954, 933, 1001, 47, 1001, 1001, - /* 1160 */ 932, 1001, 988, 1001, 1001, 1001, 1001, 1001, 1001, 366, - /* 1170 */ 879, 13, 116, 18, 243, 172, 959, 174, 176, 1001, - /* 1180 */ 171, 49, 50, 1001, 1207, 38, 370, 1001, 373, 794, - /* 1190 */ 54, 376, 771, 1001, 379, 183, 1001, 364, 799, 1001, - /* 1200 */ 1001, 1001, 368, 731, 791, 371, 1043, 1001, 788, 723, - /* 1210 */ 1001, 428, 423, 801, 374, 786, 800, 782, 1001, 1001, - /* 1220 */ 1001, 730, 377, 729, 728, 709, 780, 727, 380, 394, - /* 1230 */ 785, 726, 1031, 725, 724, 417, 722, 721, 1030, 1026, - /* 1240 */ 416, 720, 55, 56, 57, 415, 420, 732, 719, 424, - /* 1250 */ 1001, 851, 718, 717, 716, 386, 715, 784, 191, 783, - /* 1260 */ 714, 419, 427, + /* 0 */ 1235, 1220, 225, 1208, 1220, 349, 242, 346, 237, 1204, + /* 10 */ 1210, 1184, 31, 29, 27, 26, 25, 1097, 105, 1208, + /* 20 */ 1017, 1235, 362, 1208, 1235, 1204, 1209, 66, 346, 1204, + /* 30 */ 1209, 346, 320, 1235, 279, 361, 24, 170, 348, 362, + /* 40 */ 346, 348, 1196, 1108, 66, 1196, 361, 211, 1048, 250, + /* 50 */ 334, 285, 107, 1221, 1224, 61, 1221, 1224, 1260, 362, + /* 60 */ 1108, 194, 210, 1256, 269, 323, 196, 349, 283, 884, + /* 70 */ 109, 362, 282, 1185, 1321, 209, 1105, 907, 195, 43, + /* 80 */ 1108, 1148, 31, 29, 27, 26, 25, 117, 123, 335, + /* 90 */ 1334, 1319, 1108, 284, 10, 1099, 1104, 415, 414, 413, + /* 100 */ 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, + /* 110 */ 402, 401, 400, 399, 398, 270, 908, 211, 31, 29, + /* 120 */ 27, 26, 25, 9, 8, 23, 232, 1006, 902, 903, + /* 130 */ 904, 905, 906, 910, 911, 912, 1196, 27, 26, 25, + /* 140 */ 31, 29, 27, 26, 25, 1003, 1028, 907, 78, 64, + /* 150 */ 870, 77, 76, 75, 74, 73, 72, 71, 70, 69, + /* 160 */ 319, 773, 385, 384, 383, 777, 382, 779, 780, 381, + /* 170 */ 782, 378, 1274, 788, 375, 790, 791, 372, 369, 872, + /* 180 */ 291, 118, 286, 325, 321, 290, 908, 1196, 289, 1271, + /* 190 */ 287, 920, 1220, 288, 249, 23, 232, 884, 902, 903, + /* 200 */ 904, 905, 906, 910, 911, 912, 31, 29, 27, 26, + /* 210 */ 25, 324, 1235, 106, 1075, 423, 422, 78, 1321, 333, + /* 220 */ 77, 76, 75, 74, 73, 72, 71, 70, 69, 348, + /* 230 */ 43, 117, 238, 1196, 968, 1319, 1321, 218, 118, 89, + /* 240 */ 104, 874, 1220, 62, 1221, 1224, 1260, 1103, 1110, 1320, + /* 250 */ 227, 1256, 112, 1319, 316, 966, 967, 969, 970, 283, + /* 260 */ 875, 330, 1235, 282, 166, 997, 998, 870, 118, 333, + /* 270 */ 312, 1287, 1220, 219, 251, 217, 216, 263, 281, 348, + /* 280 */ 245, 244, 92, 1196, 284, 362, 264, 1175, 1177, 104, + /* 290 */ 359, 1172, 1235, 62, 1221, 1224, 1260, 1110, 120, 346, + /* 300 */ 227, 1256, 112, 1279, 939, 361, 1108, 362, 90, 348, + /* 310 */ 1027, 700, 360, 1196, 701, 1220, 700, 332, 113, 1267, + /* 320 */ 1268, 1288, 1272, 62, 1221, 1224, 1260, 277, 1108, 330, + /* 330 */ 227, 1256, 1333, 6, 702, 1235, 1026, 30, 28, 241, + /* 340 */ 240, 1294, 346, 165, 1220, 234, 258, 852, 873, 864, + /* 350 */ 92, 1196, 348, 10, 262, 397, 1196, 257, 256, 255, + /* 360 */ 254, 253, 151, 850, 1235, 857, 62, 1221, 1224, 1260, + /* 370 */ 909, 346, 12, 227, 1256, 1333, 90, 1196, 362, 21, + /* 380 */ 1086, 348, 871, 184, 1317, 1196, 114, 1267, 1268, 913, + /* 390 */ 1272, 122, 121, 1, 1155, 62, 1221, 1224, 1260, 1108, + /* 400 */ 224, 1220, 227, 1256, 1333, 1153, 30, 28, 944, 1084, + /* 410 */ 30, 28, 189, 1278, 234, 1138, 852, 427, 234, 363, + /* 420 */ 852, 1235, 943, 118, 9, 8, 270, 939, 346, 851, + /* 430 */ 305, 860, 850, 1155, 951, 1025, 850, 1024, 348, 239, + /* 440 */ 872, 12, 1196, 1085, 1153, 12, 20, 334, 853, 856, + /* 450 */ 865, 856, 201, 1221, 1224, 397, 31, 29, 27, 26, + /* 460 */ 25, 104, 1, 118, 1023, 247, 1, 30, 28, 1111, + /* 470 */ 306, 1321, 1083, 104, 1155, 234, 1196, 852, 1196, 59, + /* 480 */ 246, 1110, 1274, 1220, 117, 1153, 427, 362, 1319, 93, + /* 490 */ 427, 388, 248, 850, 1321, 1155, 1100, 1022, 851, 1270, + /* 500 */ 394, 345, 851, 1235, 393, 1196, 1176, 117, 1108, 337, + /* 510 */ 346, 1319, 1220, 52, 1021, 1020, 1076, 853, 856, 1093, + /* 520 */ 348, 853, 856, 7, 1196, 395, 1019, 1016, 1015, 394, + /* 530 */ 1101, 1014, 1235, 393, 63, 1221, 1224, 1260, 1196, 346, + /* 540 */ 330, 1259, 1256, 1095, 392, 391, 390, 427, 389, 348, + /* 550 */ 30, 28, 347, 1196, 395, 1196, 1196, 942, 234, 851, + /* 560 */ 852, 92, 1013, 63, 1221, 1224, 1260, 1196, 1196, 1196, + /* 570 */ 344, 1256, 1196, 392, 391, 390, 850, 389, 853, 856, + /* 580 */ 334, 899, 1220, 308, 30, 28, 1012, 90, 1011, 1091, + /* 590 */ 1274, 1010, 234, 118, 852, 98, 1009, 163, 1267, 329, + /* 600 */ 852, 328, 1235, 1196, 1321, 1008, 7, 1269, 137, 346, + /* 610 */ 850, 135, 30, 28, 1155, 139, 850, 117, 138, 348, + /* 620 */ 234, 1319, 852, 1196, 1005, 1154, 303, 1196, 141, 1196, + /* 630 */ 427, 140, 1196, 63, 1221, 1224, 1260, 1196, 850, 301, + /* 640 */ 7, 1257, 851, 1044, 1000, 1001, 1196, 1039, 87, 86, + /* 650 */ 85, 84, 83, 82, 81, 80, 79, 1037, 430, 387, + /* 660 */ 336, 853, 856, 58, 427, 292, 1220, 341, 1, 294, + /* 670 */ 427, 143, 187, 54, 142, 88, 851, 965, 156, 297, + /* 680 */ 859, 419, 851, 186, 338, 1220, 1235, 914, 881, 41, + /* 690 */ 154, 1018, 427, 346, 167, 853, 856, 317, 1149, 32, + /* 700 */ 32, 853, 856, 348, 851, 1235, 60, 1196, 1214, 182, + /* 710 */ 233, 160, 346, 845, 276, 1220, 858, 205, 1221, 1224, + /* 720 */ 1212, 1220, 348, 853, 856, 32, 1196, 175, 1290, 313, + /* 730 */ 331, 354, 330, 1236, 1220, 1235, 205, 1221, 1224, 173, + /* 740 */ 358, 1235, 346, 95, 342, 169, 862, 2, 346, 870, + /* 750 */ 1174, 181, 348, 92, 1235, 252, 1196, 311, 348, 339, + /* 760 */ 147, 346, 1196, 96, 260, 766, 204, 1221, 1224, 761, + /* 770 */ 259, 348, 107, 1221, 1224, 1196, 119, 98, 231, 90, + /* 780 */ 1220, 41, 861, 794, 261, 205, 1221, 1224, 1220, 115, + /* 790 */ 1267, 1268, 22, 1272, 878, 367, 265, 326, 267, 798, + /* 800 */ 1235, 804, 31, 29, 27, 26, 25, 346, 1235, 266, + /* 810 */ 1335, 96, 124, 97, 803, 346, 1220, 348, 99, 877, + /* 820 */ 268, 1196, 1220, 271, 235, 348, 98, 127, 42, 1196, + /* 830 */ 96, 205, 1221, 1224, 130, 876, 1235, 278, 280, 203, + /* 840 */ 1221, 1224, 1235, 346, 1220, 68, 307, 1098, 223, 346, + /* 850 */ 134, 1094, 136, 348, 100, 146, 101, 1196, 1096, 348, + /* 860 */ 1092, 102, 103, 1196, 1235, 149, 875, 206, 1221, 1224, + /* 870 */ 309, 346, 1220, 199, 1221, 1224, 1301, 318, 1220, 352, + /* 880 */ 856, 348, 1300, 1291, 159, 1196, 310, 314, 5, 152, + /* 890 */ 1281, 1220, 1235, 315, 226, 207, 1221, 1224, 1235, 346, + /* 900 */ 155, 4, 322, 327, 939, 346, 91, 874, 33, 348, + /* 910 */ 161, 1235, 162, 1196, 1275, 348, 228, 343, 346, 1196, + /* 920 */ 1220, 340, 17, 200, 1221, 1224, 1220, 1242, 348, 208, + /* 930 */ 1221, 1224, 1196, 110, 1183, 350, 351, 355, 177, 1220, + /* 940 */ 1235, 1318, 1232, 1221, 1224, 1336, 1235, 346, 1220, 168, + /* 950 */ 1182, 236, 357, 346, 356, 179, 188, 348, 51, 1235, + /* 960 */ 53, 1196, 1109, 348, 1051, 365, 346, 1196, 1235, 190, + /* 970 */ 185, 1231, 1221, 1224, 426, 346, 348, 1230, 1221, 1224, + /* 980 */ 1196, 197, 198, 1220, 192, 348, 193, 1190, 828, 1196, + /* 990 */ 214, 1221, 1224, 132, 1167, 1166, 111, 94, 1165, 213, + /* 1000 */ 1221, 1224, 275, 1235, 131, 1164, 1163, 1162, 1161, 1160, + /* 1010 */ 346, 1220, 830, 291, 1159, 286, 1158, 1220, 290, 1157, + /* 1020 */ 348, 289, 1156, 287, 1196, 1050, 288, 44, 1189, 1180, + /* 1030 */ 129, 1235, 126, 1087, 215, 1221, 1224, 1235, 346, 713, + /* 1040 */ 1049, 1047, 296, 274, 346, 1036, 273, 1035, 348, 272, + /* 1050 */ 1032, 1089, 1196, 67, 348, 133, 811, 304, 1196, 810, + /* 1060 */ 1088, 809, 212, 1221, 1224, 741, 1045, 1040, 202, 1221, + /* 1070 */ 1224, 145, 740, 739, 299, 738, 220, 128, 221, 293, + /* 1080 */ 737, 125, 144, 295, 736, 1038, 222, 298, 1031, 1030, + /* 1090 */ 300, 302, 65, 1188, 1187, 36, 1179, 14, 45, 150, + /* 1100 */ 148, 3, 34, 15, 32, 40, 48, 37, 39, 11, + /* 1110 */ 8, 1212, 153, 158, 986, 985, 164, 964, 229, 990, + /* 1120 */ 108, 157, 989, 900, 958, 230, 46, 1178, 957, 47, + /* 1130 */ 1004, 866, 936, 353, 935, 1004, 1004, 1004, 1004, 1004, + /* 1140 */ 991, 178, 1046, 19, 882, 366, 1004, 13, 243, 1004, + /* 1150 */ 18, 35, 172, 116, 174, 16, 370, 373, 171, 962, + /* 1160 */ 176, 376, 1004, 49, 379, 50, 772, 800, 1034, 1033, + /* 1170 */ 806, 38, 1029, 802, 795, 792, 733, 54, 725, 368, + /* 1180 */ 1211, 183, 371, 364, 789, 374, 801, 732, 396, 783, + /* 1190 */ 377, 731, 421, 781, 711, 730, 380, 729, 55, 728, + /* 1200 */ 727, 56, 57, 726, 724, 723, 787, 786, 180, 722, + /* 1210 */ 785, 386, 721, 720, 719, 784, 718, 717, 716, 416, + /* 1220 */ 417, 420, 424, 425, 428, 418, 854, 191, 429, 805, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 0, 207, 190, 174, 221, 222, 172, 213, 214, 187, - /* 10 */ 172, 177, 183, 12, 13, 14, 15, 16, 2, 207, - /* 20 */ 191, 14, 15, 16, 0, 213, 214, 193, 12, 13, - /* 30 */ 14, 15, 16, 20, 163, 21, 198, 20, 24, 25, - /* 40 */ 26, 27, 28, 29, 30, 31, 32, 187, 47, 49, - /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - /* 60 */ 60, 61, 62, 63, 64, 65, 66, 67, 0, 165, - /* 70 */ 46, 167, 71, 12, 13, 14, 15, 16, 186, 33, - /* 80 */ 79, 203, 36, 212, 206, 193, 166, 209, 42, 21, - /* 90 */ 44, 2, 24, 25, 26, 27, 28, 29, 30, 31, - /* 100 */ 32, 12, 13, 14, 15, 16, 186, 236, 47, 49, - /* 110 */ 218, 51, 46, 193, 54, 69, 115, 57, 72, 59, - /* 120 */ 249, 47, 62, 203, 253, 124, 125, 207, 127, 128, - /* 130 */ 129, 130, 131, 132, 133, 134, 0, 217, 218, 219, - /* 140 */ 79, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 150 */ 94, 95, 185, 97, 98, 99, 100, 101, 102, 186, - /* 160 */ 166, 22, 116, 196, 172, 192, 120, 174, 248, 179, - /* 170 */ 197, 20, 182, 12, 13, 14, 115, 38, 63, 190, - /* 180 */ 186, 20, 46, 22, 191, 124, 125, 193, 127, 128, - /* 190 */ 129, 130, 131, 132, 133, 134, 207, 203, 20, 38, - /* 200 */ 126, 207, 213, 214, 212, 172, 212, 68, 47, 137, - /* 210 */ 177, 217, 218, 219, 220, 166, 126, 184, 224, 225, - /* 220 */ 193, 70, 107, 108, 12, 13, 193, 200, 236, 68, - /* 230 */ 236, 70, 20, 94, 22, 186, 146, 147, 148, 149, - /* 240 */ 150, 249, 193, 249, 166, 253, 195, 253, 70, 20, - /* 250 */ 38, 3, 203, 202, 203, 94, 207, 203, 20, 47, - /* 260 */ 22, 122, 123, 209, 186, 172, 217, 218, 219, 220, - /* 270 */ 177, 193, 57, 224, 225, 226, 61, 184, 40, 172, - /* 280 */ 68, 203, 70, 122, 123, 207, 193, 238, 137, 1, - /* 290 */ 2, 171, 166, 244, 245, 217, 218, 219, 220, 84, - /* 300 */ 193, 181, 224, 225, 226, 236, 94, 172, 188, 175, - /* 310 */ 176, 115, 186, 12, 13, 14, 15, 16, 249, 193, - /* 320 */ 124, 166, 253, 245, 46, 215, 219, 20, 193, 203, - /* 330 */ 134, 169, 170, 207, 122, 123, 229, 230, 231, 20, - /* 340 */ 233, 186, 232, 217, 218, 219, 220, 212, 193, 137, - /* 350 */ 224, 225, 226, 22, 219, 166, 166, 20, 203, 71, - /* 360 */ 186, 235, 207, 20, 229, 230, 231, 193, 233, 38, - /* 370 */ 178, 236, 217, 218, 219, 220, 186, 172, 186, 224, - /* 380 */ 225, 226, 177, 193, 249, 166, 194, 81, 253, 166, - /* 390 */ 235, 187, 218, 203, 12, 13, 207, 207, 193, 166, - /* 400 */ 215, 153, 20, 186, 22, 186, 0, 217, 218, 219, - /* 410 */ 220, 194, 193, 186, 224, 225, 226, 232, 172, 192, - /* 420 */ 38, 186, 203, 177, 197, 235, 207, 192, 121, 47, - /* 430 */ 207, 212, 197, 12, 13, 167, 217, 218, 219, 193, - /* 440 */ 207, 20, 166, 22, 18, 166, 166, 166, 74, 23, - /* 450 */ 68, 77, 70, 0, 119, 236, 12, 13, 14, 38, - /* 460 */ 43, 35, 186, 57, 20, 166, 22, 61, 249, 193, - /* 470 */ 166, 45, 253, 186, 137, 22, 94, 142, 143, 203, - /* 480 */ 166, 166, 38, 207, 197, 186, 207, 207, 207, 68, - /* 490 */ 84, 70, 193, 217, 218, 219, 220, 186, 20, 187, - /* 500 */ 224, 225, 203, 0, 122, 123, 207, 14, 197, 103, - /* 510 */ 104, 207, 68, 20, 70, 94, 217, 218, 219, 220, - /* 520 */ 178, 207, 207, 224, 225, 12, 13, 21, 186, 12, - /* 530 */ 13, 105, 187, 20, 83, 22, 194, 20, 94, 22, - /* 540 */ 34, 166, 215, 122, 123, 0, 12, 13, 14, 15, - /* 550 */ 16, 38, 49, 136, 51, 38, 166, 54, 137, 232, - /* 560 */ 57, 186, 59, 137, 166, 62, 122, 123, 193, 24, - /* 570 */ 25, 26, 27, 28, 29, 30, 31, 32, 203, 20, - /* 580 */ 0, 68, 207, 70, 186, 68, 27, 70, 176, 30, - /* 590 */ 166, 193, 217, 218, 219, 4, 19, 207, 39, 121, - /* 600 */ 166, 203, 22, 256, 172, 207, 178, 94, 157, 177, - /* 610 */ 33, 94, 71, 36, 186, 217, 218, 219, 220, 42, - /* 620 */ 186, 44, 194, 225, 83, 193, 166, 193, 247, 254, - /* 630 */ 255, 207, 0, 166, 166, 122, 123, 203, 172, 122, - /* 640 */ 123, 207, 196, 177, 210, 172, 69, 166, 166, 72, - /* 650 */ 177, 217, 218, 219, 22, 166, 241, 166, 166, 193, - /* 660 */ 135, 136, 186, 166, 169, 106, 193, 207, 109, 110, - /* 670 */ 111, 112, 113, 83, 207, 207, 166, 38, 186, 74, - /* 680 */ 103, 166, 77, 186, 74, 193, 166, 77, 207, 207, - /* 690 */ 193, 38, 158, 159, 117, 203, 207, 120, 207, 207, - /* 700 */ 203, 186, 210, 172, 207, 234, 186, 68, 193, 217, - /* 710 */ 218, 219, 166, 193, 217, 218, 219, 207, 203, 1, - /* 720 */ 2, 68, 207, 203, 193, 210, 20, 207, 166, 138, - /* 730 */ 210, 166, 217, 218, 219, 216, 166, 217, 218, 219, - /* 740 */ 12, 13, 14, 15, 16, 155, 172, 172, 186, 171, - /* 750 */ 219, 186, 255, 207, 250, 193, 186, 0, 193, 228, - /* 760 */ 229, 230, 231, 193, 233, 203, 188, 193, 203, 207, - /* 770 */ 237, 114, 207, 203, 166, 74, 115, 207, 77, 217, - /* 780 */ 218, 219, 217, 218, 219, 71, 71, 217, 218, 219, - /* 790 */ 201, 199, 199, 219, 186, 172, 166, 83, 83, 71, - /* 800 */ 71, 193, 166, 229, 230, 231, 20, 233, 161, 162, - /* 810 */ 211, 203, 83, 193, 57, 207, 186, 174, 61, 20, - /* 820 */ 71, 70, 186, 193, 174, 217, 218, 219, 70, 193, - /* 830 */ 166, 80, 83, 203, 71, 204, 166, 207, 172, 203, - /* 840 */ 82, 84, 174, 207, 168, 174, 83, 217, 218, 219, - /* 850 */ 186, 20, 172, 217, 218, 219, 186, 193, 71, 186, - /* 860 */ 103, 104, 168, 193, 166, 186, 71, 203, 71, 186, - /* 870 */ 83, 207, 186, 203, 71, 186, 186, 207, 83, 186, - /* 880 */ 83, 217, 218, 219, 186, 186, 83, 217, 218, 219, - /* 890 */ 71, 193, 166, 186, 71, 71, 186, 71, 166, 71, - /* 900 */ 204, 203, 83, 186, 171, 207, 83, 83, 71, 83, - /* 910 */ 171, 83, 186, 211, 193, 217, 218, 219, 186, 193, - /* 920 */ 83, 20, 145, 246, 216, 193, 144, 208, 123, 203, - /* 930 */ 207, 246, 166, 207, 207, 203, 152, 242, 208, 207, - /* 940 */ 166, 207, 151, 217, 218, 219, 12, 13, 243, 217, - /* 950 */ 218, 219, 186, 140, 139, 239, 22, 136, 193, 193, - /* 960 */ 186, 20, 240, 215, 114, 227, 160, 193, 166, 203, - /* 970 */ 257, 154, 38, 207, 4, 35, 156, 203, 70, 223, - /* 980 */ 208, 207, 251, 217, 218, 219, 207, 252, 186, 19, - /* 990 */ 207, 217, 218, 219, 118, 193, 208, 57, 205, 207, - /* 1000 */ 193, 61, 68, 33, 204, 203, 36, 171, 70, 207, - /* 1010 */ 171, 41, 182, 73, 44, 75, 76, 172, 78, 217, - /* 1020 */ 218, 219, 193, 189, 84, 171, 168, 180, 94, 180, - /* 1030 */ 173, 164, 0, 82, 0, 0, 114, 0, 0, 69, - /* 1040 */ 0, 0, 72, 0, 0, 22, 0, 0, 0, 0, - /* 1050 */ 0, 0, 0, 43, 0, 48, 122, 123, 0, 0, - /* 1060 */ 38, 36, 43, 0, 0, 0, 0, 79, 77, 38, - /* 1070 */ 0, 38, 0, 0, 38, 22, 0, 38, 0, 22, - /* 1080 */ 38, 0, 22, 38, 22, 0, 0, 121, 0, 116, - /* 1090 */ 22, 22, 83, 38, 38, 20, 70, 83, 141, 71, - /* 1100 */ 39, 83, 141, 83, 83, 38, 82, 135, 141, 82, - /* 1110 */ 4, 2, 83, 83, 43, 126, 119, 0, 116, 258, - /* 1120 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1130 */ 38, 38, 38, 38, 38, 38, 22, 258, 258, 258, - /* 1140 */ 258, 258, 258, 43, 258, 71, 258, 70, 258, 70, - /* 1150 */ 258, 71, 70, 258, 71, 71, 258, 70, 258, 258, - /* 1160 */ 71, 258, 71, 258, 258, 258, 258, 258, 258, 38, - /* 1170 */ 71, 70, 82, 70, 38, 71, 71, 70, 70, 258, - /* 1180 */ 82, 70, 70, 258, 82, 70, 38, 258, 38, 71, - /* 1190 */ 80, 38, 22, 258, 38, 82, 258, 81, 22, 258, - /* 1200 */ 258, 258, 70, 22, 71, 70, 0, 258, 71, 22, - /* 1210 */ 258, 20, 22, 38, 70, 96, 38, 71, 258, 258, - /* 1220 */ 258, 38, 70, 38, 38, 48, 71, 38, 70, 47, - /* 1230 */ 96, 38, 0, 38, 38, 43, 38, 38, 0, 0, - /* 1240 */ 36, 38, 70, 70, 70, 38, 37, 68, 38, 21, - /* 1250 */ 258, 22, 38, 38, 38, 84, 38, 96, 22, 96, - /* 1260 */ 38, 38, 21, 258, 258, 258, 258, 258, 258, 258, - /* 1270 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1280 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1290 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1300 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1310 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1320 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1330 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1340 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1350 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1360 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1370 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1380 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1390 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1400 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1410 */ 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, - /* 1420 */ 258, 258, 258, 258, 258, 258, + /* 0 */ 187, 167, 191, 208, 167, 204, 191, 194, 207, 214, + /* 10 */ 215, 210, 12, 13, 14, 15, 16, 188, 166, 208, + /* 20 */ 168, 187, 173, 208, 187, 214, 215, 178, 194, 214, + /* 30 */ 215, 194, 219, 187, 185, 20, 222, 223, 204, 173, + /* 40 */ 194, 204, 208, 194, 178, 208, 20, 47, 0, 173, + /* 50 */ 213, 185, 218, 219, 220, 218, 219, 220, 221, 173, + /* 60 */ 194, 18, 225, 226, 178, 219, 23, 204, 57, 69, + /* 70 */ 186, 173, 61, 210, 237, 199, 178, 77, 35, 175, + /* 80 */ 194, 197, 12, 13, 14, 15, 16, 250, 45, 255, + /* 90 */ 256, 254, 194, 82, 68, 167, 192, 49, 50, 51, + /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + /* 110 */ 62, 63, 64, 65, 66, 46, 116, 47, 12, 13, + /* 120 */ 14, 15, 16, 1, 2, 125, 126, 0, 128, 129, + /* 130 */ 130, 131, 132, 133, 134, 135, 208, 14, 15, 16, + /* 140 */ 12, 13, 14, 15, 16, 164, 167, 77, 21, 106, + /* 150 */ 20, 24, 25, 26, 27, 28, 29, 30, 31, 32, + /* 160 */ 120, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 170 */ 92, 93, 216, 95, 96, 97, 98, 99, 100, 20, + /* 180 */ 49, 138, 51, 143, 144, 54, 116, 208, 57, 233, + /* 190 */ 59, 69, 167, 62, 213, 125, 126, 69, 128, 129, + /* 200 */ 130, 131, 132, 133, 134, 135, 12, 13, 14, 15, + /* 210 */ 16, 20, 187, 176, 177, 170, 171, 21, 237, 194, + /* 220 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 204, + /* 230 */ 175, 250, 179, 208, 127, 254, 237, 35, 138, 184, + /* 240 */ 187, 20, 167, 218, 219, 220, 221, 192, 195, 250, + /* 250 */ 225, 226, 227, 254, 147, 148, 149, 150, 151, 57, + /* 260 */ 20, 173, 187, 61, 239, 159, 160, 20, 138, 194, + /* 270 */ 245, 246, 167, 71, 27, 73, 74, 30, 76, 204, + /* 280 */ 196, 179, 194, 208, 82, 173, 39, 203, 204, 187, + /* 290 */ 178, 194, 187, 218, 219, 220, 221, 195, 201, 194, + /* 300 */ 225, 226, 227, 136, 137, 20, 194, 173, 220, 204, + /* 310 */ 167, 22, 178, 208, 20, 167, 22, 229, 230, 231, + /* 320 */ 232, 246, 234, 218, 219, 220, 221, 38, 194, 173, + /* 330 */ 225, 226, 227, 43, 40, 187, 167, 12, 13, 12, + /* 340 */ 13, 236, 194, 122, 167, 20, 63, 22, 20, 22, + /* 350 */ 194, 208, 204, 68, 107, 46, 208, 110, 111, 112, + /* 360 */ 113, 114, 122, 38, 187, 38, 218, 219, 220, 221, + /* 370 */ 116, 194, 47, 225, 226, 227, 220, 208, 173, 125, + /* 380 */ 0, 204, 20, 178, 236, 208, 230, 231, 232, 135, + /* 390 */ 234, 108, 109, 68, 187, 218, 219, 220, 221, 194, + /* 400 */ 193, 167, 225, 226, 227, 198, 12, 13, 14, 0, + /* 410 */ 12, 13, 180, 236, 20, 183, 22, 92, 20, 92, + /* 420 */ 22, 187, 4, 138, 1, 2, 46, 137, 194, 104, + /* 430 */ 173, 104, 38, 187, 14, 167, 38, 167, 204, 193, + /* 440 */ 20, 47, 208, 0, 198, 47, 2, 213, 123, 124, + /* 450 */ 123, 124, 218, 219, 220, 46, 12, 13, 14, 15, + /* 460 */ 16, 187, 68, 138, 167, 179, 68, 12, 13, 195, + /* 470 */ 213, 237, 0, 187, 187, 20, 208, 22, 208, 172, + /* 480 */ 193, 195, 216, 167, 250, 198, 92, 173, 254, 182, + /* 490 */ 92, 79, 178, 38, 237, 187, 189, 167, 104, 233, + /* 500 */ 57, 47, 104, 187, 61, 208, 198, 250, 194, 3, + /* 510 */ 194, 254, 167, 172, 167, 167, 177, 123, 124, 188, + /* 520 */ 204, 123, 124, 68, 208, 82, 167, 167, 167, 57, + /* 530 */ 189, 167, 187, 61, 218, 219, 220, 221, 208, 194, + /* 540 */ 173, 225, 226, 188, 101, 102, 103, 92, 105, 204, + /* 550 */ 12, 13, 14, 208, 82, 208, 208, 139, 20, 104, + /* 560 */ 22, 194, 167, 218, 219, 220, 221, 208, 208, 208, + /* 570 */ 225, 226, 208, 101, 102, 103, 38, 105, 123, 124, + /* 580 */ 213, 127, 167, 69, 12, 13, 167, 220, 167, 188, + /* 590 */ 216, 167, 20, 138, 22, 81, 167, 230, 231, 232, + /* 600 */ 22, 234, 187, 208, 237, 167, 68, 233, 72, 194, + /* 610 */ 38, 75, 12, 13, 187, 72, 38, 250, 75, 204, + /* 620 */ 20, 254, 22, 208, 0, 198, 21, 208, 72, 208, + /* 630 */ 92, 75, 208, 218, 219, 220, 221, 208, 38, 34, + /* 640 */ 68, 226, 104, 0, 162, 163, 208, 0, 24, 25, + /* 650 */ 26, 27, 28, 29, 30, 31, 32, 0, 19, 188, + /* 660 */ 154, 123, 124, 68, 92, 22, 167, 81, 68, 22, + /* 670 */ 92, 72, 33, 78, 75, 36, 104, 69, 69, 22, + /* 680 */ 38, 42, 104, 44, 81, 167, 187, 69, 69, 81, + /* 690 */ 81, 168, 92, 194, 257, 123, 124, 248, 197, 81, + /* 700 */ 81, 123, 124, 204, 104, 187, 67, 208, 68, 70, + /* 710 */ 211, 242, 194, 69, 170, 167, 38, 218, 219, 220, + /* 720 */ 80, 167, 204, 123, 124, 81, 208, 69, 217, 211, + /* 730 */ 235, 69, 173, 187, 167, 187, 218, 219, 220, 81, + /* 740 */ 101, 187, 194, 81, 158, 251, 104, 238, 194, 20, + /* 750 */ 173, 69, 204, 194, 187, 202, 208, 118, 204, 156, + /* 760 */ 121, 194, 208, 81, 116, 69, 218, 219, 220, 69, + /* 770 */ 200, 204, 218, 219, 220, 208, 115, 81, 211, 220, + /* 780 */ 167, 81, 104, 69, 200, 218, 219, 220, 167, 230, + /* 790 */ 231, 232, 2, 234, 20, 81, 173, 249, 194, 69, + /* 800 */ 187, 69, 12, 13, 14, 15, 16, 194, 187, 212, + /* 810 */ 256, 81, 175, 81, 69, 194, 167, 204, 69, 20, + /* 820 */ 205, 208, 167, 173, 211, 204, 81, 175, 175, 208, + /* 830 */ 81, 218, 219, 220, 175, 20, 187, 169, 187, 218, + /* 840 */ 219, 220, 187, 194, 167, 173, 212, 187, 169, 194, + /* 850 */ 187, 187, 187, 204, 187, 172, 187, 208, 187, 204, + /* 860 */ 187, 187, 187, 208, 187, 172, 20, 218, 219, 220, + /* 870 */ 194, 194, 167, 218, 219, 220, 247, 146, 167, 145, + /* 880 */ 124, 204, 247, 217, 243, 208, 205, 141, 153, 209, + /* 890 */ 244, 167, 187, 208, 208, 218, 219, 220, 187, 194, + /* 900 */ 209, 140, 208, 152, 137, 194, 194, 20, 115, 204, + /* 910 */ 240, 187, 228, 208, 216, 204, 161, 157, 194, 208, + /* 920 */ 167, 155, 68, 218, 219, 220, 167, 224, 204, 218, + /* 930 */ 219, 220, 208, 241, 209, 208, 208, 119, 194, 167, + /* 940 */ 187, 253, 218, 219, 220, 258, 187, 194, 167, 252, + /* 950 */ 209, 208, 205, 194, 206, 172, 183, 204, 172, 187, + /* 960 */ 68, 208, 194, 204, 0, 190, 194, 208, 187, 173, + /* 970 */ 172, 218, 219, 220, 169, 194, 204, 218, 219, 220, + /* 980 */ 208, 181, 181, 167, 174, 204, 165, 0, 80, 208, + /* 990 */ 218, 219, 220, 33, 0, 0, 36, 115, 0, 218, + /* 1000 */ 219, 220, 42, 187, 44, 0, 0, 0, 0, 0, + /* 1010 */ 194, 167, 22, 49, 0, 51, 0, 167, 54, 0, + /* 1020 */ 204, 57, 0, 59, 208, 0, 62, 67, 0, 0, + /* 1030 */ 70, 187, 43, 0, 218, 219, 220, 187, 194, 48, + /* 1040 */ 0, 0, 4, 43, 194, 0, 36, 0, 204, 38, + /* 1050 */ 0, 0, 208, 77, 204, 75, 38, 19, 208, 38, + /* 1060 */ 0, 22, 218, 219, 220, 38, 0, 0, 218, 219, + /* 1070 */ 220, 33, 38, 38, 36, 38, 22, 117, 22, 41, + /* 1080 */ 38, 121, 44, 39, 38, 0, 22, 38, 0, 0, + /* 1090 */ 22, 22, 20, 0, 0, 122, 0, 142, 68, 117, + /* 1100 */ 43, 81, 136, 142, 81, 67, 4, 81, 70, 142, + /* 1110 */ 2, 80, 69, 81, 38, 38, 80, 69, 38, 38, + /* 1120 */ 68, 68, 38, 127, 69, 38, 68, 0, 69, 68, + /* 1130 */ 259, 22, 69, 120, 69, 259, 259, 259, 259, 259, + /* 1140 */ 69, 43, 0, 81, 69, 38, 259, 68, 38, 259, + /* 1150 */ 68, 81, 69, 80, 68, 81, 38, 38, 80, 69, + /* 1160 */ 68, 38, 259, 68, 38, 68, 22, 22, 0, 0, + /* 1170 */ 38, 68, 0, 38, 69, 69, 22, 78, 22, 68, + /* 1180 */ 80, 80, 68, 79, 69, 68, 38, 38, 47, 69, + /* 1190 */ 68, 38, 37, 69, 48, 38, 68, 38, 68, 38, + /* 1200 */ 38, 68, 68, 38, 38, 38, 94, 94, 117, 38, + /* 1210 */ 94, 82, 38, 38, 38, 94, 38, 38, 38, 38, + /* 1220 */ 36, 38, 22, 21, 21, 43, 22, 22, 20, 104, + /* 1230 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1240 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1250 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1260 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1270 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1280 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1290 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1300 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1310 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1320 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1330 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1340 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1350 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1360 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1370 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1380 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 1390 */ 259, 259, 259, 259, }; -#define YY_SHIFT_COUNT (429) +#define YY_SHIFT_COUNT (430) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1241) +#define YY_SHIFT_MAX (1208) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 426, 212, 161, 382, 382, 382, 382, 421, 382, 382, - /* 10 */ 151, 513, 517, 444, 513, 513, 513, 513, 513, 513, - /* 20 */ 513, 513, 513, 513, 513, 513, 513, 513, 513, 513, - /* 30 */ 513, 513, 513, 178, 178, 178, 337, 934, 934, 13, - /* 40 */ 13, 934, 13, 13, 66, 17, 229, 229, 72, 319, - /* 50 */ 17, 13, 13, 17, 13, 17, 319, 17, 17, 13, - /* 60 */ 278, 1, 61, 61, 559, 14, 940, 139, 60, 139, - /* 70 */ 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, - /* 80 */ 139, 139, 139, 139, 139, 139, 139, 139, 238, 24, - /* 90 */ 307, 307, 307, 136, 343, 319, 17, 17, 17, 306, - /* 100 */ 56, 56, 56, 56, 56, 68, 503, 534, 90, 215, - /* 110 */ 335, 331, 478, 525, 417, 525, 493, 248, 591, 706, - /* 120 */ 657, 661, 661, 706, 786, 66, 343, 799, 66, 66, - /* 130 */ 706, 66, 831, 17, 17, 17, 17, 17, 17, 17, - /* 140 */ 17, 17, 17, 17, 706, 831, 786, 278, 343, 799, - /* 150 */ 278, 901, 777, 782, 805, 777, 782, 805, 805, 784, - /* 160 */ 791, 813, 815, 821, 343, 941, 850, 806, 820, 817, - /* 170 */ 908, 17, 782, 805, 805, 782, 805, 876, 343, 799, - /* 180 */ 278, 306, 278, 343, 938, 706, 278, 831, 1263, 1263, - /* 190 */ 1263, 1263, 0, 545, 577, 46, 970, 16, 89, 728, - /* 200 */ 406, 757, 301, 301, 301, 301, 301, 301, 301, 115, - /* 210 */ 288, 196, 7, 7, 7, 7, 374, 605, 610, 701, - /* 220 */ 453, 580, 632, 506, 541, 714, 715, 718, 647, 590, - /* 230 */ 451, 729, 74, 749, 758, 763, 787, 795, 797, 803, - /* 240 */ 639, 653, 819, 823, 824, 826, 828, 837, 751, 1032, - /* 250 */ 951, 1034, 1035, 922, 1037, 1038, 1040, 1041, 1043, 1044, - /* 260 */ 1023, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1010, 1054, - /* 270 */ 1007, 1058, 1059, 1022, 1025, 1019, 1063, 1064, 1065, 1066, - /* 280 */ 988, 991, 1031, 1033, 1053, 1070, 1036, 1039, 1042, 1045, - /* 290 */ 1055, 1056, 1072, 1057, 1073, 1060, 1061, 1076, 1062, 1067, - /* 300 */ 1078, 1068, 1081, 1069, 1075, 1085, 1086, 966, 1088, 1026, - /* 310 */ 1071, 973, 1009, 1014, 957, 1028, 1018, 1074, 1077, 1079, - /* 320 */ 1080, 1082, 1083, 1020, 1024, 1087, 1021, 961, 1084, 1089, - /* 330 */ 1027, 972, 1029, 1090, 1091, 1030, 967, 1106, 1092, 1093, - /* 340 */ 1094, 1095, 1096, 1097, 1109, 989, 1098, 1099, 1101, 1103, - /* 350 */ 1104, 1105, 1107, 1108, 997, 1111, 1117, 1100, 1002, 1112, - /* 360 */ 1110, 1102, 1113, 1114, 1115, 1116, 1118, 1131, 1136, 1132, - /* 370 */ 1133, 1148, 1135, 1137, 1150, 1144, 1146, 1153, 1152, 1155, - /* 380 */ 1156, 1158, 1119, 1134, 1161, 1163, 1170, 1171, 1172, 1173, - /* 390 */ 1174, 1175, 1178, 1176, 1177, 1182, 1179, 1181, 1183, 1185, - /* 400 */ 1186, 1189, 1193, 1195, 1196, 1187, 1198, 1199, 1203, 1210, - /* 410 */ 1214, 1215, 1216, 1218, 1222, 1206, 1207, 1204, 1192, 1232, - /* 420 */ 1223, 1209, 1238, 1239, 1190, 1228, 1229, 1236, 1241, 1191, + /* 0 */ 43, 325, 394, 398, 398, 398, 398, 455, 398, 398, + /* 10 */ 285, 572, 600, 538, 572, 572, 572, 572, 572, 572, + /* 20 */ 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, + /* 30 */ 572, 572, 572, 26, 26, 26, 130, 327, 327, 15, + /* 40 */ 15, 327, 15, 15, 69, 159, 191, 191, 100, 328, + /* 50 */ 159, 15, 15, 159, 15, 159, 328, 159, 159, 15, + /* 60 */ 309, 0, 70, 70, 247, 196, 202, 578, 131, 578, + /* 70 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, + /* 80 */ 578, 578, 578, 578, 578, 578, 578, 578, 294, 380, + /* 90 */ 221, 221, 221, 409, 362, 328, 159, 159, 159, 412, + /* 100 */ 78, 78, 78, 78, 78, 127, 964, 106, 107, 11, + /* 110 */ 40, 289, 240, 167, 290, 167, 420, 506, 418, 729, + /* 120 */ 661, 648, 648, 729, 774, 69, 362, 799, 69, 69, + /* 130 */ 729, 69, 815, 159, 159, 159, 159, 159, 159, 159, + /* 140 */ 159, 159, 159, 159, 729, 815, 774, 309, 362, 799, + /* 150 */ 309, 846, 731, 734, 756, 731, 734, 756, 756, 735, + /* 160 */ 751, 746, 761, 767, 362, 887, 793, 755, 760, 766, + /* 170 */ 854, 159, 734, 756, 756, 734, 756, 818, 362, 799, + /* 180 */ 309, 412, 309, 362, 892, 729, 309, 815, 1230, 1230, + /* 190 */ 1230, 1230, 48, 624, 639, 960, 1038, 443, 472, 444, + /* 200 */ 790, 128, 194, 194, 194, 194, 194, 194, 194, 283, + /* 210 */ 122, 254, 123, 123, 123, 123, 536, 543, 556, 599, + /* 220 */ 643, 647, 657, 605, 514, 608, 609, 423, 482, 603, + /* 230 */ 586, 618, 454, 619, 640, 644, 658, 662, 682, 696, + /* 240 */ 642, 678, 700, 714, 730, 732, 745, 749, 595, 987, + /* 250 */ 908, 994, 995, 882, 998, 1005, 1006, 1007, 1008, 1009, + /* 260 */ 990, 1014, 1016, 1019, 1022, 1025, 1028, 1029, 989, 1033, + /* 270 */ 991, 1040, 1041, 1011, 1010, 1000, 1045, 1047, 1050, 1051, + /* 280 */ 976, 980, 1018, 1021, 1039, 1060, 1027, 1034, 1035, 1037, + /* 290 */ 1042, 1046, 1066, 1054, 1067, 1056, 1044, 1085, 1064, 1049, + /* 300 */ 1088, 1068, 1089, 1069, 1072, 1093, 1094, 973, 1096, 1030, + /* 310 */ 1057, 982, 1020, 1023, 955, 1043, 1026, 1048, 1052, 1053, + /* 320 */ 1055, 1058, 1059, 1032, 1031, 1061, 1062, 961, 1063, 1065, + /* 330 */ 1036, 966, 1070, 1073, 1071, 1074, 967, 1102, 1076, 1077, + /* 340 */ 1080, 1081, 1084, 1087, 1108, 996, 1078, 1075, 1079, 1082, + /* 350 */ 1083, 1090, 1086, 1092, 1013, 1095, 1127, 1098, 1091, 1097, + /* 360 */ 1099, 1100, 1101, 1109, 1103, 1104, 1105, 1107, 1110, 1111, + /* 370 */ 1106, 1118, 1114, 1115, 1119, 1117, 1120, 1123, 1122, 1124, + /* 380 */ 1126, 1128, 1112, 1113, 1116, 1121, 1144, 1129, 1130, 1132, + /* 390 */ 1125, 1133, 1134, 1135, 1148, 1145, 1146, 1141, 1154, 1149, + /* 400 */ 1153, 1157, 1159, 1161, 1162, 1165, 1156, 1166, 1167, 1171, + /* 410 */ 1174, 1175, 1176, 1178, 1179, 1180, 1142, 1181, 1184, 1182, + /* 420 */ 1168, 1183, 1155, 1169, 1172, 1200, 1202, 1204, 1205, 1203, + /* 430 */ 1208, }; #define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-217) -#define YY_REDUCE_MAX (867) +#define YY_REDUCE_MIN (-205) +#define YY_REDUCE_MAX (850) static const short yy_reduce_ofst[] = { - /* 0 */ -129, -6, 49, 78, 126, 155, 190, 219, 276, 299, - /* 10 */ 135, 375, 398, 434, 492, -80, 497, 515, 520, 562, - /* 20 */ 565, 570, 608, 630, 636, 664, 670, 698, 726, 732, - /* 30 */ 766, 774, 802, 531, 107, 574, -8, -188, -11, 33, - /* 40 */ 93, -206, -166, 205, -171, -27, -108, 174, 69, -122, - /* 50 */ 192, 246, 432, 227, 466, 342, 51, 235, 428, 473, - /* 60 */ 120, -217, -217, -217, -162, -96, -33, 189, 134, 223, - /* 70 */ 233, 279, 280, 281, 304, 314, 315, 390, 424, 460, - /* 80 */ 467, 468, 481, 482, 489, 491, 510, 546, 162, -7, - /* 90 */ 110, 185, 327, 578, 27, 54, 217, 287, 311, -10, - /* 100 */ -178, -140, 204, 312, 345, 268, 412, 347, 381, 446, - /* 110 */ 415, 495, 519, 471, 471, 471, 476, 504, 533, 575, - /* 120 */ 589, 592, 593, 623, 599, 643, 620, 631, 650, 668, - /* 130 */ 666, 671, 676, 673, 679, 683, 686, 689, 690, 693, - /* 140 */ 699, 707, 710, 717, 680, 694, 702, 733, 721, 696, - /* 150 */ 739, 708, 677, 719, 723, 685, 730, 727, 734, 705, - /* 160 */ 695, 722, 716, 471, 765, 748, 738, 713, 735, 731, - /* 170 */ 756, 476, 772, 779, 783, 788, 792, 793, 807, 800, - /* 180 */ 836, 830, 839, 829, 834, 845, 854, 858, 847, 849, - /* 190 */ 857, 867, + /* 0 */ -19, -163, 25, 75, 105, 148, 177, 234, 316, 345, + /* 10 */ 367, -166, 415, 499, 518, 548, 554, 567, 613, 621, + /* 20 */ 649, 655, 677, 705, 711, 724, 753, 759, 772, 781, + /* 30 */ 816, 844, 850, 88, 156, 559, 257, -189, -185, -151, + /* 40 */ -134, -205, -114, -102, 55, 207, -187, -154, -1, -199, + /* 50 */ 53, 112, 134, 246, 205, 102, 84, 287, 286, 314, + /* 60 */ 307, -186, -186, -186, -124, -148, -116, -72, 37, -21, + /* 70 */ 143, 169, 268, 270, 297, 330, 347, 348, 359, 360, + /* 80 */ 361, 364, 395, 419, 421, 424, 429, 438, 45, -96, + /* 90 */ -44, 266, 374, 341, 97, -137, 274, 308, 427, 232, + /* 100 */ -171, 331, 355, 401, 471, 523, 339, 437, 449, 501, + /* 110 */ 469, 544, 511, 495, 495, 495, 546, 494, 509, 577, + /* 120 */ 553, 570, 584, 623, 597, 637, 604, 615, 652, 653, + /* 130 */ 650, 659, 668, 651, 660, 663, 664, 665, 667, 669, + /* 140 */ 671, 673, 674, 675, 672, 679, 634, 683, 676, 681, + /* 150 */ 693, 666, 629, 680, 685, 635, 691, 686, 694, 646, + /* 160 */ 641, 692, 670, 495, 712, 698, 684, 687, 688, 697, + /* 170 */ 703, 546, 725, 727, 728, 741, 743, 748, 744, 747, + /* 180 */ 783, 773, 786, 768, 775, 796, 798, 805, 800, 801, + /* 190 */ 810, 821, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 10 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 20 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 30 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 40 */ 999, 999, 999, 999, 1052, 999, 999, 999, 999, 999, - /* 50 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 60 */ 1050, 999, 1258, 999, 1164, 999, 999, 999, 999, 999, - /* 70 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 80 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 1052, - /* 90 */ 1269, 1269, 1269, 1050, 999, 999, 999, 999, 999, 1135, - /* 100 */ 999, 999, 999, 999, 999, 999, 999, 1333, 999, 1088, - /* 110 */ 1293, 999, 1285, 1261, 1275, 1262, 999, 1318, 1278, 999, - /* 120 */ 1169, 1166, 1166, 999, 999, 1052, 999, 999, 1052, 1052, - /* 130 */ 999, 1052, 999, 999, 999, 999, 999, 999, 999, 999, - /* 140 */ 999, 999, 999, 999, 999, 999, 999, 1050, 999, 999, - /* 150 */ 1050, 999, 1300, 1298, 999, 1300, 1298, 999, 999, 1312, - /* 160 */ 1308, 1291, 1289, 1275, 999, 999, 999, 1336, 1324, 1320, - /* 170 */ 999, 999, 1298, 999, 999, 1298, 999, 1177, 999, 999, - /* 180 */ 1050, 999, 1050, 999, 1104, 999, 1050, 999, 1138, 1138, - /* 190 */ 1053, 1004, 999, 999, 999, 999, 999, 999, 999, 999, - /* 200 */ 999, 999, 1230, 1311, 1310, 1229, 1235, 1234, 1233, 999, - /* 210 */ 999, 999, 1224, 1225, 1223, 1222, 999, 999, 999, 999, - /* 220 */ 999, 999, 999, 999, 999, 999, 999, 1259, 999, 1321, - /* 230 */ 1325, 999, 999, 999, 1209, 999, 999, 999, 999, 999, - /* 240 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 250 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 260 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 270 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 280 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 290 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 300 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 310 */ 999, 999, 1282, 1292, 999, 999, 999, 999, 999, 999, - /* 320 */ 999, 999, 999, 999, 1209, 999, 1309, 999, 1268, 1264, - /* 330 */ 999, 999, 1260, 999, 999, 1319, 999, 999, 999, 999, - /* 340 */ 999, 999, 999, 999, 1254, 999, 999, 999, 999, 999, - /* 350 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 360 */ 999, 1208, 999, 999, 999, 999, 999, 999, 999, 1132, - /* 370 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 380 */ 999, 999, 1117, 1115, 1114, 1113, 999, 1110, 999, 999, - /* 390 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 400 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 410 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, - /* 420 */ 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, + /* 0 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 10 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 20 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 30 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 40 */ 1002, 1002, 1002, 1002, 1055, 1002, 1002, 1002, 1002, 1002, + /* 50 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 60 */ 1053, 1002, 1262, 1002, 1168, 1002, 1002, 1002, 1002, 1002, + /* 70 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 80 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1055, + /* 90 */ 1273, 1273, 1273, 1053, 1002, 1002, 1002, 1002, 1002, 1137, + /* 100 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1337, 1002, 1090, + /* 110 */ 1297, 1002, 1289, 1265, 1279, 1266, 1002, 1322, 1282, 1002, + /* 120 */ 1173, 1170, 1170, 1002, 1002, 1055, 1002, 1002, 1055, 1055, + /* 130 */ 1002, 1055, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 140 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1053, 1002, 1002, + /* 150 */ 1053, 1002, 1304, 1302, 1002, 1304, 1302, 1002, 1002, 1316, + /* 160 */ 1312, 1295, 1293, 1279, 1002, 1002, 1002, 1340, 1328, 1324, + /* 170 */ 1002, 1002, 1302, 1002, 1002, 1302, 1002, 1181, 1002, 1002, + /* 180 */ 1053, 1002, 1053, 1002, 1106, 1002, 1053, 1002, 1140, 1140, + /* 190 */ 1056, 1007, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 200 */ 1002, 1002, 1234, 1315, 1314, 1233, 1239, 1238, 1237, 1002, + /* 210 */ 1002, 1002, 1228, 1229, 1227, 1226, 1002, 1002, 1002, 1002, + /* 220 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1263, 1002, 1325, + /* 230 */ 1329, 1002, 1002, 1002, 1213, 1002, 1002, 1002, 1002, 1002, + /* 240 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 250 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 260 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 270 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 280 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 290 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 300 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 310 */ 1002, 1002, 1286, 1296, 1002, 1002, 1002, 1002, 1002, 1002, + /* 320 */ 1002, 1002, 1002, 1002, 1213, 1002, 1313, 1002, 1272, 1268, + /* 330 */ 1002, 1002, 1264, 1002, 1002, 1323, 1002, 1002, 1002, 1002, + /* 340 */ 1002, 1002, 1002, 1002, 1258, 1002, 1002, 1002, 1002, 1002, + /* 350 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 360 */ 1002, 1212, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1134, + /* 370 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 380 */ 1002, 1002, 1119, 1117, 1116, 1115, 1002, 1112, 1002, 1002, + /* 390 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 400 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 410 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 420 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, + /* 430 */ 1002, }; /********** End of lemon-generated parsing tables *****************************/ @@ -773,197 +768,198 @@ static const char *const yyTokenName[] = { /* 64 */ "SINGLE_STABLE", /* 65 */ "STREAM_MODE", /* 66 */ "RETENTIONS", - /* 67 */ "FILE_FACTOR", - /* 68 */ "NK_FLOAT", - /* 69 */ "TABLE", - /* 70 */ "NK_LP", - /* 71 */ "NK_RP", - /* 72 */ "STABLE", - /* 73 */ "ADD", - /* 74 */ "COLUMN", - /* 75 */ "MODIFY", - /* 76 */ "RENAME", - /* 77 */ "TAG", - /* 78 */ "SET", - /* 79 */ "NK_EQ", - /* 80 */ "USING", - /* 81 */ "TAGS", - /* 82 */ "NK_DOT", - /* 83 */ "NK_COMMA", - /* 84 */ "COMMENT", - /* 85 */ "BOOL", - /* 86 */ "TINYINT", - /* 87 */ "SMALLINT", - /* 88 */ "INT", - /* 89 */ "INTEGER", - /* 90 */ "BIGINT", - /* 91 */ "FLOAT", - /* 92 */ "DOUBLE", - /* 93 */ "BINARY", - /* 94 */ "TIMESTAMP", - /* 95 */ "NCHAR", - /* 96 */ "UNSIGNED", - /* 97 */ "JSON", - /* 98 */ "VARCHAR", - /* 99 */ "MEDIUMBLOB", - /* 100 */ "BLOB", - /* 101 */ "VARBINARY", - /* 102 */ "DECIMAL", - /* 103 */ "SMA", - /* 104 */ "ROLLUP", - /* 105 */ "SHOW", - /* 106 */ "DATABASES", - /* 107 */ "TABLES", - /* 108 */ "STABLES", - /* 109 */ "MNODES", - /* 110 */ "MODULES", - /* 111 */ "QNODES", - /* 112 */ "FUNCTIONS", - /* 113 */ "INDEXES", - /* 114 */ "FROM", - /* 115 */ "LIKE", - /* 116 */ "INDEX", - /* 117 */ "FULLTEXT", - /* 118 */ "FUNCTION", - /* 119 */ "INTERVAL", - /* 120 */ "TOPIC", - /* 121 */ "AS", - /* 122 */ "NK_BOOL", - /* 123 */ "NK_VARIABLE", - /* 124 */ "BETWEEN", - /* 125 */ "IS", - /* 126 */ "NULL", - /* 127 */ "NK_LT", - /* 128 */ "NK_GT", - /* 129 */ "NK_LE", - /* 130 */ "NK_GE", - /* 131 */ "NK_NE", - /* 132 */ "MATCH", - /* 133 */ "NMATCH", - /* 134 */ "IN", - /* 135 */ "JOIN", - /* 136 */ "INNER", - /* 137 */ "SELECT", - /* 138 */ "DISTINCT", - /* 139 */ "WHERE", - /* 140 */ "PARTITION", - /* 141 */ "BY", - /* 142 */ "SESSION", - /* 143 */ "STATE_WINDOW", - /* 144 */ "SLIDING", - /* 145 */ "FILL", - /* 146 */ "VALUE", - /* 147 */ "NONE", - /* 148 */ "PREV", - /* 149 */ "LINEAR", - /* 150 */ "NEXT", - /* 151 */ "GROUP", - /* 152 */ "HAVING", - /* 153 */ "ORDER", - /* 154 */ "SLIMIT", - /* 155 */ "SOFFSET", - /* 156 */ "LIMIT", - /* 157 */ "OFFSET", - /* 158 */ "ASC", - /* 159 */ "DESC", - /* 160 */ "NULLS", - /* 161 */ "FIRST", - /* 162 */ "LAST", - /* 163 */ "cmd", - /* 164 */ "account_options", - /* 165 */ "alter_account_options", - /* 166 */ "literal", - /* 167 */ "alter_account_option", - /* 168 */ "user_name", - /* 169 */ "dnode_endpoint", - /* 170 */ "dnode_host_name", - /* 171 */ "not_exists_opt", - /* 172 */ "db_name", - /* 173 */ "db_options", - /* 174 */ "exists_opt", - /* 175 */ "alter_db_options", - /* 176 */ "alter_db_option", - /* 177 */ "full_table_name", - /* 178 */ "column_def_list", - /* 179 */ "tags_def_opt", - /* 180 */ "table_options", - /* 181 */ "multi_create_clause", - /* 182 */ "tags_def", - /* 183 */ "multi_drop_clause", - /* 184 */ "alter_table_clause", - /* 185 */ "alter_table_options", - /* 186 */ "column_name", - /* 187 */ "type_name", - /* 188 */ "create_subtable_clause", - /* 189 */ "specific_tags_opt", - /* 190 */ "literal_list", - /* 191 */ "drop_table_clause", - /* 192 */ "col_name_list", - /* 193 */ "table_name", - /* 194 */ "column_def", - /* 195 */ "func_name_list", - /* 196 */ "alter_table_option", - /* 197 */ "col_name", - /* 198 */ "db_name_cond_opt", - /* 199 */ "like_pattern_opt", - /* 200 */ "table_name_cond", - /* 201 */ "from_db_opt", - /* 202 */ "func_name", - /* 203 */ "function_name", - /* 204 */ "index_name", - /* 205 */ "index_options", - /* 206 */ "func_list", - /* 207 */ "duration_literal", - /* 208 */ "sliding_opt", - /* 209 */ "func", - /* 210 */ "expression_list", - /* 211 */ "topic_name", - /* 212 */ "query_expression", - /* 213 */ "signed", - /* 214 */ "signed_literal", - /* 215 */ "table_alias", - /* 216 */ "column_alias", - /* 217 */ "expression", - /* 218 */ "column_reference", - /* 219 */ "subquery", - /* 220 */ "predicate", - /* 221 */ "compare_op", - /* 222 */ "in_op", - /* 223 */ "in_predicate_value", - /* 224 */ "boolean_value_expression", - /* 225 */ "boolean_primary", - /* 226 */ "common_expression", - /* 227 */ "from_clause", - /* 228 */ "table_reference_list", - /* 229 */ "table_reference", - /* 230 */ "table_primary", - /* 231 */ "joined_table", - /* 232 */ "alias_opt", - /* 233 */ "parenthesized_joined_table", - /* 234 */ "join_type", - /* 235 */ "search_condition", - /* 236 */ "query_specification", - /* 237 */ "set_quantifier_opt", - /* 238 */ "select_list", - /* 239 */ "where_clause_opt", - /* 240 */ "partition_by_clause_opt", - /* 241 */ "twindow_clause_opt", - /* 242 */ "group_by_clause_opt", - /* 243 */ "having_clause_opt", - /* 244 */ "select_sublist", - /* 245 */ "select_item", - /* 246 */ "fill_opt", - /* 247 */ "fill_mode", - /* 248 */ "group_by_list", - /* 249 */ "query_expression_body", - /* 250 */ "order_by_clause_opt", - /* 251 */ "slimit_clause_opt", - /* 252 */ "limit_clause_opt", - /* 253 */ "query_primary", - /* 254 */ "sort_specification_list", - /* 255 */ "sort_specification", - /* 256 */ "ordering_specification_opt", - /* 257 */ "null_ordering_opt", + /* 67 */ "TABLE", + /* 68 */ "NK_LP", + /* 69 */ "NK_RP", + /* 70 */ "STABLE", + /* 71 */ "ADD", + /* 72 */ "COLUMN", + /* 73 */ "MODIFY", + /* 74 */ "RENAME", + /* 75 */ "TAG", + /* 76 */ "SET", + /* 77 */ "NK_EQ", + /* 78 */ "USING", + /* 79 */ "TAGS", + /* 80 */ "NK_DOT", + /* 81 */ "NK_COMMA", + /* 82 */ "COMMENT", + /* 83 */ "BOOL", + /* 84 */ "TINYINT", + /* 85 */ "SMALLINT", + /* 86 */ "INT", + /* 87 */ "INTEGER", + /* 88 */ "BIGINT", + /* 89 */ "FLOAT", + /* 90 */ "DOUBLE", + /* 91 */ "BINARY", + /* 92 */ "TIMESTAMP", + /* 93 */ "NCHAR", + /* 94 */ "UNSIGNED", + /* 95 */ "JSON", + /* 96 */ "VARCHAR", + /* 97 */ "MEDIUMBLOB", + /* 98 */ "BLOB", + /* 99 */ "VARBINARY", + /* 100 */ "DECIMAL", + /* 101 */ "SMA", + /* 102 */ "ROLLUP", + /* 103 */ "FILE_FACTOR", + /* 104 */ "NK_FLOAT", + /* 105 */ "DELAY", + /* 106 */ "SHOW", + /* 107 */ "DATABASES", + /* 108 */ "TABLES", + /* 109 */ "STABLES", + /* 110 */ "MNODES", + /* 111 */ "MODULES", + /* 112 */ "QNODES", + /* 113 */ "FUNCTIONS", + /* 114 */ "INDEXES", + /* 115 */ "FROM", + /* 116 */ "LIKE", + /* 117 */ "INDEX", + /* 118 */ "FULLTEXT", + /* 119 */ "FUNCTION", + /* 120 */ "INTERVAL", + /* 121 */ "TOPIC", + /* 122 */ "AS", + /* 123 */ "NK_BOOL", + /* 124 */ "NK_VARIABLE", + /* 125 */ "BETWEEN", + /* 126 */ "IS", + /* 127 */ "NULL", + /* 128 */ "NK_LT", + /* 129 */ "NK_GT", + /* 130 */ "NK_LE", + /* 131 */ "NK_GE", + /* 132 */ "NK_NE", + /* 133 */ "MATCH", + /* 134 */ "NMATCH", + /* 135 */ "IN", + /* 136 */ "JOIN", + /* 137 */ "INNER", + /* 138 */ "SELECT", + /* 139 */ "DISTINCT", + /* 140 */ "WHERE", + /* 141 */ "PARTITION", + /* 142 */ "BY", + /* 143 */ "SESSION", + /* 144 */ "STATE_WINDOW", + /* 145 */ "SLIDING", + /* 146 */ "FILL", + /* 147 */ "VALUE", + /* 148 */ "NONE", + /* 149 */ "PREV", + /* 150 */ "LINEAR", + /* 151 */ "NEXT", + /* 152 */ "GROUP", + /* 153 */ "HAVING", + /* 154 */ "ORDER", + /* 155 */ "SLIMIT", + /* 156 */ "SOFFSET", + /* 157 */ "LIMIT", + /* 158 */ "OFFSET", + /* 159 */ "ASC", + /* 160 */ "DESC", + /* 161 */ "NULLS", + /* 162 */ "FIRST", + /* 163 */ "LAST", + /* 164 */ "cmd", + /* 165 */ "account_options", + /* 166 */ "alter_account_options", + /* 167 */ "literal", + /* 168 */ "alter_account_option", + /* 169 */ "user_name", + /* 170 */ "dnode_endpoint", + /* 171 */ "dnode_host_name", + /* 172 */ "not_exists_opt", + /* 173 */ "db_name", + /* 174 */ "db_options", + /* 175 */ "exists_opt", + /* 176 */ "alter_db_options", + /* 177 */ "alter_db_option", + /* 178 */ "full_table_name", + /* 179 */ "column_def_list", + /* 180 */ "tags_def_opt", + /* 181 */ "table_options", + /* 182 */ "multi_create_clause", + /* 183 */ "tags_def", + /* 184 */ "multi_drop_clause", + /* 185 */ "alter_table_clause", + /* 186 */ "alter_table_options", + /* 187 */ "column_name", + /* 188 */ "type_name", + /* 189 */ "create_subtable_clause", + /* 190 */ "specific_tags_opt", + /* 191 */ "literal_list", + /* 192 */ "drop_table_clause", + /* 193 */ "col_name_list", + /* 194 */ "table_name", + /* 195 */ "column_def", + /* 196 */ "func_name_list", + /* 197 */ "alter_table_option", + /* 198 */ "col_name", + /* 199 */ "db_name_cond_opt", + /* 200 */ "like_pattern_opt", + /* 201 */ "table_name_cond", + /* 202 */ "from_db_opt", + /* 203 */ "func_name", + /* 204 */ "function_name", + /* 205 */ "index_name", + /* 206 */ "index_options", + /* 207 */ "func_list", + /* 208 */ "duration_literal", + /* 209 */ "sliding_opt", + /* 210 */ "func", + /* 211 */ "expression_list", + /* 212 */ "topic_name", + /* 213 */ "query_expression", + /* 214 */ "signed", + /* 215 */ "signed_literal", + /* 216 */ "table_alias", + /* 217 */ "column_alias", + /* 218 */ "expression", + /* 219 */ "column_reference", + /* 220 */ "subquery", + /* 221 */ "predicate", + /* 222 */ "compare_op", + /* 223 */ "in_op", + /* 224 */ "in_predicate_value", + /* 225 */ "boolean_value_expression", + /* 226 */ "boolean_primary", + /* 227 */ "common_expression", + /* 228 */ "from_clause", + /* 229 */ "table_reference_list", + /* 230 */ "table_reference", + /* 231 */ "table_primary", + /* 232 */ "joined_table", + /* 233 */ "alias_opt", + /* 234 */ "parenthesized_joined_table", + /* 235 */ "join_type", + /* 236 */ "search_condition", + /* 237 */ "query_specification", + /* 238 */ "set_quantifier_opt", + /* 239 */ "select_list", + /* 240 */ "where_clause_opt", + /* 241 */ "partition_by_clause_opt", + /* 242 */ "twindow_clause_opt", + /* 243 */ "group_by_clause_opt", + /* 244 */ "having_clause_opt", + /* 245 */ "select_sublist", + /* 246 */ "select_item", + /* 247 */ "fill_opt", + /* 248 */ "fill_mode", + /* 249 */ "group_by_list", + /* 250 */ "query_expression_body", + /* 251 */ "order_by_clause_opt", + /* 252 */ "slimit_clause_opt", + /* 253 */ "limit_clause_opt", + /* 254 */ "query_primary", + /* 255 */ "sort_specification_list", + /* 256 */ "sort_specification", + /* 257 */ "ordering_specification_opt", + /* 258 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1041,273 +1037,274 @@ static const char *const yyRuleName[] = { /* 67 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", /* 68 */ "db_options ::= db_options STREAM_MODE NK_INTEGER", /* 69 */ "db_options ::= db_options RETENTIONS NK_STRING", - /* 70 */ "db_options ::= db_options FILE_FACTOR NK_FLOAT", - /* 71 */ "alter_db_options ::= alter_db_option", - /* 72 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 73 */ "alter_db_option ::= BLOCKS NK_INTEGER", - /* 74 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 75 */ "alter_db_option ::= KEEP NK_INTEGER", - /* 76 */ "alter_db_option ::= WAL NK_INTEGER", - /* 77 */ "alter_db_option ::= QUORUM NK_INTEGER", - /* 78 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 79 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 80 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 81 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 82 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 83 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 84 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 85 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 86 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 87 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 88 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 89 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 90 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 91 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 92 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 93 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 94 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 95 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", - /* 96 */ "multi_create_clause ::= create_subtable_clause", - /* 97 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 98 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", - /* 99 */ "multi_drop_clause ::= drop_table_clause", - /* 100 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 101 */ "drop_table_clause ::= exists_opt full_table_name", - /* 102 */ "specific_tags_opt ::=", - /* 103 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 104 */ "full_table_name ::= table_name", - /* 105 */ "full_table_name ::= db_name NK_DOT table_name", - /* 106 */ "column_def_list ::= column_def", - /* 107 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 108 */ "column_def ::= column_name type_name", - /* 109 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 110 */ "type_name ::= BOOL", - /* 111 */ "type_name ::= TINYINT", - /* 112 */ "type_name ::= SMALLINT", - /* 113 */ "type_name ::= INT", - /* 114 */ "type_name ::= INTEGER", - /* 115 */ "type_name ::= BIGINT", - /* 116 */ "type_name ::= FLOAT", - /* 117 */ "type_name ::= DOUBLE", - /* 118 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 119 */ "type_name ::= TIMESTAMP", - /* 120 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 121 */ "type_name ::= TINYINT UNSIGNED", - /* 122 */ "type_name ::= SMALLINT UNSIGNED", - /* 123 */ "type_name ::= INT UNSIGNED", - /* 124 */ "type_name ::= BIGINT UNSIGNED", - /* 125 */ "type_name ::= JSON", - /* 126 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 127 */ "type_name ::= MEDIUMBLOB", - /* 128 */ "type_name ::= BLOB", - /* 129 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 130 */ "type_name ::= DECIMAL", - /* 131 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 132 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 133 */ "tags_def_opt ::=", - /* 134 */ "tags_def_opt ::= tags_def", - /* 135 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 136 */ "table_options ::=", - /* 137 */ "table_options ::= table_options COMMENT NK_STRING", - /* 138 */ "table_options ::= table_options KEEP NK_INTEGER", - /* 139 */ "table_options ::= table_options TTL NK_INTEGER", - /* 140 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 141 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", - /* 142 */ "alter_table_options ::= alter_table_option", - /* 143 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 144 */ "alter_table_option ::= COMMENT NK_STRING", - /* 145 */ "alter_table_option ::= KEEP NK_INTEGER", - /* 146 */ "alter_table_option ::= TTL NK_INTEGER", - /* 147 */ "col_name_list ::= col_name", - /* 148 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 149 */ "col_name ::= column_name", - /* 150 */ "cmd ::= SHOW DNODES", - /* 151 */ "cmd ::= SHOW USERS", - /* 152 */ "cmd ::= SHOW DATABASES", - /* 153 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 154 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 155 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 156 */ "cmd ::= SHOW MNODES", - /* 157 */ "cmd ::= SHOW MODULES", - /* 158 */ "cmd ::= SHOW QNODES", - /* 159 */ "cmd ::= SHOW FUNCTIONS", - /* 160 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 161 */ "cmd ::= SHOW STREAMS", - /* 162 */ "db_name_cond_opt ::=", - /* 163 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 164 */ "like_pattern_opt ::=", - /* 165 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 166 */ "table_name_cond ::= table_name", - /* 167 */ "from_db_opt ::=", - /* 168 */ "from_db_opt ::= FROM db_name", - /* 169 */ "func_name_list ::= func_name", - /* 170 */ "func_name_list ::= func_name_list NK_COMMA col_name", - /* 171 */ "func_name ::= function_name", - /* 172 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 173 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 174 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 175 */ "index_options ::=", - /* 176 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 177 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 178 */ "func_list ::= func", - /* 179 */ "func_list ::= func_list NK_COMMA func", - /* 180 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 181 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 182 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 183 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 184 */ "cmd ::= query_expression", - /* 185 */ "literal ::= NK_INTEGER", - /* 186 */ "literal ::= NK_FLOAT", - /* 187 */ "literal ::= NK_STRING", - /* 188 */ "literal ::= NK_BOOL", - /* 189 */ "literal ::= TIMESTAMP NK_STRING", - /* 190 */ "literal ::= duration_literal", - /* 191 */ "duration_literal ::= NK_VARIABLE", - /* 192 */ "signed ::= NK_INTEGER", - /* 193 */ "signed ::= NK_PLUS NK_INTEGER", - /* 194 */ "signed ::= NK_MINUS NK_INTEGER", - /* 195 */ "signed ::= NK_FLOAT", - /* 196 */ "signed ::= NK_PLUS NK_FLOAT", - /* 197 */ "signed ::= NK_MINUS NK_FLOAT", - /* 198 */ "signed_literal ::= signed", - /* 199 */ "signed_literal ::= NK_STRING", - /* 200 */ "signed_literal ::= NK_BOOL", - /* 201 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 202 */ "signed_literal ::= duration_literal", - /* 203 */ "literal_list ::= signed_literal", - /* 204 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 205 */ "db_name ::= NK_ID", - /* 206 */ "table_name ::= NK_ID", - /* 207 */ "column_name ::= NK_ID", - /* 208 */ "function_name ::= NK_ID", - /* 209 */ "table_alias ::= NK_ID", - /* 210 */ "column_alias ::= NK_ID", - /* 211 */ "user_name ::= NK_ID", - /* 212 */ "index_name ::= NK_ID", - /* 213 */ "topic_name ::= NK_ID", - /* 214 */ "expression ::= literal", - /* 215 */ "expression ::= column_reference", - /* 216 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 217 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 218 */ "expression ::= subquery", - /* 219 */ "expression ::= NK_LP expression NK_RP", - /* 220 */ "expression ::= NK_PLUS expression", - /* 221 */ "expression ::= NK_MINUS expression", - /* 222 */ "expression ::= expression NK_PLUS expression", - /* 223 */ "expression ::= expression NK_MINUS expression", - /* 224 */ "expression ::= expression NK_STAR expression", - /* 225 */ "expression ::= expression NK_SLASH expression", - /* 226 */ "expression ::= expression NK_REM expression", - /* 227 */ "expression_list ::= expression", - /* 228 */ "expression_list ::= expression_list NK_COMMA expression", - /* 229 */ "column_reference ::= column_name", - /* 230 */ "column_reference ::= table_name NK_DOT column_name", - /* 231 */ "predicate ::= expression compare_op expression", - /* 232 */ "predicate ::= expression BETWEEN expression AND expression", - /* 233 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 234 */ "predicate ::= expression IS NULL", - /* 235 */ "predicate ::= expression IS NOT NULL", - /* 236 */ "predicate ::= expression in_op in_predicate_value", - /* 237 */ "compare_op ::= NK_LT", - /* 238 */ "compare_op ::= NK_GT", - /* 239 */ "compare_op ::= NK_LE", - /* 240 */ "compare_op ::= NK_GE", - /* 241 */ "compare_op ::= NK_NE", - /* 242 */ "compare_op ::= NK_EQ", - /* 243 */ "compare_op ::= LIKE", - /* 244 */ "compare_op ::= NOT LIKE", - /* 245 */ "compare_op ::= MATCH", - /* 246 */ "compare_op ::= NMATCH", - /* 247 */ "in_op ::= IN", - /* 248 */ "in_op ::= NOT IN", - /* 249 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 250 */ "boolean_value_expression ::= boolean_primary", - /* 251 */ "boolean_value_expression ::= NOT boolean_primary", - /* 252 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 253 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 254 */ "boolean_primary ::= predicate", - /* 255 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 256 */ "common_expression ::= expression", - /* 257 */ "common_expression ::= boolean_value_expression", - /* 258 */ "from_clause ::= FROM table_reference_list", - /* 259 */ "table_reference_list ::= table_reference", - /* 260 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 261 */ "table_reference ::= table_primary", - /* 262 */ "table_reference ::= joined_table", - /* 263 */ "table_primary ::= table_name alias_opt", - /* 264 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 265 */ "table_primary ::= subquery alias_opt", - /* 266 */ "table_primary ::= parenthesized_joined_table", - /* 267 */ "alias_opt ::=", - /* 268 */ "alias_opt ::= table_alias", - /* 269 */ "alias_opt ::= AS table_alias", - /* 270 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 271 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 272 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 273 */ "join_type ::=", - /* 274 */ "join_type ::= INNER", - /* 275 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 276 */ "set_quantifier_opt ::=", - /* 277 */ "set_quantifier_opt ::= DISTINCT", - /* 278 */ "set_quantifier_opt ::= ALL", - /* 279 */ "select_list ::= NK_STAR", - /* 280 */ "select_list ::= select_sublist", - /* 281 */ "select_sublist ::= select_item", - /* 282 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 283 */ "select_item ::= common_expression", - /* 284 */ "select_item ::= common_expression column_alias", - /* 285 */ "select_item ::= common_expression AS column_alias", - /* 286 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 287 */ "where_clause_opt ::=", - /* 288 */ "where_clause_opt ::= WHERE search_condition", - /* 289 */ "partition_by_clause_opt ::=", - /* 290 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 291 */ "twindow_clause_opt ::=", - /* 292 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 293 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 294 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 295 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 296 */ "sliding_opt ::=", - /* 297 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 298 */ "fill_opt ::=", - /* 299 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 300 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 301 */ "fill_mode ::= NONE", - /* 302 */ "fill_mode ::= PREV", - /* 303 */ "fill_mode ::= NULL", - /* 304 */ "fill_mode ::= LINEAR", - /* 305 */ "fill_mode ::= NEXT", - /* 306 */ "group_by_clause_opt ::=", - /* 307 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 308 */ "group_by_list ::= expression", - /* 309 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 310 */ "having_clause_opt ::=", - /* 311 */ "having_clause_opt ::= HAVING search_condition", - /* 312 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 313 */ "query_expression_body ::= query_primary", - /* 314 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 315 */ "query_primary ::= query_specification", - /* 316 */ "order_by_clause_opt ::=", - /* 317 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 318 */ "slimit_clause_opt ::=", - /* 319 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 320 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 321 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 322 */ "limit_clause_opt ::=", - /* 323 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 324 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 325 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 326 */ "subquery ::= NK_LP query_expression NK_RP", - /* 327 */ "search_condition ::= common_expression", - /* 328 */ "sort_specification_list ::= sort_specification", - /* 329 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 330 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 331 */ "ordering_specification_opt ::=", - /* 332 */ "ordering_specification_opt ::= ASC", - /* 333 */ "ordering_specification_opt ::= DESC", - /* 334 */ "null_ordering_opt ::=", - /* 335 */ "null_ordering_opt ::= NULLS FIRST", - /* 336 */ "null_ordering_opt ::= NULLS LAST", + /* 70 */ "alter_db_options ::= alter_db_option", + /* 71 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 72 */ "alter_db_option ::= BLOCKS NK_INTEGER", + /* 73 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 74 */ "alter_db_option ::= KEEP NK_INTEGER", + /* 75 */ "alter_db_option ::= WAL NK_INTEGER", + /* 76 */ "alter_db_option ::= QUORUM NK_INTEGER", + /* 77 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 78 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 79 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 80 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 81 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 82 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 83 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 84 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 85 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 86 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 87 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 88 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 89 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 90 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 91 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 92 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 93 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 94 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", + /* 95 */ "multi_create_clause ::= create_subtable_clause", + /* 96 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 97 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", + /* 98 */ "multi_drop_clause ::= drop_table_clause", + /* 99 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 100 */ "drop_table_clause ::= exists_opt full_table_name", + /* 101 */ "specific_tags_opt ::=", + /* 102 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 103 */ "full_table_name ::= table_name", + /* 104 */ "full_table_name ::= db_name NK_DOT table_name", + /* 105 */ "column_def_list ::= column_def", + /* 106 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 107 */ "column_def ::= column_name type_name", + /* 108 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 109 */ "type_name ::= BOOL", + /* 110 */ "type_name ::= TINYINT", + /* 111 */ "type_name ::= SMALLINT", + /* 112 */ "type_name ::= INT", + /* 113 */ "type_name ::= INTEGER", + /* 114 */ "type_name ::= BIGINT", + /* 115 */ "type_name ::= FLOAT", + /* 116 */ "type_name ::= DOUBLE", + /* 117 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 118 */ "type_name ::= TIMESTAMP", + /* 119 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 120 */ "type_name ::= TINYINT UNSIGNED", + /* 121 */ "type_name ::= SMALLINT UNSIGNED", + /* 122 */ "type_name ::= INT UNSIGNED", + /* 123 */ "type_name ::= BIGINT UNSIGNED", + /* 124 */ "type_name ::= JSON", + /* 125 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 126 */ "type_name ::= MEDIUMBLOB", + /* 127 */ "type_name ::= BLOB", + /* 128 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 129 */ "type_name ::= DECIMAL", + /* 130 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 131 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 132 */ "tags_def_opt ::=", + /* 133 */ "tags_def_opt ::= tags_def", + /* 134 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 135 */ "table_options ::=", + /* 136 */ "table_options ::= table_options COMMENT NK_STRING", + /* 137 */ "table_options ::= table_options KEEP NK_INTEGER", + /* 138 */ "table_options ::= table_options TTL NK_INTEGER", + /* 139 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 140 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", + /* 141 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", + /* 142 */ "table_options ::= table_options DELAY NK_INTEGER", + /* 143 */ "alter_table_options ::= alter_table_option", + /* 144 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 145 */ "alter_table_option ::= COMMENT NK_STRING", + /* 146 */ "alter_table_option ::= KEEP NK_INTEGER", + /* 147 */ "alter_table_option ::= TTL NK_INTEGER", + /* 148 */ "col_name_list ::= col_name", + /* 149 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 150 */ "col_name ::= column_name", + /* 151 */ "cmd ::= SHOW DNODES", + /* 152 */ "cmd ::= SHOW USERS", + /* 153 */ "cmd ::= SHOW DATABASES", + /* 154 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 155 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 156 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 157 */ "cmd ::= SHOW MNODES", + /* 158 */ "cmd ::= SHOW MODULES", + /* 159 */ "cmd ::= SHOW QNODES", + /* 160 */ "cmd ::= SHOW FUNCTIONS", + /* 161 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 162 */ "cmd ::= SHOW STREAMS", + /* 163 */ "db_name_cond_opt ::=", + /* 164 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 165 */ "like_pattern_opt ::=", + /* 166 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 167 */ "table_name_cond ::= table_name", + /* 168 */ "from_db_opt ::=", + /* 169 */ "from_db_opt ::= FROM db_name", + /* 170 */ "func_name_list ::= func_name", + /* 171 */ "func_name_list ::= func_name_list NK_COMMA col_name", + /* 172 */ "func_name ::= function_name", + /* 173 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 174 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 175 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 176 */ "index_options ::=", + /* 177 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 178 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 179 */ "func_list ::= func", + /* 180 */ "func_list ::= func_list NK_COMMA func", + /* 181 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 182 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 183 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 184 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 185 */ "cmd ::= query_expression", + /* 186 */ "literal ::= NK_INTEGER", + /* 187 */ "literal ::= NK_FLOAT", + /* 188 */ "literal ::= NK_STRING", + /* 189 */ "literal ::= NK_BOOL", + /* 190 */ "literal ::= TIMESTAMP NK_STRING", + /* 191 */ "literal ::= duration_literal", + /* 192 */ "duration_literal ::= NK_VARIABLE", + /* 193 */ "signed ::= NK_INTEGER", + /* 194 */ "signed ::= NK_PLUS NK_INTEGER", + /* 195 */ "signed ::= NK_MINUS NK_INTEGER", + /* 196 */ "signed ::= NK_FLOAT", + /* 197 */ "signed ::= NK_PLUS NK_FLOAT", + /* 198 */ "signed ::= NK_MINUS NK_FLOAT", + /* 199 */ "signed_literal ::= signed", + /* 200 */ "signed_literal ::= NK_STRING", + /* 201 */ "signed_literal ::= NK_BOOL", + /* 202 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 203 */ "signed_literal ::= duration_literal", + /* 204 */ "literal_list ::= signed_literal", + /* 205 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 206 */ "db_name ::= NK_ID", + /* 207 */ "table_name ::= NK_ID", + /* 208 */ "column_name ::= NK_ID", + /* 209 */ "function_name ::= NK_ID", + /* 210 */ "table_alias ::= NK_ID", + /* 211 */ "column_alias ::= NK_ID", + /* 212 */ "user_name ::= NK_ID", + /* 213 */ "index_name ::= NK_ID", + /* 214 */ "topic_name ::= NK_ID", + /* 215 */ "expression ::= literal", + /* 216 */ "expression ::= column_reference", + /* 217 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 218 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 219 */ "expression ::= subquery", + /* 220 */ "expression ::= NK_LP expression NK_RP", + /* 221 */ "expression ::= NK_PLUS expression", + /* 222 */ "expression ::= NK_MINUS expression", + /* 223 */ "expression ::= expression NK_PLUS expression", + /* 224 */ "expression ::= expression NK_MINUS expression", + /* 225 */ "expression ::= expression NK_STAR expression", + /* 226 */ "expression ::= expression NK_SLASH expression", + /* 227 */ "expression ::= expression NK_REM expression", + /* 228 */ "expression_list ::= expression", + /* 229 */ "expression_list ::= expression_list NK_COMMA expression", + /* 230 */ "column_reference ::= column_name", + /* 231 */ "column_reference ::= table_name NK_DOT column_name", + /* 232 */ "predicate ::= expression compare_op expression", + /* 233 */ "predicate ::= expression BETWEEN expression AND expression", + /* 234 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 235 */ "predicate ::= expression IS NULL", + /* 236 */ "predicate ::= expression IS NOT NULL", + /* 237 */ "predicate ::= expression in_op in_predicate_value", + /* 238 */ "compare_op ::= NK_LT", + /* 239 */ "compare_op ::= NK_GT", + /* 240 */ "compare_op ::= NK_LE", + /* 241 */ "compare_op ::= NK_GE", + /* 242 */ "compare_op ::= NK_NE", + /* 243 */ "compare_op ::= NK_EQ", + /* 244 */ "compare_op ::= LIKE", + /* 245 */ "compare_op ::= NOT LIKE", + /* 246 */ "compare_op ::= MATCH", + /* 247 */ "compare_op ::= NMATCH", + /* 248 */ "in_op ::= IN", + /* 249 */ "in_op ::= NOT IN", + /* 250 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 251 */ "boolean_value_expression ::= boolean_primary", + /* 252 */ "boolean_value_expression ::= NOT boolean_primary", + /* 253 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 254 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 255 */ "boolean_primary ::= predicate", + /* 256 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 257 */ "common_expression ::= expression", + /* 258 */ "common_expression ::= boolean_value_expression", + /* 259 */ "from_clause ::= FROM table_reference_list", + /* 260 */ "table_reference_list ::= table_reference", + /* 261 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 262 */ "table_reference ::= table_primary", + /* 263 */ "table_reference ::= joined_table", + /* 264 */ "table_primary ::= table_name alias_opt", + /* 265 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 266 */ "table_primary ::= subquery alias_opt", + /* 267 */ "table_primary ::= parenthesized_joined_table", + /* 268 */ "alias_opt ::=", + /* 269 */ "alias_opt ::= table_alias", + /* 270 */ "alias_opt ::= AS table_alias", + /* 271 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 272 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 273 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 274 */ "join_type ::=", + /* 275 */ "join_type ::= INNER", + /* 276 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 277 */ "set_quantifier_opt ::=", + /* 278 */ "set_quantifier_opt ::= DISTINCT", + /* 279 */ "set_quantifier_opt ::= ALL", + /* 280 */ "select_list ::= NK_STAR", + /* 281 */ "select_list ::= select_sublist", + /* 282 */ "select_sublist ::= select_item", + /* 283 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 284 */ "select_item ::= common_expression", + /* 285 */ "select_item ::= common_expression column_alias", + /* 286 */ "select_item ::= common_expression AS column_alias", + /* 287 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 288 */ "where_clause_opt ::=", + /* 289 */ "where_clause_opt ::= WHERE search_condition", + /* 290 */ "partition_by_clause_opt ::=", + /* 291 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 292 */ "twindow_clause_opt ::=", + /* 293 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 294 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 295 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 296 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 297 */ "sliding_opt ::=", + /* 298 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 299 */ "fill_opt ::=", + /* 300 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 301 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 302 */ "fill_mode ::= NONE", + /* 303 */ "fill_mode ::= PREV", + /* 304 */ "fill_mode ::= NULL", + /* 305 */ "fill_mode ::= LINEAR", + /* 306 */ "fill_mode ::= NEXT", + /* 307 */ "group_by_clause_opt ::=", + /* 308 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 309 */ "group_by_list ::= expression", + /* 310 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 311 */ "having_clause_opt ::=", + /* 312 */ "having_clause_opt ::= HAVING search_condition", + /* 313 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 314 */ "query_expression_body ::= query_primary", + /* 315 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 316 */ "query_primary ::= query_specification", + /* 317 */ "order_by_clause_opt ::=", + /* 318 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 319 */ "slimit_clause_opt ::=", + /* 320 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 321 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 322 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 323 */ "limit_clause_opt ::=", + /* 324 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 325 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 326 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 327 */ "subquery ::= NK_LP query_expression NK_RP", + /* 328 */ "search_condition ::= common_expression", + /* 329 */ "sort_specification_list ::= sort_specification", + /* 330 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 331 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 332 */ "ordering_specification_opt ::=", + /* 333 */ "ordering_specification_opt ::= ASC", + /* 334 */ "ordering_specification_opt ::= DESC", + /* 335 */ "null_ordering_opt ::=", + /* 336 */ "null_ordering_opt ::= NULLS FIRST", + /* 337 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1325,10 +1322,10 @@ static int yyGrowStack(yyParser *p){ newSize = p->yystksz*2 + 100; idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; if( p->yystack==&p->yystk0 ){ - pNew = taosMemoryMalloc(newSize*sizeof(pNew[0])); + pNew = malloc(newSize*sizeof(pNew[0])); if( pNew ) pNew[0] = p->yystk0; }else{ - pNew = taosMemoryRealloc(p->yystack, newSize*sizeof(pNew[0])); + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); } if( pNew ){ p->yystack = pNew; @@ -1434,145 +1431,145 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 163: /* cmd */ - case 166: /* literal */ - case 173: /* db_options */ - case 175: /* alter_db_options */ - case 177: /* full_table_name */ - case 180: /* table_options */ - case 184: /* alter_table_clause */ - case 185: /* alter_table_options */ - case 188: /* create_subtable_clause */ - case 191: /* drop_table_clause */ - case 194: /* column_def */ - case 197: /* col_name */ - case 198: /* db_name_cond_opt */ - case 199: /* like_pattern_opt */ - case 200: /* table_name_cond */ - case 201: /* from_db_opt */ - case 202: /* func_name */ - case 205: /* index_options */ - case 207: /* duration_literal */ - case 208: /* sliding_opt */ - case 209: /* func */ - case 212: /* query_expression */ - case 213: /* signed */ - case 214: /* signed_literal */ - case 217: /* expression */ - case 218: /* column_reference */ - case 219: /* subquery */ - case 220: /* predicate */ - case 223: /* in_predicate_value */ - case 224: /* boolean_value_expression */ - case 225: /* boolean_primary */ - case 226: /* common_expression */ - case 227: /* from_clause */ - case 228: /* table_reference_list */ - case 229: /* table_reference */ - case 230: /* table_primary */ - case 231: /* joined_table */ - case 233: /* parenthesized_joined_table */ - case 235: /* search_condition */ - case 236: /* query_specification */ - case 239: /* where_clause_opt */ - case 241: /* twindow_clause_opt */ - case 243: /* having_clause_opt */ - case 245: /* select_item */ - case 246: /* fill_opt */ - case 249: /* query_expression_body */ - case 251: /* slimit_clause_opt */ - case 252: /* limit_clause_opt */ - case 253: /* query_primary */ - case 255: /* sort_specification */ + case 164: /* cmd */ + case 167: /* literal */ + case 174: /* db_options */ + case 176: /* alter_db_options */ + case 178: /* full_table_name */ + case 181: /* table_options */ + case 185: /* alter_table_clause */ + case 186: /* alter_table_options */ + case 189: /* create_subtable_clause */ + case 192: /* drop_table_clause */ + case 195: /* column_def */ + case 198: /* col_name */ + case 199: /* db_name_cond_opt */ + case 200: /* like_pattern_opt */ + case 201: /* table_name_cond */ + case 202: /* from_db_opt */ + case 203: /* func_name */ + case 206: /* index_options */ + case 208: /* duration_literal */ + case 209: /* sliding_opt */ + case 210: /* func */ + case 213: /* query_expression */ + case 214: /* signed */ + case 215: /* signed_literal */ + case 218: /* expression */ + case 219: /* column_reference */ + case 220: /* subquery */ + case 221: /* predicate */ + case 224: /* in_predicate_value */ + case 225: /* boolean_value_expression */ + case 226: /* boolean_primary */ + case 227: /* common_expression */ + case 228: /* from_clause */ + case 229: /* table_reference_list */ + case 230: /* table_reference */ + case 231: /* table_primary */ + case 232: /* joined_table */ + case 234: /* parenthesized_joined_table */ + case 236: /* search_condition */ + case 237: /* query_specification */ + case 240: /* where_clause_opt */ + case 242: /* twindow_clause_opt */ + case 244: /* having_clause_opt */ + case 246: /* select_item */ + case 247: /* fill_opt */ + case 250: /* query_expression_body */ + case 252: /* slimit_clause_opt */ + case 253: /* limit_clause_opt */ + case 254: /* query_primary */ + case 256: /* sort_specification */ { - nodesDestroyNode((yypminor->yy140)); + nodesDestroyNode((yypminor->yy378)); } break; - case 164: /* account_options */ - case 165: /* alter_account_options */ - case 167: /* alter_account_option */ + case 165: /* account_options */ + case 166: /* alter_account_options */ + case 168: /* alter_account_option */ { } break; - case 168: /* user_name */ - case 169: /* dnode_endpoint */ - case 170: /* dnode_host_name */ - case 172: /* db_name */ - case 186: /* column_name */ - case 193: /* table_name */ - case 203: /* function_name */ - case 204: /* index_name */ - case 211: /* topic_name */ - case 215: /* table_alias */ - case 216: /* column_alias */ - case 232: /* alias_opt */ + case 169: /* user_name */ + case 170: /* dnode_endpoint */ + case 171: /* dnode_host_name */ + case 173: /* db_name */ + case 187: /* column_name */ + case 194: /* table_name */ + case 204: /* function_name */ + case 205: /* index_name */ + case 212: /* topic_name */ + case 216: /* table_alias */ + case 217: /* column_alias */ + case 233: /* alias_opt */ { } break; - case 171: /* not_exists_opt */ - case 174: /* exists_opt */ - case 237: /* set_quantifier_opt */ + case 172: /* not_exists_opt */ + case 175: /* exists_opt */ + case 238: /* set_quantifier_opt */ { } break; - case 176: /* alter_db_option */ - case 196: /* alter_table_option */ + case 177: /* alter_db_option */ + case 197: /* alter_table_option */ { } break; - case 178: /* column_def_list */ - case 179: /* tags_def_opt */ - case 181: /* multi_create_clause */ - case 182: /* tags_def */ - case 183: /* multi_drop_clause */ - case 189: /* specific_tags_opt */ - case 190: /* literal_list */ - case 192: /* col_name_list */ - case 195: /* func_name_list */ - case 206: /* func_list */ - case 210: /* expression_list */ - case 238: /* select_list */ - case 240: /* partition_by_clause_opt */ - case 242: /* group_by_clause_opt */ - case 244: /* select_sublist */ - case 248: /* group_by_list */ - case 250: /* order_by_clause_opt */ - case 254: /* sort_specification_list */ + case 179: /* column_def_list */ + case 180: /* tags_def_opt */ + case 182: /* multi_create_clause */ + case 183: /* tags_def */ + case 184: /* multi_drop_clause */ + case 190: /* specific_tags_opt */ + case 191: /* literal_list */ + case 193: /* col_name_list */ + case 196: /* func_name_list */ + case 207: /* func_list */ + case 211: /* expression_list */ + case 239: /* select_list */ + case 241: /* partition_by_clause_opt */ + case 243: /* group_by_clause_opt */ + case 245: /* select_sublist */ + case 249: /* group_by_list */ + case 251: /* order_by_clause_opt */ + case 255: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy136)); + nodesDestroyList((yypminor->yy404)); } break; - case 187: /* type_name */ + case 188: /* type_name */ { } break; - case 221: /* compare_op */ - case 222: /* in_op */ + case 222: /* compare_op */ + case 223: /* in_op */ { } break; - case 234: /* join_type */ + case 235: /* join_type */ { } break; - case 247: /* fill_mode */ + case 248: /* fill_mode */ { } break; - case 256: /* ordering_specification_opt */ + case 257: /* ordering_specification_opt */ { } break; - case 257: /* null_ordering_opt */ + case 258: /* null_ordering_opt */ { } @@ -1610,7 +1607,7 @@ void ParseFinalize(void *p){ yyParser *pParser = (yyParser*)p; while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 - if( pParser->yystack!=&pParser->yystk0 ) taosMemoryFree(pParser->yystack); + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); #endif } @@ -1871,343 +1868,344 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 163, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 163, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 164, 0 }, /* (2) account_options ::= */ - { 164, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 164, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 164, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 164, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 164, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 164, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 164, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 164, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 164, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 165, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 165, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 167, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 167, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 167, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 167, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 167, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 167, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 167, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 167, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 167, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 167, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 163, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 163, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 163, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 163, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 163, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 163, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 163, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 163, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 163, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 163, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 163, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 163, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 169, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 170, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 170, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 163, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 163, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 163, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 163, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 163, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 163, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 163, -2 }, /* (45) cmd ::= USE db_name */ - { 163, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 171, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 171, 0 }, /* (48) not_exists_opt ::= */ - { 174, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 174, 0 }, /* (50) exists_opt ::= */ - { 173, 0 }, /* (51) db_options ::= */ - { 173, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 173, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 173, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 173, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 173, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 173, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 173, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 173, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 173, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 173, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 173, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 173, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 173, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 173, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 173, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 173, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 173, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 173, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 173, -3 }, /* (70) db_options ::= db_options FILE_FACTOR NK_FLOAT */ - { 175, -1 }, /* (71) alter_db_options ::= alter_db_option */ - { 175, -2 }, /* (72) alter_db_options ::= alter_db_options alter_db_option */ - { 176, -2 }, /* (73) alter_db_option ::= BLOCKS NK_INTEGER */ - { 176, -2 }, /* (74) alter_db_option ::= FSYNC NK_INTEGER */ - { 176, -2 }, /* (75) alter_db_option ::= KEEP NK_INTEGER */ - { 176, -2 }, /* (76) alter_db_option ::= WAL NK_INTEGER */ - { 176, -2 }, /* (77) alter_db_option ::= QUORUM NK_INTEGER */ - { 176, -2 }, /* (78) alter_db_option ::= CACHELAST NK_INTEGER */ - { 163, -9 }, /* (79) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 163, -3 }, /* (80) cmd ::= CREATE TABLE multi_create_clause */ - { 163, -9 }, /* (81) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 163, -3 }, /* (82) cmd ::= DROP TABLE multi_drop_clause */ - { 163, -4 }, /* (83) cmd ::= DROP STABLE exists_opt full_table_name */ - { 163, -3 }, /* (84) cmd ::= ALTER TABLE alter_table_clause */ - { 163, -3 }, /* (85) cmd ::= ALTER STABLE alter_table_clause */ - { 184, -2 }, /* (86) alter_table_clause ::= full_table_name alter_table_options */ - { 184, -5 }, /* (87) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 184, -4 }, /* (88) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 184, -5 }, /* (89) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 184, -5 }, /* (90) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 184, -5 }, /* (91) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 184, -4 }, /* (92) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 184, -5 }, /* (93) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 184, -5 }, /* (94) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 184, -6 }, /* (95) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 181, -1 }, /* (96) multi_create_clause ::= create_subtable_clause */ - { 181, -2 }, /* (97) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 188, -9 }, /* (98) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 183, -1 }, /* (99) multi_drop_clause ::= drop_table_clause */ - { 183, -2 }, /* (100) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 191, -2 }, /* (101) drop_table_clause ::= exists_opt full_table_name */ - { 189, 0 }, /* (102) specific_tags_opt ::= */ - { 189, -3 }, /* (103) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 177, -1 }, /* (104) full_table_name ::= table_name */ - { 177, -3 }, /* (105) full_table_name ::= db_name NK_DOT table_name */ - { 178, -1 }, /* (106) column_def_list ::= column_def */ - { 178, -3 }, /* (107) column_def_list ::= column_def_list NK_COMMA column_def */ - { 194, -2 }, /* (108) column_def ::= column_name type_name */ - { 194, -4 }, /* (109) column_def ::= column_name type_name COMMENT NK_STRING */ - { 187, -1 }, /* (110) type_name ::= BOOL */ - { 187, -1 }, /* (111) type_name ::= TINYINT */ - { 187, -1 }, /* (112) type_name ::= SMALLINT */ - { 187, -1 }, /* (113) type_name ::= INT */ - { 187, -1 }, /* (114) type_name ::= INTEGER */ - { 187, -1 }, /* (115) type_name ::= BIGINT */ - { 187, -1 }, /* (116) type_name ::= FLOAT */ - { 187, -1 }, /* (117) type_name ::= DOUBLE */ - { 187, -4 }, /* (118) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (119) type_name ::= TIMESTAMP */ - { 187, -4 }, /* (120) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 187, -2 }, /* (121) type_name ::= TINYINT UNSIGNED */ - { 187, -2 }, /* (122) type_name ::= SMALLINT UNSIGNED */ - { 187, -2 }, /* (123) type_name ::= INT UNSIGNED */ - { 187, -2 }, /* (124) type_name ::= BIGINT UNSIGNED */ - { 187, -1 }, /* (125) type_name ::= JSON */ - { 187, -4 }, /* (126) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (127) type_name ::= MEDIUMBLOB */ - { 187, -1 }, /* (128) type_name ::= BLOB */ - { 187, -4 }, /* (129) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 187, -1 }, /* (130) type_name ::= DECIMAL */ - { 187, -4 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 187, -6 }, /* (132) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 179, 0 }, /* (133) tags_def_opt ::= */ - { 179, -1 }, /* (134) tags_def_opt ::= tags_def */ - { 182, -4 }, /* (135) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 180, 0 }, /* (136) table_options ::= */ - { 180, -3 }, /* (137) table_options ::= table_options COMMENT NK_STRING */ - { 180, -3 }, /* (138) table_options ::= table_options KEEP NK_INTEGER */ - { 180, -3 }, /* (139) table_options ::= table_options TTL NK_INTEGER */ - { 180, -5 }, /* (140) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 180, -5 }, /* (141) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 185, -1 }, /* (142) alter_table_options ::= alter_table_option */ - { 185, -2 }, /* (143) alter_table_options ::= alter_table_options alter_table_option */ - { 196, -2 }, /* (144) alter_table_option ::= COMMENT NK_STRING */ - { 196, -2 }, /* (145) alter_table_option ::= KEEP NK_INTEGER */ - { 196, -2 }, /* (146) alter_table_option ::= TTL NK_INTEGER */ - { 192, -1 }, /* (147) col_name_list ::= col_name */ - { 192, -3 }, /* (148) col_name_list ::= col_name_list NK_COMMA col_name */ - { 197, -1 }, /* (149) col_name ::= column_name */ - { 163, -2 }, /* (150) cmd ::= SHOW DNODES */ - { 163, -2 }, /* (151) cmd ::= SHOW USERS */ - { 163, -2 }, /* (152) cmd ::= SHOW DATABASES */ - { 163, -4 }, /* (153) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 163, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 163, -3 }, /* (155) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 163, -2 }, /* (156) cmd ::= SHOW MNODES */ - { 163, -2 }, /* (157) cmd ::= SHOW MODULES */ - { 163, -2 }, /* (158) cmd ::= SHOW QNODES */ - { 163, -2 }, /* (159) cmd ::= SHOW FUNCTIONS */ - { 163, -5 }, /* (160) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 163, -2 }, /* (161) cmd ::= SHOW STREAMS */ - { 198, 0 }, /* (162) db_name_cond_opt ::= */ - { 198, -2 }, /* (163) db_name_cond_opt ::= db_name NK_DOT */ - { 199, 0 }, /* (164) like_pattern_opt ::= */ - { 199, -2 }, /* (165) like_pattern_opt ::= LIKE NK_STRING */ - { 200, -1 }, /* (166) table_name_cond ::= table_name */ - { 201, 0 }, /* (167) from_db_opt ::= */ - { 201, -2 }, /* (168) from_db_opt ::= FROM db_name */ - { 195, -1 }, /* (169) func_name_list ::= func_name */ - { 195, -3 }, /* (170) func_name_list ::= func_name_list NK_COMMA col_name */ - { 202, -1 }, /* (171) func_name ::= function_name */ - { 163, -8 }, /* (172) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 163, -10 }, /* (173) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 163, -6 }, /* (174) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 205, 0 }, /* (175) index_options ::= */ - { 205, -9 }, /* (176) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 205, -11 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 206, -1 }, /* (178) func_list ::= func */ - { 206, -3 }, /* (179) func_list ::= func_list NK_COMMA func */ - { 209, -4 }, /* (180) func ::= function_name NK_LP expression_list NK_RP */ - { 163, -6 }, /* (181) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 163, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 163, -4 }, /* (183) cmd ::= DROP TOPIC exists_opt topic_name */ - { 163, -1 }, /* (184) cmd ::= query_expression */ - { 166, -1 }, /* (185) literal ::= NK_INTEGER */ - { 166, -1 }, /* (186) literal ::= NK_FLOAT */ - { 166, -1 }, /* (187) literal ::= NK_STRING */ - { 166, -1 }, /* (188) literal ::= NK_BOOL */ - { 166, -2 }, /* (189) literal ::= TIMESTAMP NK_STRING */ - { 166, -1 }, /* (190) literal ::= duration_literal */ - { 207, -1 }, /* (191) duration_literal ::= NK_VARIABLE */ - { 213, -1 }, /* (192) signed ::= NK_INTEGER */ - { 213, -2 }, /* (193) signed ::= NK_PLUS NK_INTEGER */ - { 213, -2 }, /* (194) signed ::= NK_MINUS NK_INTEGER */ - { 213, -1 }, /* (195) signed ::= NK_FLOAT */ - { 213, -2 }, /* (196) signed ::= NK_PLUS NK_FLOAT */ - { 213, -2 }, /* (197) signed ::= NK_MINUS NK_FLOAT */ - { 214, -1 }, /* (198) signed_literal ::= signed */ - { 214, -1 }, /* (199) signed_literal ::= NK_STRING */ - { 214, -1 }, /* (200) signed_literal ::= NK_BOOL */ - { 214, -2 }, /* (201) signed_literal ::= TIMESTAMP NK_STRING */ - { 214, -1 }, /* (202) signed_literal ::= duration_literal */ - { 190, -1 }, /* (203) literal_list ::= signed_literal */ - { 190, -3 }, /* (204) literal_list ::= literal_list NK_COMMA signed_literal */ - { 172, -1 }, /* (205) db_name ::= NK_ID */ - { 193, -1 }, /* (206) table_name ::= NK_ID */ - { 186, -1 }, /* (207) column_name ::= NK_ID */ - { 203, -1 }, /* (208) function_name ::= NK_ID */ - { 215, -1 }, /* (209) table_alias ::= NK_ID */ - { 216, -1 }, /* (210) column_alias ::= NK_ID */ - { 168, -1 }, /* (211) user_name ::= NK_ID */ - { 204, -1 }, /* (212) index_name ::= NK_ID */ - { 211, -1 }, /* (213) topic_name ::= NK_ID */ - { 217, -1 }, /* (214) expression ::= literal */ - { 217, -1 }, /* (215) expression ::= column_reference */ - { 217, -4 }, /* (216) expression ::= function_name NK_LP expression_list NK_RP */ - { 217, -4 }, /* (217) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 217, -1 }, /* (218) expression ::= subquery */ - { 217, -3 }, /* (219) expression ::= NK_LP expression NK_RP */ - { 217, -2 }, /* (220) expression ::= NK_PLUS expression */ - { 217, -2 }, /* (221) expression ::= NK_MINUS expression */ - { 217, -3 }, /* (222) expression ::= expression NK_PLUS expression */ - { 217, -3 }, /* (223) expression ::= expression NK_MINUS expression */ - { 217, -3 }, /* (224) expression ::= expression NK_STAR expression */ - { 217, -3 }, /* (225) expression ::= expression NK_SLASH expression */ - { 217, -3 }, /* (226) expression ::= expression NK_REM expression */ - { 210, -1 }, /* (227) expression_list ::= expression */ - { 210, -3 }, /* (228) expression_list ::= expression_list NK_COMMA expression */ - { 218, -1 }, /* (229) column_reference ::= column_name */ - { 218, -3 }, /* (230) column_reference ::= table_name NK_DOT column_name */ - { 220, -3 }, /* (231) predicate ::= expression compare_op expression */ - { 220, -5 }, /* (232) predicate ::= expression BETWEEN expression AND expression */ - { 220, -6 }, /* (233) predicate ::= expression NOT BETWEEN expression AND expression */ - { 220, -3 }, /* (234) predicate ::= expression IS NULL */ - { 220, -4 }, /* (235) predicate ::= expression IS NOT NULL */ - { 220, -3 }, /* (236) predicate ::= expression in_op in_predicate_value */ - { 221, -1 }, /* (237) compare_op ::= NK_LT */ - { 221, -1 }, /* (238) compare_op ::= NK_GT */ - { 221, -1 }, /* (239) compare_op ::= NK_LE */ - { 221, -1 }, /* (240) compare_op ::= NK_GE */ - { 221, -1 }, /* (241) compare_op ::= NK_NE */ - { 221, -1 }, /* (242) compare_op ::= NK_EQ */ - { 221, -1 }, /* (243) compare_op ::= LIKE */ - { 221, -2 }, /* (244) compare_op ::= NOT LIKE */ - { 221, -1 }, /* (245) compare_op ::= MATCH */ - { 221, -1 }, /* (246) compare_op ::= NMATCH */ - { 222, -1 }, /* (247) in_op ::= IN */ - { 222, -2 }, /* (248) in_op ::= NOT IN */ - { 223, -3 }, /* (249) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 224, -1 }, /* (250) boolean_value_expression ::= boolean_primary */ - { 224, -2 }, /* (251) boolean_value_expression ::= NOT boolean_primary */ - { 224, -3 }, /* (252) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 224, -3 }, /* (253) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 225, -1 }, /* (254) boolean_primary ::= predicate */ - { 225, -3 }, /* (255) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 226, -1 }, /* (256) common_expression ::= expression */ - { 226, -1 }, /* (257) common_expression ::= boolean_value_expression */ - { 227, -2 }, /* (258) from_clause ::= FROM table_reference_list */ - { 228, -1 }, /* (259) table_reference_list ::= table_reference */ - { 228, -3 }, /* (260) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 229, -1 }, /* (261) table_reference ::= table_primary */ - { 229, -1 }, /* (262) table_reference ::= joined_table */ - { 230, -2 }, /* (263) table_primary ::= table_name alias_opt */ - { 230, -4 }, /* (264) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 230, -2 }, /* (265) table_primary ::= subquery alias_opt */ - { 230, -1 }, /* (266) table_primary ::= parenthesized_joined_table */ - { 232, 0 }, /* (267) alias_opt ::= */ - { 232, -1 }, /* (268) alias_opt ::= table_alias */ - { 232, -2 }, /* (269) alias_opt ::= AS table_alias */ - { 233, -3 }, /* (270) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 233, -3 }, /* (271) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 231, -6 }, /* (272) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 234, 0 }, /* (273) join_type ::= */ - { 234, -1 }, /* (274) join_type ::= INNER */ - { 236, -9 }, /* (275) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 237, 0 }, /* (276) set_quantifier_opt ::= */ - { 237, -1 }, /* (277) set_quantifier_opt ::= DISTINCT */ - { 237, -1 }, /* (278) set_quantifier_opt ::= ALL */ - { 238, -1 }, /* (279) select_list ::= NK_STAR */ - { 238, -1 }, /* (280) select_list ::= select_sublist */ - { 244, -1 }, /* (281) select_sublist ::= select_item */ - { 244, -3 }, /* (282) select_sublist ::= select_sublist NK_COMMA select_item */ - { 245, -1 }, /* (283) select_item ::= common_expression */ - { 245, -2 }, /* (284) select_item ::= common_expression column_alias */ - { 245, -3 }, /* (285) select_item ::= common_expression AS column_alias */ - { 245, -3 }, /* (286) select_item ::= table_name NK_DOT NK_STAR */ - { 239, 0 }, /* (287) where_clause_opt ::= */ - { 239, -2 }, /* (288) where_clause_opt ::= WHERE search_condition */ - { 240, 0 }, /* (289) partition_by_clause_opt ::= */ - { 240, -3 }, /* (290) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 241, 0 }, /* (291) twindow_clause_opt ::= */ - { 241, -6 }, /* (292) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 241, -4 }, /* (293) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 241, -6 }, /* (294) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 241, -8 }, /* (295) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 208, 0 }, /* (296) sliding_opt ::= */ - { 208, -4 }, /* (297) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 246, 0 }, /* (298) fill_opt ::= */ - { 246, -4 }, /* (299) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 246, -6 }, /* (300) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 247, -1 }, /* (301) fill_mode ::= NONE */ - { 247, -1 }, /* (302) fill_mode ::= PREV */ - { 247, -1 }, /* (303) fill_mode ::= NULL */ - { 247, -1 }, /* (304) fill_mode ::= LINEAR */ - { 247, -1 }, /* (305) fill_mode ::= NEXT */ - { 242, 0 }, /* (306) group_by_clause_opt ::= */ - { 242, -3 }, /* (307) group_by_clause_opt ::= GROUP BY group_by_list */ - { 248, -1 }, /* (308) group_by_list ::= expression */ - { 248, -3 }, /* (309) group_by_list ::= group_by_list NK_COMMA expression */ - { 243, 0 }, /* (310) having_clause_opt ::= */ - { 243, -2 }, /* (311) having_clause_opt ::= HAVING search_condition */ - { 212, -4 }, /* (312) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 249, -1 }, /* (313) query_expression_body ::= query_primary */ - { 249, -4 }, /* (314) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 253, -1 }, /* (315) query_primary ::= query_specification */ - { 250, 0 }, /* (316) order_by_clause_opt ::= */ - { 250, -3 }, /* (317) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 251, 0 }, /* (318) slimit_clause_opt ::= */ - { 251, -2 }, /* (319) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 251, -4 }, /* (320) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 251, -4 }, /* (321) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 252, 0 }, /* (322) limit_clause_opt ::= */ - { 252, -2 }, /* (323) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 252, -4 }, /* (324) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 252, -4 }, /* (325) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 219, -3 }, /* (326) subquery ::= NK_LP query_expression NK_RP */ - { 235, -1 }, /* (327) search_condition ::= common_expression */ - { 254, -1 }, /* (328) sort_specification_list ::= sort_specification */ - { 254, -3 }, /* (329) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 255, -3 }, /* (330) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 256, 0 }, /* (331) ordering_specification_opt ::= */ - { 256, -1 }, /* (332) ordering_specification_opt ::= ASC */ - { 256, -1 }, /* (333) ordering_specification_opt ::= DESC */ - { 257, 0 }, /* (334) null_ordering_opt ::= */ - { 257, -2 }, /* (335) null_ordering_opt ::= NULLS FIRST */ - { 257, -2 }, /* (336) null_ordering_opt ::= NULLS LAST */ + { 164, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 164, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 165, 0 }, /* (2) account_options ::= */ + { 165, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 165, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 165, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 165, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 165, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 165, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 165, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 165, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 165, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 166, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 166, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 168, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 168, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 168, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 168, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 168, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 168, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 168, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 168, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 168, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 168, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 164, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 164, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 164, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 164, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 164, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 164, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 164, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 164, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 164, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 164, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 164, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 164, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 170, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 171, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 171, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 164, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 164, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 164, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 164, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 164, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 164, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ + { 164, -2 }, /* (45) cmd ::= USE db_name */ + { 164, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 172, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ + { 172, 0 }, /* (48) not_exists_opt ::= */ + { 175, -2 }, /* (49) exists_opt ::= IF EXISTS */ + { 175, 0 }, /* (50) exists_opt ::= */ + { 174, 0 }, /* (51) db_options ::= */ + { 174, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ + { 174, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ + { 174, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ + { 174, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ + { 174, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ + { 174, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ + { 174, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ + { 174, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ + { 174, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ + { 174, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ + { 174, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ + { 174, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ + { 174, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ + { 174, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ + { 174, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ + { 174, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 174, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 174, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ + { 176, -1 }, /* (70) alter_db_options ::= alter_db_option */ + { 176, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ + { 177, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ + { 177, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ + { 177, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ + { 177, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ + { 177, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ + { 177, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ + { 164, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 164, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ + { 164, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 164, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ + { 164, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ + { 164, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ + { 164, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ + { 185, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ + { 185, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 185, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 185, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 185, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 185, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 185, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 185, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 185, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 185, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 182, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ + { 182, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 189, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 184, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ + { 184, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 192, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ + { 190, 0 }, /* (101) specific_tags_opt ::= */ + { 190, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 178, -1 }, /* (103) full_table_name ::= table_name */ + { 178, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ + { 179, -1 }, /* (105) column_def_list ::= column_def */ + { 179, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ + { 195, -2 }, /* (107) column_def ::= column_name type_name */ + { 195, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ + { 188, -1 }, /* (109) type_name ::= BOOL */ + { 188, -1 }, /* (110) type_name ::= TINYINT */ + { 188, -1 }, /* (111) type_name ::= SMALLINT */ + { 188, -1 }, /* (112) type_name ::= INT */ + { 188, -1 }, /* (113) type_name ::= INTEGER */ + { 188, -1 }, /* (114) type_name ::= BIGINT */ + { 188, -1 }, /* (115) type_name ::= FLOAT */ + { 188, -1 }, /* (116) type_name ::= DOUBLE */ + { 188, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 188, -1 }, /* (118) type_name ::= TIMESTAMP */ + { 188, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 188, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ + { 188, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ + { 188, -2 }, /* (122) type_name ::= INT UNSIGNED */ + { 188, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ + { 188, -1 }, /* (124) type_name ::= JSON */ + { 188, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 188, -1 }, /* (126) type_name ::= MEDIUMBLOB */ + { 188, -1 }, /* (127) type_name ::= BLOB */ + { 188, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 188, -1 }, /* (129) type_name ::= DECIMAL */ + { 188, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 188, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 180, 0 }, /* (132) tags_def_opt ::= */ + { 180, -1 }, /* (133) tags_def_opt ::= tags_def */ + { 183, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 181, 0 }, /* (135) table_options ::= */ + { 181, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ + { 181, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ + { 181, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ + { 181, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 181, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 181, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 181, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ + { 186, -1 }, /* (143) alter_table_options ::= alter_table_option */ + { 186, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ + { 197, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ + { 197, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ + { 197, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ + { 193, -1 }, /* (148) col_name_list ::= col_name */ + { 193, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ + { 198, -1 }, /* (150) col_name ::= column_name */ + { 164, -2 }, /* (151) cmd ::= SHOW DNODES */ + { 164, -2 }, /* (152) cmd ::= SHOW USERS */ + { 164, -2 }, /* (153) cmd ::= SHOW DATABASES */ + { 164, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 164, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 164, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 164, -2 }, /* (157) cmd ::= SHOW MNODES */ + { 164, -2 }, /* (158) cmd ::= SHOW MODULES */ + { 164, -2 }, /* (159) cmd ::= SHOW QNODES */ + { 164, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ + { 164, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 164, -2 }, /* (162) cmd ::= SHOW STREAMS */ + { 199, 0 }, /* (163) db_name_cond_opt ::= */ + { 199, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ + { 200, 0 }, /* (165) like_pattern_opt ::= */ + { 200, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ + { 201, -1 }, /* (167) table_name_cond ::= table_name */ + { 202, 0 }, /* (168) from_db_opt ::= */ + { 202, -2 }, /* (169) from_db_opt ::= FROM db_name */ + { 196, -1 }, /* (170) func_name_list ::= func_name */ + { 196, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ + { 203, -1 }, /* (172) func_name ::= function_name */ + { 164, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 164, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 164, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 206, 0 }, /* (176) index_options ::= */ + { 206, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 206, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 207, -1 }, /* (179) func_list ::= func */ + { 207, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ + { 210, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ + { 164, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 164, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 164, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ + { 164, -1 }, /* (185) cmd ::= query_expression */ + { 167, -1 }, /* (186) literal ::= NK_INTEGER */ + { 167, -1 }, /* (187) literal ::= NK_FLOAT */ + { 167, -1 }, /* (188) literal ::= NK_STRING */ + { 167, -1 }, /* (189) literal ::= NK_BOOL */ + { 167, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ + { 167, -1 }, /* (191) literal ::= duration_literal */ + { 208, -1 }, /* (192) duration_literal ::= NK_VARIABLE */ + { 214, -1 }, /* (193) signed ::= NK_INTEGER */ + { 214, -2 }, /* (194) signed ::= NK_PLUS NK_INTEGER */ + { 214, -2 }, /* (195) signed ::= NK_MINUS NK_INTEGER */ + { 214, -1 }, /* (196) signed ::= NK_FLOAT */ + { 214, -2 }, /* (197) signed ::= NK_PLUS NK_FLOAT */ + { 214, -2 }, /* (198) signed ::= NK_MINUS NK_FLOAT */ + { 215, -1 }, /* (199) signed_literal ::= signed */ + { 215, -1 }, /* (200) signed_literal ::= NK_STRING */ + { 215, -1 }, /* (201) signed_literal ::= NK_BOOL */ + { 215, -2 }, /* (202) signed_literal ::= TIMESTAMP NK_STRING */ + { 215, -1 }, /* (203) signed_literal ::= duration_literal */ + { 191, -1 }, /* (204) literal_list ::= signed_literal */ + { 191, -3 }, /* (205) literal_list ::= literal_list NK_COMMA signed_literal */ + { 173, -1 }, /* (206) db_name ::= NK_ID */ + { 194, -1 }, /* (207) table_name ::= NK_ID */ + { 187, -1 }, /* (208) column_name ::= NK_ID */ + { 204, -1 }, /* (209) function_name ::= NK_ID */ + { 216, -1 }, /* (210) table_alias ::= NK_ID */ + { 217, -1 }, /* (211) column_alias ::= NK_ID */ + { 169, -1 }, /* (212) user_name ::= NK_ID */ + { 205, -1 }, /* (213) index_name ::= NK_ID */ + { 212, -1 }, /* (214) topic_name ::= NK_ID */ + { 218, -1 }, /* (215) expression ::= literal */ + { 218, -1 }, /* (216) expression ::= column_reference */ + { 218, -4 }, /* (217) expression ::= function_name NK_LP expression_list NK_RP */ + { 218, -4 }, /* (218) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 218, -1 }, /* (219) expression ::= subquery */ + { 218, -3 }, /* (220) expression ::= NK_LP expression NK_RP */ + { 218, -2 }, /* (221) expression ::= NK_PLUS expression */ + { 218, -2 }, /* (222) expression ::= NK_MINUS expression */ + { 218, -3 }, /* (223) expression ::= expression NK_PLUS expression */ + { 218, -3 }, /* (224) expression ::= expression NK_MINUS expression */ + { 218, -3 }, /* (225) expression ::= expression NK_STAR expression */ + { 218, -3 }, /* (226) expression ::= expression NK_SLASH expression */ + { 218, -3 }, /* (227) expression ::= expression NK_REM expression */ + { 211, -1 }, /* (228) expression_list ::= expression */ + { 211, -3 }, /* (229) expression_list ::= expression_list NK_COMMA expression */ + { 219, -1 }, /* (230) column_reference ::= column_name */ + { 219, -3 }, /* (231) column_reference ::= table_name NK_DOT column_name */ + { 221, -3 }, /* (232) predicate ::= expression compare_op expression */ + { 221, -5 }, /* (233) predicate ::= expression BETWEEN expression AND expression */ + { 221, -6 }, /* (234) predicate ::= expression NOT BETWEEN expression AND expression */ + { 221, -3 }, /* (235) predicate ::= expression IS NULL */ + { 221, -4 }, /* (236) predicate ::= expression IS NOT NULL */ + { 221, -3 }, /* (237) predicate ::= expression in_op in_predicate_value */ + { 222, -1 }, /* (238) compare_op ::= NK_LT */ + { 222, -1 }, /* (239) compare_op ::= NK_GT */ + { 222, -1 }, /* (240) compare_op ::= NK_LE */ + { 222, -1 }, /* (241) compare_op ::= NK_GE */ + { 222, -1 }, /* (242) compare_op ::= NK_NE */ + { 222, -1 }, /* (243) compare_op ::= NK_EQ */ + { 222, -1 }, /* (244) compare_op ::= LIKE */ + { 222, -2 }, /* (245) compare_op ::= NOT LIKE */ + { 222, -1 }, /* (246) compare_op ::= MATCH */ + { 222, -1 }, /* (247) compare_op ::= NMATCH */ + { 223, -1 }, /* (248) in_op ::= IN */ + { 223, -2 }, /* (249) in_op ::= NOT IN */ + { 224, -3 }, /* (250) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 225, -1 }, /* (251) boolean_value_expression ::= boolean_primary */ + { 225, -2 }, /* (252) boolean_value_expression ::= NOT boolean_primary */ + { 225, -3 }, /* (253) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 225, -3 }, /* (254) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 226, -1 }, /* (255) boolean_primary ::= predicate */ + { 226, -3 }, /* (256) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 227, -1 }, /* (257) common_expression ::= expression */ + { 227, -1 }, /* (258) common_expression ::= boolean_value_expression */ + { 228, -2 }, /* (259) from_clause ::= FROM table_reference_list */ + { 229, -1 }, /* (260) table_reference_list ::= table_reference */ + { 229, -3 }, /* (261) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 230, -1 }, /* (262) table_reference ::= table_primary */ + { 230, -1 }, /* (263) table_reference ::= joined_table */ + { 231, -2 }, /* (264) table_primary ::= table_name alias_opt */ + { 231, -4 }, /* (265) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 231, -2 }, /* (266) table_primary ::= subquery alias_opt */ + { 231, -1 }, /* (267) table_primary ::= parenthesized_joined_table */ + { 233, 0 }, /* (268) alias_opt ::= */ + { 233, -1 }, /* (269) alias_opt ::= table_alias */ + { 233, -2 }, /* (270) alias_opt ::= AS table_alias */ + { 234, -3 }, /* (271) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 234, -3 }, /* (272) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 232, -6 }, /* (273) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 235, 0 }, /* (274) join_type ::= */ + { 235, -1 }, /* (275) join_type ::= INNER */ + { 237, -9 }, /* (276) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 238, 0 }, /* (277) set_quantifier_opt ::= */ + { 238, -1 }, /* (278) set_quantifier_opt ::= DISTINCT */ + { 238, -1 }, /* (279) set_quantifier_opt ::= ALL */ + { 239, -1 }, /* (280) select_list ::= NK_STAR */ + { 239, -1 }, /* (281) select_list ::= select_sublist */ + { 245, -1 }, /* (282) select_sublist ::= select_item */ + { 245, -3 }, /* (283) select_sublist ::= select_sublist NK_COMMA select_item */ + { 246, -1 }, /* (284) select_item ::= common_expression */ + { 246, -2 }, /* (285) select_item ::= common_expression column_alias */ + { 246, -3 }, /* (286) select_item ::= common_expression AS column_alias */ + { 246, -3 }, /* (287) select_item ::= table_name NK_DOT NK_STAR */ + { 240, 0 }, /* (288) where_clause_opt ::= */ + { 240, -2 }, /* (289) where_clause_opt ::= WHERE search_condition */ + { 241, 0 }, /* (290) partition_by_clause_opt ::= */ + { 241, -3 }, /* (291) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 242, 0 }, /* (292) twindow_clause_opt ::= */ + { 242, -6 }, /* (293) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 242, -4 }, /* (294) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 242, -6 }, /* (295) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 242, -8 }, /* (296) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 209, 0 }, /* (297) sliding_opt ::= */ + { 209, -4 }, /* (298) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 247, 0 }, /* (299) fill_opt ::= */ + { 247, -4 }, /* (300) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 247, -6 }, /* (301) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 248, -1 }, /* (302) fill_mode ::= NONE */ + { 248, -1 }, /* (303) fill_mode ::= PREV */ + { 248, -1 }, /* (304) fill_mode ::= NULL */ + { 248, -1 }, /* (305) fill_mode ::= LINEAR */ + { 248, -1 }, /* (306) fill_mode ::= NEXT */ + { 243, 0 }, /* (307) group_by_clause_opt ::= */ + { 243, -3 }, /* (308) group_by_clause_opt ::= GROUP BY group_by_list */ + { 249, -1 }, /* (309) group_by_list ::= expression */ + { 249, -3 }, /* (310) group_by_list ::= group_by_list NK_COMMA expression */ + { 244, 0 }, /* (311) having_clause_opt ::= */ + { 244, -2 }, /* (312) having_clause_opt ::= HAVING search_condition */ + { 213, -4 }, /* (313) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 250, -1 }, /* (314) query_expression_body ::= query_primary */ + { 250, -4 }, /* (315) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 254, -1 }, /* (316) query_primary ::= query_specification */ + { 251, 0 }, /* (317) order_by_clause_opt ::= */ + { 251, -3 }, /* (318) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 252, 0 }, /* (319) slimit_clause_opt ::= */ + { 252, -2 }, /* (320) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 252, -4 }, /* (321) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 252, -4 }, /* (322) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 253, 0 }, /* (323) limit_clause_opt ::= */ + { 253, -2 }, /* (324) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 253, -4 }, /* (325) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 253, -4 }, /* (326) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 220, -3 }, /* (327) subquery ::= NK_LP query_expression NK_RP */ + { 236, -1 }, /* (328) search_condition ::= common_expression */ + { 255, -1 }, /* (329) sort_specification_list ::= sort_specification */ + { 255, -3 }, /* (330) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 256, -3 }, /* (331) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 257, 0 }, /* (332) ordering_specification_opt ::= */ + { 257, -1 }, /* (333) ordering_specification_opt ::= ASC */ + { 257, -1 }, /* (334) ordering_specification_opt ::= DESC */ + { 258, 0 }, /* (335) null_ordering_opt ::= */ + { 258, -2 }, /* (336) null_ordering_opt ::= NULLS FIRST */ + { 258, -2 }, /* (337) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2296,11 +2294,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,164,&yymsp[0].minor); + yy_destructor(yypParser,165,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,165,&yymsp[0].minor); + yy_destructor(yypParser,166,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2314,20 +2312,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,164,&yymsp[-2].minor); +{ yy_destructor(yypParser,165,&yymsp[-2].minor); { } - yy_destructor(yypParser,166,&yymsp[0].minor); + yy_destructor(yypParser,167,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,167,&yymsp[0].minor); +{ yy_destructor(yypParser,168,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,165,&yymsp[-1].minor); +{ yy_destructor(yypParser,166,&yymsp[-1].minor); { } - yy_destructor(yypParser,167,&yymsp[0].minor); + yy_destructor(yypParser,168,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2341,31 +2339,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,166,&yymsp[0].minor); + yy_destructor(yypParser,167,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy149, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy183, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy149, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy183, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy183); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy149, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy183, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy183); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2382,17 +2380,17 @@ static YYACTIONTYPE yy_reduce( case 36: /* dnode_endpoint ::= NK_STRING */ case 37: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==37); case 38: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==38); - case 205: /* db_name ::= NK_ID */ yytestcase(yyruleno==205); - case 206: /* table_name ::= NK_ID */ yytestcase(yyruleno==206); - case 207: /* column_name ::= NK_ID */ yytestcase(yyruleno==207); - case 208: /* function_name ::= NK_ID */ yytestcase(yyruleno==208); - case 209: /* table_alias ::= NK_ID */ yytestcase(yyruleno==209); - case 210: /* column_alias ::= NK_ID */ yytestcase(yyruleno==210); - case 211: /* user_name ::= NK_ID */ yytestcase(yyruleno==211); - case 212: /* index_name ::= NK_ID */ yytestcase(yyruleno==212); - case 213: /* topic_name ::= NK_ID */ yytestcase(yyruleno==213); -{ yylhsminor.yy149 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy149 = yylhsminor.yy149; + case 206: /* db_name ::= NK_ID */ yytestcase(yyruleno==206); + case 207: /* table_name ::= NK_ID */ yytestcase(yyruleno==207); + case 208: /* column_name ::= NK_ID */ yytestcase(yyruleno==208); + case 209: /* function_name ::= NK_ID */ yytestcase(yyruleno==209); + case 210: /* table_alias ::= NK_ID */ yytestcase(yyruleno==210); + case 211: /* column_alias ::= NK_ID */ yytestcase(yyruleno==211); + case 212: /* user_name ::= NK_ID */ yytestcase(yyruleno==212); + case 213: /* index_name ::= NK_ID */ yytestcase(yyruleno==213); + case 214: /* topic_name ::= NK_ID */ yytestcase(yyruleno==214); +{ yylhsminor.yy183 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy183 = yylhsminor.yy183; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2407,922 +2405,926 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropQnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 43: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy497, &yymsp[-1].minor.yy149, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy215, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } break; case 44: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy497, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } break; case 45: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy149); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy183); } break; case 46: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy149, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy497 = true; } +{ yymsp[-2].minor.yy215 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 276: /* set_quantifier_opt ::= */ yytestcase(yyruleno==276); -{ yymsp[1].minor.yy497 = false; } + case 277: /* set_quantifier_opt ::= */ yytestcase(yyruleno==277); +{ yymsp[1].minor.yy215 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy497 = true; } +{ yymsp[-1].minor.yy215 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy140 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy378 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 53: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 54: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 55: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 56: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 57: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 58: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 59: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 60: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 61: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 62: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 63: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 64: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 65: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 66: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 67: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 68: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; case 69: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 70: /* db_options ::= db_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-2].minor.yy140, DB_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 70: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy378 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy378 = setDatabaseOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 71: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy140 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy140 = setDatabaseOption(pCxt, yylhsminor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 71: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 72: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy140 = setDatabaseOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 72: /* alter_db_option ::= BLOCKS NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 73: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 73: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } + break; + case 74: /* alter_db_option ::= KEEP NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } + break; + case 75: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_WAL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 74: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 75: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 76: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_WAL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 76: /* alter_db_option ::= QUORUM NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 77: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 77: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } + break; + case 78: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 80: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==80); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy215, yymsp[-5].minor.yy378, yymsp[-3].minor.yy404, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } + break; + case 79: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy404); } + break; + case 81: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy404); } + break; + case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } + break; + case 83: /* cmd ::= ALTER TABLE alter_table_clause */ + case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); + case 185: /* cmd ::= query_expression */ yytestcase(yyruleno==185); +{ pCxt->pRootNode = yymsp[0].minor.yy378; } + break; + case 85: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy378 = createAlterTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; + break; + case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; + break; + case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy183); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; + break; + case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; + break; + case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 78: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } - break; - case 79: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 81: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==81); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy497, yymsp[-5].minor.yy140, yymsp[-3].minor.yy136, yymsp[-1].minor.yy136, yymsp[0].minor.yy140); } - break; - case 80: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy136); } - break; - case 82: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy136); } - break; - case 83: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy497, yymsp[0].minor.yy140); } - break; - case 84: /* cmd ::= ALTER TABLE alter_table_clause */ - case 85: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==85); - case 184: /* cmd ::= query_expression */ yytestcase(yyruleno==184); -{ pCxt->pRootNode = yymsp[0].minor.yy140; } - break; - case 86: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy140 = createAlterTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; - break; - case 87: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; - break; - case 88: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; - break; - case 89: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; - break; - case 90: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 91: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy183); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 92: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 93: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 94: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ +{ yylhsminor.yy378 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy378, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378); } + yymsp[-5].minor.yy378 = yylhsminor.yy378; break; - case 95: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy140 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy140, &yymsp[-2].minor.yy149, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + case 95: /* multi_create_clause ::= create_subtable_clause */ + case 98: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==98); + case 105: /* column_def_list ::= column_def */ yytestcase(yyruleno==105); + case 148: /* col_name_list ::= col_name */ yytestcase(yyruleno==148); + case 170: /* func_name_list ::= func_name */ yytestcase(yyruleno==170); + case 179: /* func_list ::= func */ yytestcase(yyruleno==179); + case 204: /* literal_list ::= signed_literal */ yytestcase(yyruleno==204); + case 282: /* select_sublist ::= select_item */ yytestcase(yyruleno==282); + case 329: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==329); +{ yylhsminor.yy404 = createNodeList(pCxt, yymsp[0].minor.yy378); } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 96: /* multi_create_clause ::= create_subtable_clause */ - case 99: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==99); - case 106: /* column_def_list ::= column_def */ yytestcase(yyruleno==106); - case 147: /* col_name_list ::= col_name */ yytestcase(yyruleno==147); - case 169: /* func_name_list ::= func_name */ yytestcase(yyruleno==169); - case 178: /* func_list ::= func */ yytestcase(yyruleno==178); - case 203: /* literal_list ::= signed_literal */ yytestcase(yyruleno==203); - case 281: /* select_sublist ::= select_item */ yytestcase(yyruleno==281); - case 328: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==328); -{ yylhsminor.yy136 = createNodeList(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 96: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 99: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==99); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } + yymsp[-1].minor.yy404 = yylhsminor.yy404; break; - case 97: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 100: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==100); -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-1].minor.yy136, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy136 = yylhsminor.yy136; + case 97: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ +{ yylhsminor.yy378 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy215, yymsp[-7].minor.yy378, yymsp[-5].minor.yy378, yymsp[-4].minor.yy404, yymsp[-1].minor.yy404); } + yymsp[-8].minor.yy378 = yylhsminor.yy378; break; - case 98: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy140 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy497, yymsp[-7].minor.yy140, yymsp[-5].minor.yy140, yymsp[-4].minor.yy136, yymsp[-1].minor.yy136); } - yymsp[-8].minor.yy140 = yylhsminor.yy140; + case 100: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy378 = createDropTableClause(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 101: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy140 = createDropTableClause(pCxt, yymsp[-1].minor.yy497, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 101: /* specific_tags_opt ::= */ + case 132: /* tags_def_opt ::= */ yytestcase(yyruleno==132); + case 290: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==290); + case 307: /* group_by_clause_opt ::= */ yytestcase(yyruleno==307); + case 317: /* order_by_clause_opt ::= */ yytestcase(yyruleno==317); +{ yymsp[1].minor.yy404 = NULL; } break; - case 102: /* specific_tags_opt ::= */ - case 133: /* tags_def_opt ::= */ yytestcase(yyruleno==133); - case 289: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==289); - case 306: /* group_by_clause_opt ::= */ yytestcase(yyruleno==306); - case 316: /* order_by_clause_opt ::= */ yytestcase(yyruleno==316); -{ yymsp[1].minor.yy136 = NULL; } + case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy404 = yymsp[-1].minor.yy404; } break; - case 103: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy136 = yymsp[-1].minor.yy136; } + case 103: /* full_table_name ::= table_name */ +{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy183, NULL); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 104: /* full_table_name ::= table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy149, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 104: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, NULL); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 105: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 106: /* column_def_list ::= column_def_list NK_COMMA column_def */ + case 149: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==149); + case 171: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==171); + case 180: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==180); + case 205: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==205); + case 283: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==283); + case 330: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==330); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, yymsp[0].minor.yy378); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; break; - case 107: /* column_def_list ::= column_def_list NK_COMMA column_def */ - case 148: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==148); - case 170: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==170); - case 179: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==179); - case 204: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==204); - case 282: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==282); - case 329: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==329); -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, yymsp[0].minor.yy140); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 107: /* column_def ::= column_name type_name */ +{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504, NULL); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 108: /* column_def ::= column_name type_name */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy149, yymsp[0].minor.yy256, NULL); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 108: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 109: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-2].minor.yy256, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 109: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 110: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 110: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 111: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 111: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 112: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 112: /* type_name ::= INT */ + case 113: /* type_name ::= INTEGER */ yytestcase(yyruleno==113); +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 113: /* type_name ::= INT */ - case 114: /* type_name ::= INTEGER */ yytestcase(yyruleno==114); -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_INT); } + case 114: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 115: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 115: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 116: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 116: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 117: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 117: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 118: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 118: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 119: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 119: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 120: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 120: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 121: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 121: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 122: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 122: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 123: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UINT); } + case 123: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 124: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy256 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 124: /* type_name ::= JSON */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 125: /* type_name ::= JSON */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_JSON); } + case 125: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 126: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 126: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 127: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 127: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 128: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 128: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 129: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 129: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 130: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 130: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 132: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy256 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 133: /* tags_def_opt ::= tags_def */ + case 281: /* select_list ::= select_sublist */ yytestcase(yyruleno==281); +{ yylhsminor.yy404 = yymsp[0].minor.yy404; } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 134: /* tags_def_opt ::= tags_def */ - case 280: /* select_list ::= select_sublist */ yytestcase(yyruleno==280); -{ yylhsminor.yy136 = yymsp[0].minor.yy136; } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 134: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy404 = yymsp[-1].minor.yy404; } break; - case 135: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy136 = yymsp[-1].minor.yy136; } + case 135: /* table_options ::= */ +{ yymsp[1].minor.yy378 = createDefaultTableOptions(pCxt); } break; - case 136: /* table_options ::= */ -{ yymsp[1].minor.yy140 = createDefaultTableOptions(pCxt); } + case 136: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 137: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 137: /* table_options ::= table_options KEEP NK_INTEGER */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 138: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 138: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 139: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-2].minor.yy140, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 139: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy378 = setTableSmaOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 140: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy140 = setTableSmaOption(pCxt, yymsp[-4].minor.yy140, yymsp[-1].minor.yy136); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 140: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ +{ yylhsminor.yy378 = setTableRollupOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 141: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy140 = setTableRollupOption(pCxt, yymsp[-4].minor.yy140, yymsp[-1].minor.yy136); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + case 141: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 142: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy140 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy140 = setTableOption(pCxt, yylhsminor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 142: /* table_options ::= table_options DELAY NK_INTEGER */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 143: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy140 = setTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 143: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy378 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy378 = setTableOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 144: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 144: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 145: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 145: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy11.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 146: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy233.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } + case 146: /* alter_table_option ::= KEEP NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 149: /* col_name ::= column_name */ -{ yylhsminor.yy140 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy149); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 147: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy11.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } break; - case 150: /* cmd ::= SHOW DNODES */ + case 150: /* col_name ::= column_name */ +{ yylhsminor.yy378 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183); } + yymsp[0].minor.yy378 = yylhsminor.yy378; + break; + case 151: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } break; - case 151: /* cmd ::= SHOW USERS */ + case 152: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } break; - case 152: /* cmd ::= SHOW DATABASES */ + case 153: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; - case 153: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } + case 154: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } break; - case 154: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } + case 155: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } break; - case 155: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy140, NULL); } + case 156: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy378, NULL); } break; - case 156: /* cmd ::= SHOW MNODES */ + case 157: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } break; - case 157: /* cmd ::= SHOW MODULES */ + case 158: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } break; - case 158: /* cmd ::= SHOW QNODES */ + case 159: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } break; - case 159: /* cmd ::= SHOW FUNCTIONS */ + case 160: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; - case 160: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 161: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } break; - case 161: /* cmd ::= SHOW STREAMS */ + case 162: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } break; - case 162: /* db_name_cond_opt ::= */ - case 167: /* from_db_opt ::= */ yytestcase(yyruleno==167); -{ yymsp[1].minor.yy140 = createDefaultDatabaseCondValue(pCxt); } + case 163: /* db_name_cond_opt ::= */ + case 168: /* from_db_opt ::= */ yytestcase(yyruleno==168); +{ yymsp[1].minor.yy378 = createDefaultDatabaseCondValue(pCxt); } break; - case 163: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 164: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy183); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 164: /* like_pattern_opt ::= */ - case 175: /* index_options ::= */ yytestcase(yyruleno==175); - case 287: /* where_clause_opt ::= */ yytestcase(yyruleno==287); - case 291: /* twindow_clause_opt ::= */ yytestcase(yyruleno==291); - case 296: /* sliding_opt ::= */ yytestcase(yyruleno==296); - case 298: /* fill_opt ::= */ yytestcase(yyruleno==298); - case 310: /* having_clause_opt ::= */ yytestcase(yyruleno==310); - case 318: /* slimit_clause_opt ::= */ yytestcase(yyruleno==318); - case 322: /* limit_clause_opt ::= */ yytestcase(yyruleno==322); -{ yymsp[1].minor.yy140 = NULL; } + case 165: /* like_pattern_opt ::= */ + case 176: /* index_options ::= */ yytestcase(yyruleno==176); + case 288: /* where_clause_opt ::= */ yytestcase(yyruleno==288); + case 292: /* twindow_clause_opt ::= */ yytestcase(yyruleno==292); + case 297: /* sliding_opt ::= */ yytestcase(yyruleno==297); + case 299: /* fill_opt ::= */ yytestcase(yyruleno==299); + case 311: /* having_clause_opt ::= */ yytestcase(yyruleno==311); + case 319: /* slimit_clause_opt ::= */ yytestcase(yyruleno==319); + case 323: /* limit_clause_opt ::= */ yytestcase(yyruleno==323); +{ yymsp[1].minor.yy378 = NULL; } break; - case 165: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 166: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 166: /* table_name_cond ::= table_name */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy149); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 167: /* table_name_cond ::= table_name */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 168: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy149); } + case 169: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } break; - case 171: /* func_name ::= function_name */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[0].minor.yy149, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 172: /* func_name ::= function_name */ +{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[0].minor.yy183, NULL); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 172: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy497, &yymsp[-3].minor.yy149, &yymsp[-1].minor.yy149, NULL, yymsp[0].minor.yy140); } + case 173: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy215, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, NULL, yymsp[0].minor.yy378); } break; - case 173: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy497, &yymsp[-5].minor.yy149, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136, NULL); } + case 174: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy215, &yymsp[-5].minor.yy183, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404, NULL); } break; - case 174: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149); } + case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183); } break; - case 176: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy140 = createIndexOption(pCxt, yymsp[-6].minor.yy136, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL, yymsp[0].minor.yy140); } + case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy378 = createIndexOption(pCxt, yymsp[-6].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL, yymsp[0].minor.yy378); } break; - case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy140 = createIndexOption(pCxt, yymsp[-8].minor.yy136, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[0].minor.yy140); } + case 178: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy378 = createIndexOption(pCxt, yymsp[-8].minor.yy404, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[0].minor.yy378); } break; - case 180: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 181: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 181: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, yymsp[0].minor.yy140, NULL); } + case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378, NULL); } break; - case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy497, &yymsp[-2].minor.yy149, NULL, &yymsp[0].minor.yy149); } + case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, NULL, &yymsp[0].minor.yy183); } break; - case 183: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy497, &yymsp[0].minor.yy149); } + case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } break; - case 185: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 186: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 186: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 187: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 187: /* literal ::= NK_STRING */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 188: /* literal ::= NK_STRING */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 188: /* literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 189: /* literal ::= NK_BOOL */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 189: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 190: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 190: /* literal ::= duration_literal */ - case 198: /* signed_literal ::= signed */ yytestcase(yyruleno==198); - case 214: /* expression ::= literal */ yytestcase(yyruleno==214); - case 215: /* expression ::= column_reference */ yytestcase(yyruleno==215); - case 218: /* expression ::= subquery */ yytestcase(yyruleno==218); - case 250: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==250); - case 254: /* boolean_primary ::= predicate */ yytestcase(yyruleno==254); - case 256: /* common_expression ::= expression */ yytestcase(yyruleno==256); - case 257: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==257); - case 259: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==259); - case 261: /* table_reference ::= table_primary */ yytestcase(yyruleno==261); - case 262: /* table_reference ::= joined_table */ yytestcase(yyruleno==262); - case 266: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==266); - case 313: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==313); - case 315: /* query_primary ::= query_specification */ yytestcase(yyruleno==315); -{ yylhsminor.yy140 = yymsp[0].minor.yy140; } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 191: /* literal ::= duration_literal */ + case 199: /* signed_literal ::= signed */ yytestcase(yyruleno==199); + case 215: /* expression ::= literal */ yytestcase(yyruleno==215); + case 216: /* expression ::= column_reference */ yytestcase(yyruleno==216); + case 219: /* expression ::= subquery */ yytestcase(yyruleno==219); + case 251: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==251); + case 255: /* boolean_primary ::= predicate */ yytestcase(yyruleno==255); + case 257: /* common_expression ::= expression */ yytestcase(yyruleno==257); + case 258: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==258); + case 260: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==260); + case 262: /* table_reference ::= table_primary */ yytestcase(yyruleno==262); + case 263: /* table_reference ::= joined_table */ yytestcase(yyruleno==263); + case 267: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==267); + case 314: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==314); + case 316: /* query_primary ::= query_specification */ yytestcase(yyruleno==316); +{ yylhsminor.yy378 = yymsp[0].minor.yy378; } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 191: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 192: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 192: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 193: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 193: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 194: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 194: /* signed ::= NK_MINUS NK_INTEGER */ + case 195: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 195: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 196: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 196: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 197: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 197: /* signed ::= NK_MINUS NK_FLOAT */ + case 198: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 199: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 200: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 200: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 201: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 201: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 202: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 202: /* signed_literal ::= duration_literal */ - case 327: /* search_condition ::= common_expression */ yytestcase(yyruleno==327); -{ yylhsminor.yy140 = releaseRawExprNode(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 203: /* signed_literal ::= duration_literal */ + case 328: /* search_condition ::= common_expression */ yytestcase(yyruleno==328); +{ yylhsminor.yy378 = releaseRawExprNode(pCxt, yymsp[0].minor.yy378); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 216: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy149, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy149, yymsp[-1].minor.yy136)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 217: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404)); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 217: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy149, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy149, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 218: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 219: /* expression ::= NK_LP expression NK_RP */ - case 255: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==255); -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 220: /* expression ::= NK_LP expression NK_RP */ + case 256: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==256); +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 220: /* expression ::= NK_PLUS expression */ + case 221: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 221: /* expression ::= NK_MINUS expression */ + case 222: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 222: /* expression ::= expression NK_PLUS expression */ + case 223: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 223: /* expression ::= expression NK_MINUS expression */ + case 224: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 224: /* expression ::= expression NK_STAR expression */ + case 225: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 225: /* expression ::= expression NK_SLASH expression */ + case 226: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 226: /* expression ::= expression NK_REM expression */ + case 227: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 227: /* expression_list ::= expression */ -{ yylhsminor.yy136 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 228: /* expression_list ::= expression */ +{ yylhsminor.yy404 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 228: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 229: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; break; - case 229: /* column_reference ::= column_name */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy149, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy149)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 230: /* column_reference ::= column_name */ +{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy183, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183)); } + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 230: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149, createColumnNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy149)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 231: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183)); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 231: /* predicate ::= expression compare_op expression */ - case 236: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==236); + case 232: /* predicate ::= expression compare_op expression */ + case 237: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==237); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy320, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy366, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 232: /* predicate ::= expression BETWEEN expression AND expression */ + case 233: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + yymsp[-4].minor.yy378 = yylhsminor.yy378; break; - case 233: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 234: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + yymsp[-5].minor.yy378 = yylhsminor.yy378; break; - case 234: /* predicate ::= expression IS NULL */ + case 235: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 235: /* predicate ::= expression IS NOT NULL */ + case 236: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 237: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy320 = OP_TYPE_LOWER_THAN; } + case 238: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_THAN; } break; - case 238: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy320 = OP_TYPE_GREATER_THAN; } + case 239: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_THAN; } break; - case 239: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy320 = OP_TYPE_LOWER_EQUAL; } + case 240: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_EQUAL; } break; - case 240: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy320 = OP_TYPE_GREATER_EQUAL; } + case 241: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_EQUAL; } break; - case 241: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy320 = OP_TYPE_NOT_EQUAL; } + case 242: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy366 = OP_TYPE_NOT_EQUAL; } break; - case 242: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy320 = OP_TYPE_EQUAL; } + case 243: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy366 = OP_TYPE_EQUAL; } break; - case 243: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy320 = OP_TYPE_LIKE; } + case 244: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy366 = OP_TYPE_LIKE; } break; - case 244: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy320 = OP_TYPE_NOT_LIKE; } + case 245: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_LIKE; } break; - case 245: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy320 = OP_TYPE_MATCH; } + case 246: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy366 = OP_TYPE_MATCH; } break; - case 246: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy320 = OP_TYPE_NMATCH; } + case 247: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy366 = OP_TYPE_NMATCH; } break; - case 247: /* in_op ::= IN */ -{ yymsp[0].minor.yy320 = OP_TYPE_IN; } + case 248: /* in_op ::= IN */ +{ yymsp[0].minor.yy366 = OP_TYPE_IN; } break; - case 248: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy320 = OP_TYPE_NOT_IN; } + case 249: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_IN; } break; - case 249: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy136)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 250: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 251: /* boolean_value_expression ::= NOT boolean_primary */ + case 252: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 252: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 253: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 253: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 254: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 258: /* from_clause ::= FROM table_reference_list */ - case 288: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==288); - case 311: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==311); -{ yymsp[-1].minor.yy140 = yymsp[0].minor.yy140; } + case 259: /* from_clause ::= FROM table_reference_list */ + case 289: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==289); + case 312: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==312); +{ yymsp[-1].minor.yy378 = yymsp[0].minor.yy378; } break; - case 260: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy140, yymsp[0].minor.yy140, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 261: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy378 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy378, yymsp[0].minor.yy378, NULL); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 263: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 264: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 264: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-3].minor.yy149, &yymsp[-1].minor.yy149, &yymsp[0].minor.yy149); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 265: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 265: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy140 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 266: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy378 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 267: /* alias_opt ::= */ -{ yymsp[1].minor.yy149 = nil_token; } + case 268: /* alias_opt ::= */ +{ yymsp[1].minor.yy183 = nil_token; } break; - case 268: /* alias_opt ::= table_alias */ -{ yylhsminor.yy149 = yymsp[0].minor.yy149; } - yymsp[0].minor.yy149 = yylhsminor.yy149; + case 269: /* alias_opt ::= table_alias */ +{ yylhsminor.yy183 = yymsp[0].minor.yy183; } + yymsp[0].minor.yy183 = yylhsminor.yy183; break; - case 269: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy149 = yymsp[0].minor.yy149; } + case 270: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy183 = yymsp[0].minor.yy183; } break; - case 270: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 271: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==271); -{ yymsp[-2].minor.yy140 = yymsp[-1].minor.yy140; } + case 271: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 272: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==272); +{ yymsp[-2].minor.yy378 = yymsp[-1].minor.yy378; } break; - case 272: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, yymsp[-4].minor.yy144, yymsp[-5].minor.yy140, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + case 273: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy378 = createJoinTableNode(pCxt, yymsp[-4].minor.yy162, yymsp[-5].minor.yy378, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } + yymsp[-5].minor.yy378 = yylhsminor.yy378; break; - case 273: /* join_type ::= */ -{ yymsp[1].minor.yy144 = JOIN_TYPE_INNER; } + case 274: /* join_type ::= */ +{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } break; - case 274: /* join_type ::= INNER */ -{ yymsp[0].minor.yy144 = JOIN_TYPE_INNER; } + case 275: /* join_type ::= INNER */ +{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } break; - case 275: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 276: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy140 = createSelectStmt(pCxt, yymsp[-7].minor.yy497, yymsp[-6].minor.yy136, yymsp[-5].minor.yy140); - yymsp[-8].minor.yy140 = addWhereClause(pCxt, yymsp[-8].minor.yy140, yymsp[-4].minor.yy140); - yymsp[-8].minor.yy140 = addPartitionByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-3].minor.yy136); - yymsp[-8].minor.yy140 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy140, yymsp[-2].minor.yy140); - yymsp[-8].minor.yy140 = addGroupByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-1].minor.yy136); - yymsp[-8].minor.yy140 = addHavingClause(pCxt, yymsp[-8].minor.yy140, yymsp[0].minor.yy140); + yymsp[-8].minor.yy378 = createSelectStmt(pCxt, yymsp[-7].minor.yy215, yymsp[-6].minor.yy404, yymsp[-5].minor.yy378); + yymsp[-8].minor.yy378 = addWhereClause(pCxt, yymsp[-8].minor.yy378, yymsp[-4].minor.yy378); + yymsp[-8].minor.yy378 = addPartitionByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-3].minor.yy404); + yymsp[-8].minor.yy378 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy378, yymsp[-2].minor.yy378); + yymsp[-8].minor.yy378 = addGroupByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-1].minor.yy404); + yymsp[-8].minor.yy378 = addHavingClause(pCxt, yymsp[-8].minor.yy378, yymsp[0].minor.yy378); } break; - case 277: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy497 = true; } + case 278: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy215 = true; } break; - case 278: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy497 = false; } + case 279: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy215 = false; } break; - case 279: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy136 = NULL; } + case 280: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy404 = NULL; } break; - case 283: /* select_item ::= common_expression */ + case 284: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); + yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), &t); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + yymsp[0].minor.yy378 = yylhsminor.yy378; break; - case 284: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 285: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } + yymsp[-1].minor.yy378 = yylhsminor.yy378; break; - case 285: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), &yymsp[0].minor.yy149); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 286: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), &yymsp[0].minor.yy183); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 286: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy140 = createColumnNode(pCxt, &yymsp[-2].minor.yy149, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 287: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy378 = createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 290: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 307: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==307); - case 317: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==317); -{ yymsp[-2].minor.yy136 = yymsp[0].minor.yy136; } + case 291: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 308: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==308); + case 318: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==318); +{ yymsp[-2].minor.yy404 = yymsp[0].minor.yy404; } break; - case 292: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy140 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 293: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy378 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } break; - case 293: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy140 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 294: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy378 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } break; - case 294: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 295: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } break; - case 295: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 296: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } break; - case 297: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy140 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy140); } + case 298: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy378 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy378); } break; - case 299: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy140 = createFillNode(pCxt, yymsp[-1].minor.yy306, NULL); } + case 300: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy378 = createFillNode(pCxt, yymsp[-1].minor.yy466, NULL); } break; - case 300: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy140 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy136)); } + case 301: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy378 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } break; - case 301: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy306 = FILL_MODE_NONE; } + case 302: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy466 = FILL_MODE_NONE; } break; - case 302: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy306 = FILL_MODE_PREV; } + case 303: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy466 = FILL_MODE_PREV; } break; - case 303: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy306 = FILL_MODE_NULL; } + case 304: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy466 = FILL_MODE_NULL; } break; - case 304: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy306 = FILL_MODE_LINEAR; } + case 305: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy466 = FILL_MODE_LINEAR; } break; - case 305: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy306 = FILL_MODE_NEXT; } + case 306: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy466 = FILL_MODE_NEXT; } break; - case 308: /* group_by_list ::= expression */ -{ yylhsminor.yy136 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[0].minor.yy136 = yylhsminor.yy136; + case 309: /* group_by_list ::= expression */ +{ yylhsminor.yy404 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 309: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy136 = addNodeToList(pCxt, yymsp[-2].minor.yy136, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy136 = yylhsminor.yy136; + case 310: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; break; - case 312: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 313: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy140 = addOrderByClause(pCxt, yymsp[-3].minor.yy140, yymsp[-2].minor.yy136); - yylhsminor.yy140 = addSlimitClause(pCxt, yylhsminor.yy140, yymsp[-1].minor.yy140); - yylhsminor.yy140 = addLimitClause(pCxt, yylhsminor.yy140, yymsp[0].minor.yy140); + yylhsminor.yy378 = addOrderByClause(pCxt, yymsp[-3].minor.yy378, yymsp[-2].minor.yy404); + yylhsminor.yy378 = addSlimitClause(pCxt, yylhsminor.yy378, yymsp[-1].minor.yy378); + yylhsminor.yy378 = addLimitClause(pCxt, yylhsminor.yy378, yymsp[0].minor.yy378); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 314: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy140 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 315: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy378 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy378, yymsp[0].minor.yy378); } + yymsp[-3].minor.yy378 = yylhsminor.yy378; break; - case 319: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 323: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==323); -{ yymsp[-1].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 320: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 324: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==324); +{ yymsp[-1].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 320: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 324: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==324); -{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 321: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 325: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==325); +{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 321: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 325: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==325); -{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 322: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 326: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==326); +{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 326: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy140); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 327: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy378); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 330: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy140 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[-1].minor.yy158, yymsp[0].minor.yy73); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 331: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy378 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[-1].minor.yy400, yymsp[0].minor.yy151); } + yymsp[-2].minor.yy378 = yylhsminor.yy378; break; - case 331: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy158 = ORDER_ASC; } + case 332: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy400 = ORDER_ASC; } break; - case 332: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy158 = ORDER_ASC; } + case 333: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy400 = ORDER_ASC; } break; - case 333: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy158 = ORDER_DESC; } + case 334: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy400 = ORDER_DESC; } break; - case 334: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy73 = NULL_ORDER_DEFAULT; } + case 335: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy151 = NULL_ORDER_DEFAULT; } break; - case 335: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy73 = NULL_ORDER_FIRST; } + case 336: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy151 = NULL_ORDER_FIRST; } break; - case 336: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy73 = NULL_ORDER_LAST; } + case 337: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy151 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 1813ad0827..3057e06fe1 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -416,6 +416,7 @@ TEST_F(ParserTest, createDatabase) { "VGROUPS 100 " "SINGLE_STABLE 0 " "STREAM_MODE 1 " + "RETENTIONS '15s:7d,1m:21d,15m:5y'" ); ASSERT_TRUE(run()); } @@ -469,7 +470,7 @@ TEST_F(ParserTest, createTable) { "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) " "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, " "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)" + "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" ); ASSERT_TRUE(run()); @@ -491,7 +492,7 @@ TEST_F(ParserTest, createTable) { "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) " "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, " "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)" + "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2" ); ASSERT_TRUE(run()); } From b27fa6c8e3521ddc078de0903fc6ec7c7729a8e2 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 17:22:18 +0800 Subject: [PATCH 137/149] stream add shuffle dispatcher --- include/common/tmsg.h | 4 +- include/libs/stream/tstream.h | 6 +- source/common/src/tmsg.c | 4 +- source/dnode/mnode/impl/inc/mndDb.h | 1 + source/dnode/mnode/impl/src/mndDb.c | 80 ++++++----- source/dnode/mnode/impl/src/mndScheduler.c | 11 ++ source/libs/stream/src/tstream.c | 157 +++++++++++++++------ 7 files changed, 174 insertions(+), 89 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bdb6181884..6494e06c45 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -565,8 +565,10 @@ typedef struct { SArray* pVgroupInfos; // Array of SVgroupInfo } SUseDbRsp; -int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp); +int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp); int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp); +int32_t tSerializeSUseDbRspImp(SCoder* pEncoder, const SUseDbRsp* pRsp); +int32_t tDeserializeSUseDbRspImp(SCoder* pDecoder, SUseDbRsp* pRsp); void tFreeSUsedbRsp(SUseDbRsp* pRsp); typedef struct { diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 8be9bbbebd..02fe591a09 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -72,8 +72,9 @@ typedef struct { } STaskDispatcherFixedEp; typedef struct { - int8_t hashMethod; - SArray* info; + // int8_t hashMethod; + char stbFullName[TSDB_TABLE_FNAME_LEN]; + SUseDbRsp dbInfo; } STaskDispatcherShuffle; typedef struct { @@ -135,7 +136,6 @@ typedef struct { int8_t sinkType; int8_t dispatchType; int16_t dispatchMsgType; - int32_t downstreamTaskId; int32_t nodeId; SEpSet epSet; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index f464ce6f50..c85184ffba 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1829,7 +1829,7 @@ int32_t tDeserializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) { return 0; } -static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) { +int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, const SUseDbRsp *pRsp) { if (tEncodeCStr(pEncoder, pRsp->db) < 0) return -1; if (tEncodeI64(pEncoder, pRsp->uid) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1; @@ -1848,7 +1848,7 @@ static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) { return 0; } -int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, SUseDbRsp *pRsp) { +int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, const SUseDbRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mnode/impl/inc/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h index 125b0d3191..c0b25d74d1 100644 --- a/source/dnode/mnode/impl/inc/mndDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -28,6 +28,7 @@ SDbObj *mndAcquireDb(SMnode *pMnode, const char *db); void mndReleaseDb(SMnode *pMnode, SDbObj *pDb); int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, void **ppRsp, int32_t *pRspLen); char *mnGetDbStr(char *src); +int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUseDbReq *pReq); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 05c7d79a1a..1f629b8837 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -955,7 +955,6 @@ void mndGetDBTableNum(SDbObj *pDb, SMnode *pMnode, int32_t *num) { sdbCancelFetch(pSdb, pIter); } - static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { int32_t vindex = 0; SSdb *pSdb = pMnode->pSdb; @@ -991,7 +990,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { } sdbRelease(pSdb, pVgroup); - + if (pDb && (vindex >= pDb->cfg.numOfVgroups)) { break; } @@ -1000,6 +999,28 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { sdbCancelFetch(pSdb, pIter); } +int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUseDbReq *pReq) { + pRsp->pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); + if (pRsp->pVgroupInfos == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + int32_t numOfTable = 0; + mndGetDBTableNum(pDb, pMnode, &numOfTable); + + if (pReq == NULL || pReq->vgVersion < pDb->vgVersion || pReq->dbId != pDb->uid || numOfTable != pReq->numOfTable) { + mndBuildDBVgroupInfo(pDb, pMnode, pRsp->pVgroupInfos); + } + + memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN); + pRsp->uid = pDb->uid; + pRsp->vgVersion = pDb->vgVersion; + pRsp->vgNum = taosArrayGetSize(pRsp->pVgroupInfos); + pRsp->hashMethod = pDb->hashMethod; + return 0; +} + static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; int32_t code = -1; @@ -1023,10 +1044,10 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto USE_DB_OVER; } - + mndBuildDBVgroupInfo(NULL, pMnode, usedbRsp.pVgroupInfos); usedbRsp.vgVersion = vgVersion++; - + if (taosArrayGetSize(usedbRsp.pVgroupInfos) <= 0) { terrno = TSDB_CODE_MND_DB_NOT_EXIST; } @@ -1034,7 +1055,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { usedbRsp.vgVersion = usedbReq.vgVersion; code = 0; } - usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); + usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); // no jump, need to construct rsp } else { @@ -1057,24 +1078,10 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { goto USE_DB_OVER; } - usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); - if (usedbRsp.pVgroupInfos == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + if (mndExtractDbInfo(pMnode, pDb, &usedbRsp, &usedbReq) < 0) { goto USE_DB_OVER; } - int32_t numOfTable = 0; - mndGetDBTableNum(pDb, pMnode, &numOfTable); - - if (usedbReq.vgVersion < pDb->vgVersion || usedbReq.dbId != pDb->uid || numOfTable != usedbReq.numOfTable) { - mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos); - } - - memcpy(usedbRsp.db, pDb->name, TSDB_DB_FNAME_LEN); - usedbRsp.uid = pDb->uid; - usedbRsp.vgVersion = pDb->vgVersion; - usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); - usedbRsp.hashMethod = pDb->hashMethod; code = 0; } } @@ -1138,7 +1145,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, mndReleaseDb(pMnode, pDb); continue; } - + usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); if (usedbRsp.pVgroupInfos == NULL) { mndReleaseDb(pMnode, pDb); @@ -1364,11 +1371,11 @@ static int32_t mndGetDbMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMet pSchema[cols].bytes = pShow->bytes[cols]; cols++; -// pShow->bytes[cols] = 1; -// pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; -// strcpy(pSchema[cols].name, "update"); -// pSchema[cols].bytes = pShow->bytes[cols]; -// cols++; + // pShow->bytes[cols] = 1; + // pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; + // strcpy(pSchema[cols].name, "update"); + // pSchema[cols].bytes = pShow->bytes[cols]; + // cols++; pMeta->numOfColumns = cols; pShow->numOfColumns = cols; @@ -1396,14 +1403,15 @@ char *mnGetDbStr(char *src) { return pos; } -static char* getDataPosition(char* pData, SShowObj* pShow, int32_t cols, int32_t rows, int32_t capacityOfRow) { +static char *getDataPosition(char *pData, SShowObj *pShow, int32_t cols, int32_t rows, int32_t capacityOfRow) { return pData + pShow->offset[cols] * capacityOfRow + pShow->bytes[cols] * rows; } -static void dumpDbInfoToPayload(char* data, SDbObj* pDb, SShowObj* pShow, int32_t rows, int32_t rowCapacity, int64_t numOfTables) { +static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_t rows, int32_t rowCapacity, + int64_t numOfTables) { int32_t cols = 0; - char* pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + char *pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); char *name = mnGetDbStr(pDb->name); if (name != NULL) { STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); @@ -1497,20 +1505,20 @@ static void dumpDbInfoToPayload(char* data, SDbObj* pDb, SShowObj* pShow, int32_ STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2); cols++; -// pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); -// *(int8_t *)pWrite = pDb->cfg.update; + // pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + // *(int8_t *)pWrite = pDb->cfg.update; } -static void setInformationSchemaDbCfg(SDbObj* pDbObj) { +static void setInformationSchemaDbCfg(SDbObj *pDbObj) { ASSERT(pDbObj != NULL); strncpy(pDbObj->name, TSDB_INFORMATION_SCHEMA_DB, tListLen(pDbObj->name)); - pDbObj->createdTime = 0; + pDbObj->createdTime = 0; pDbObj->cfg.numOfVgroups = 0; - pDbObj->cfg.quorum = 1; + pDbObj->cfg.quorum = 1; pDbObj->cfg.replications = 1; - pDbObj->cfg.update = 1; - pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; + pDbObj->cfg.update = 1; + pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rowsCapacity) { diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 697811cd04..305912a72a 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -222,8 +222,19 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i /*pTask->sinkType = TASK_SINK__NONE;*/ // dispatch part + pTask->dispatchType = TASK_DISPATCH__NONE; +#if 0 pTask->dispatchType = TASK_DISPATCH__SHUFFLE; pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; + SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); + ASSERT(pDb); + if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { + sdbRelease(pSdb, pDb); + qDestroyQueryPlan(pPlan); + return -1; + } + sdbRelease(pSdb, pDb); +#endif // exec part pTask->execType = TASK_EXEC__MERGE; diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 028e310a25..eb4cd2f97d 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -16,12 +16,88 @@ #include "tstream.h" #include "executor.h" +static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { + SStreamTaskExecReq req = { + .streamId = pTask->streamId, + .data = data, + }; + + int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); + void* buf = rpcMallocCont(tlen); + + if (buf == NULL) { + return -1; + } + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { + ((SMsgHead*)buf)->vgId = 0; + req.taskId = pTask->inplaceDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); + *ppEpSet = &pTask->fixedEpDispatcher.epSet; + req.taskId = pTask->fixedEpDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { + int32_t nodeId = 0; + char ctbName[TSDB_TABLE_FNAME_LEN]; + // all groupId must be the same in an array + SSDataBlock* pBlock = taosArrayGet(data, 0); + sprintf(ctbName, "%s:%ld", pTask->shuffleDispatcher.stbFullName, pBlock->info.groupId); + + // TODO: get hash function by hashMethod + + // get groupId, compute hash value + uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName)); + // + // get node + // TODO: optimize search process + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t sz = taosArrayGetSize(vgInfo); + for (int32_t i = 0; i < sz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + if (hashValue >= pVgInfo->hashBegin && hashValue <= pVgInfo->hashEnd) { + nodeId = pVgInfo->vgId; + *ppEpSet = &pVgInfo->epSet; + break; + } + } + ASSERT(nodeId != 0); + ((SMsgHead*)buf)->vgId = htonl(nodeId); + } + + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tEncodeSStreamTaskExecReq(&abuf, &req); + + pMsg->pCont = buf; + pMsg->contLen = tlen; + pMsg->code = 0; + pMsg->msgType = pTask->dispatchMsgType; + + return 0; +} + +static int32_t streamShuffleDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SHashObj* data) { + void* pIter = NULL; + while (1) { + pIter = taosHashIterate(data, pIter); + if (pIter == NULL) return 0; + SArray* pData = (SArray*)pIter; + SRpcMsg dispatchMsg = {0}; + SEpSet* pEpSet; + if (streamBuildDispatchMsg(pTask, pData, &dispatchMsg, &pEpSet) < 0) { + ASSERT(0); + return -1; + } + tmsgSendReq(pMsgCb, pEpSet, &dispatchMsg); + } + return 0; +} + int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, int32_t inputType, int32_t workId) { SArray* pRes = NULL; // source if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK && pTask->sourceType != TASK_SOURCE__SCAN) return 0; // exec + // TODO: for shuffle dispatcher, merge data by groupId if (pTask->execType != TASK_EXEC__NONE) { ASSERT(workId < pTask->exec.numOfRunners); void* exec = pTask->exec.runners[workId].executor; @@ -83,28 +159,13 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in } // dispatch + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - SStreamTaskExecReq req = { - .streamId = pTask->streamId, - .taskId = pTask->taskId, - .data = pRes, - }; - - int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); - void* buf = rpcMallocCont(tlen); - - if (buf == NULL) { + SRpcMsg dispatchMsg = {0}; + if (streamBuildDispatchMsg(pTask, pRes, &dispatchMsg, NULL) < 0) { + ASSERT(0); return -1; } - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSStreamTaskExecReq(&abuf, &req); - - SRpcMsg dispatchMsg = { - .pCont = buf, - .contLen = tlen, - .code = 0, - .msgType = pTask->dispatchMsgType, - }; int32_t qType; if (pTask->dispatchMsgType == TDMT_VND_TASK_PIPE_EXEC || pTask->dispatchMsgType == TDMT_SND_TASK_PIPE_EXEC) { @@ -120,36 +181,38 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in tmsgPutToQueue(pMsgCb, qType, &dispatchMsg); } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - SStreamTaskExecReq req = { - .streamId = pTask->streamId, - .taskId = pTask->fixedEpDispatcher.taskId, - .data = pRes, - }; - - int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); - void* buf = rpcMallocCont(tlen); - - if (buf == NULL) { + SRpcMsg dispatchMsg = {0}; + SEpSet* pEpSet = NULL; + if (streamBuildDispatchMsg(pTask, pRes, &dispatchMsg, &pEpSet) < 0) { + ASSERT(0); return -1; } - ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSStreamTaskExecReq(&abuf, &req); - - SRpcMsg dispatchMsg = { - .pCont = buf, - .contLen = tlen, - .code = 0, - .msgType = pTask->dispatchMsgType, - }; - - SEpSet* pEpSet = &pTask->fixedEpDispatcher.epSet; - tmsgSendReq(pMsgCb, pEpSet, &dispatchMsg); } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - // TODO + SHashObj* pShuffleRes = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (pShuffleRes == NULL) { + return -1; + } + + int32_t sz = taosArrayGetSize(pRes); + for (int32_t i = 0; i < sz; i++) { + SSDataBlock* pDataBlock = taosArrayGet(pRes, i); + SArray* pArray = taosHashGet(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t)); + if (pArray == NULL) { + pArray = taosArrayInit(0, sizeof(SSDataBlock)); + if (pArray == NULL) { + return -1; + } + taosHashPut(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t), &pArray, sizeof(void*)); + } + taosArrayPush(pArray, pDataBlock); + } + + if (streamShuffleDispatch(pTask, pMsgCb, pShuffleRes) < 0) { + return -1; + } } else { ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); @@ -196,7 +259,6 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->downstreamTaskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; @@ -225,7 +287,8 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1; + if (tSerializeSUseDbRspImp(pEncoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; + /*if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ } /*tEndEncode(pEncoder);*/ @@ -242,7 +305,6 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->downstreamTaskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; @@ -271,7 +333,8 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1; + /*if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ + if (tDeserializeSUseDbRspImp(pDecoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; } /*tEndDecode(pDecoder);*/ From ce016a216cfe8c3133f2c86eeeafbbaea7742652 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 17:25:12 +0800 Subject: [PATCH 138/149] refact node msg fp --- include/util/tqueue.h | 2 +- source/dnode/mgmt/bnode/inc/bmInt.h | 2 +- source/dnode/mgmt/bnode/src/bmWorker.c | 6 +- source/dnode/mgmt/container/inc/dnd.h | 2 +- source/dnode/mgmt/container/src/dndExec.c | 3 +- source/dnode/mgmt/container/src/dndMsg.c | 2 +- source/dnode/mgmt/dnode/inc/dmInt.h | 2 +- source/dnode/mgmt/dnode/src/dmMsg.c | 26 ++-- source/dnode/mgmt/dnode/src/dmWorker.c | 6 +- source/dnode/mgmt/mnode/inc/mmInt.h | 13 +- source/dnode/mgmt/mnode/src/mmInt.c | 1 + source/dnode/mgmt/mnode/src/mmMsg.c | 162 +++++++++++----------- source/dnode/mgmt/mnode/src/mmWorker.c | 75 +++++----- source/dnode/mgmt/qnode/inc/qmInt.h | 4 +- source/dnode/mgmt/qnode/src/qmMsg.c | 18 +-- source/dnode/mgmt/qnode/src/qmWorker.c | 27 ++-- source/dnode/mgmt/snode/inc/smInt.h | 8 +- source/dnode/mgmt/snode/src/smMsg.c | 4 +- source/dnode/mgmt/snode/src/smWorker.c | 26 ++-- source/dnode/mgmt/vnode/inc/vmInt.h | 12 +- source/dnode/mgmt/vnode/src/vmMsg.c | 88 ++++++------ source/dnode/mgmt/vnode/src/vmWorker.c | 63 ++++++--- source/util/src/tqueue.c | 4 +- 23 files changed, 296 insertions(+), 260 deletions(-) diff --git a/include/util/tqueue.h b/include/util/tqueue.h index 3bccc7404b..70db65d50f 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -56,7 +56,7 @@ void taosCloseQueue(STaosQueue *queue); void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp); void *taosAllocateQitem(int32_t size); void taosFreeQitem(void *pItem); -int32_t taosWriteQitem(STaosQueue *queue, void *pItem); +void taosWriteQitem(STaosQueue *queue, void *pItem); int32_t taosReadQitem(STaosQueue *queue, void **ppItem); bool taosQueueEmpty(STaosQueue *queue); int32_t taosQueueSize(STaosQueue *queue); diff --git a/source/dnode/mgmt/bnode/inc/bmInt.h b/source/dnode/mgmt/bnode/inc/bmInt.h index 8cfff0f1f3..f19ba4e034 100644 --- a/source/dnode/mgmt/bnode/inc/bmInt.h +++ b/source/dnode/mgmt/bnode/inc/bmInt.h @@ -43,7 +43,7 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); // bmWorker.c int32_t bmStartWorker(SBnodeMgmt *pMgmt); void bmStopWorker(SBnodeMgmt *pMgmt); -int32_t bmProcessWriteMsg(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/bnode/src/bmWorker.c b/source/dnode/mgmt/bnode/src/bmWorker.c index 1ed9b0d931..932c008e34 100644 --- a/source/dnode/mgmt/bnode/src/bmWorker.c +++ b/source/dnode/mgmt/bnode/src/bmWorker.c @@ -63,11 +63,13 @@ static void bmProcessQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs taosArrayDestroy(pArray); } -int32_t bmProcessWriteMsg(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SBnodeMgmt *pMgmt = pWrapper->pMgmt; SMultiWorker *pWorker = &pMgmt->writeWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t bmStartWorker(SBnodeMgmt *pMgmt) { diff --git a/source/dnode/mgmt/container/inc/dnd.h b/source/dnode/mgmt/container/inc/dnd.h index f6c8897f64..7c06e08dff 100644 --- a/source/dnode/mgmt/container/inc/dnd.h +++ b/source/dnode/mgmt/container/inc/dnd.h @@ -63,7 +63,7 @@ typedef struct SQnodeMgmt SQnodeMgmt; typedef struct SSnodeMgmt SSnodeMgmt; typedef struct SBnodeMgmt SBnodeMgmt; -typedef int32_t (*NodeMsgFp)(void *pMgmt, SNodeMsg *pMsg); +typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper); typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper); typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper); diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index cc1d8e5f24..94c996280f 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -123,7 +123,8 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t pRpc->ahandle); NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; - int32_t code = (*msgFp)(pWrapper->pMgmt, pMsg); + int32_t code = (*msgFp)(pWrapper, pMsg); + dTrace("msg:%p, is processed, code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (code != 0) { if (pRpc->msgType & 1U) { diff --git a/source/dnode/mgmt/container/src/dndMsg.c b/source/dnode/mgmt/container/src/dndMsg.c index b72d085861..5da1d73034 100644 --- a/source/dnode/mgmt/container/src/dndMsg.c +++ b/source/dnode/mgmt/container/src/dndMsg.c @@ -62,7 +62,7 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { if (pWrapper->procType == PROC_SINGLE) { dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); - code = (*msgFp)(pWrapper->pMgmt, pMsg); + code = (*msgFp)(pWrapper, pMsg); } else if (pWrapper->procType == PROC_PARENT) { dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user); diff --git a/source/dnode/mgmt/dnode/inc/dmInt.h b/source/dnode/mgmt/dnode/inc/dmInt.h index b02b1d2297..3036d1f5ad 100644 --- a/source/dnode/mgmt/dnode/inc/dmInt.h +++ b/source/dnode/mgmt/dnode/inc/dmInt.h @@ -54,7 +54,7 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); int32_t dmStartWorker(SDnodeMgmt *pMgmt); void dmStopWorker(SDnodeMgmt *pMgmt); int32_t dmStartThread(SDnodeMgmt *pMgmt); -int32_t dmProcessMgmtMsg(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/dnode/src/dmMsg.c b/source/dnode/mgmt/dnode/src/dmMsg.c index eb4e843c55..b301ef478b 100644 --- a/source/dnode/mgmt/dnode/src/dmMsg.c +++ b/source/dnode/mgmt/dnode/src/dmMsg.c @@ -118,19 +118,19 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { void dmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, VND_VGID); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, (NodeMsgFp)dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, VND_VGID); } diff --git a/source/dnode/mgmt/dnode/src/dmWorker.c b/source/dnode/mgmt/dnode/src/dmWorker.c index 8e560503d0..63b9704b78 100644 --- a/source/dnode/mgmt/dnode/src/dmWorker.c +++ b/source/dnode/mgmt/dnode/src/dmWorker.c @@ -140,12 +140,14 @@ void dmStopWorker(SDnodeMgmt *pMgmt) { dDebug("dnode workers are closed"); } -int32_t dmProcessMgmtMsg(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->mgmtWorker; if (pMsg->rpcMsg.msgType == TDMT_MND_STATUS_RSP) { pWorker = &pMgmt->statusWorker; } dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } diff --git a/source/dnode/mgmt/mnode/inc/mmInt.h b/source/dnode/mgmt/mnode/inc/mmInt.h index cd4585048b..86cba97a33 100644 --- a/source/dnode/mgmt/mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mnode/inc/mmInt.h @@ -55,13 +55,14 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); // mmWorker.c int32_t mmStartWorker(SMnodeMgmt *pMgmt); void mmStopWorker(SMnodeMgmt *pMgmt); -int32_t mmProcessWriteMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessSyncMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg); -int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg); +int32_t mmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessReadMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); +int32_t mmPutMsgToSyncQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mnode/src/mmInt.c b/source/dnode/mgmt/mnode/src/mmInt.c index 61afcb11d1..f5a3252fa2 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mnode/src/mmInt.c @@ -48,6 +48,7 @@ static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; + msgCb.queueFps[SYNC_QUEUE] = mmPutMsgToWriteQueue; msgCb.sendReqFp = dndSendReqToDnode; msgCb.sendMnodeReqFp = dndSendReqToMnode; msgCb.sendRspFp = dndSendRsp; diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c index d04077baf8..6afcd249b3 100644 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ b/source/dnode/mgmt/mnode/src/mmMsg.c @@ -75,91 +75,91 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { void mmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, VND_VGID); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, (NodeMsgFp)mmProcessReadMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, VND_VGID); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MND_VGID); } diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mnode/src/mmWorker.c index d07313410a..0897951fe3 100644 --- a/source/dnode/mgmt/mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mnode/src/mmWorker.c @@ -67,60 +67,63 @@ static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } - -static int32_t mmPutMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SNodeMsg *pMsg) { +static void mmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); } -int32_t mmProcessWriteMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->writeWorker, pMsg); +int32_t mmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->writeWorker, pMsg); + return 0; } -int32_t mmProcessSyncMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg); +int32_t mmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->syncWorker, pMsg); + return 0; } -int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg); +int32_t mmProcessReadMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->readWorker, pMsg); + return 0; } -int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg); +int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mmPutMsgToWorker(&pMgmt->queryWorker, pMsg); + return 0; } -static int32_t mmPutRpcMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) { +static int32_t mmPutRpcMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); - if (pMsg == NULL) { - return -1; - } + if (pMsg == NULL) return -1; dTrace("msg:%p, is created and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; - - int32_t code = taosWriteQitem(pWorker->queue, pMsg); - if (code != 0) { - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pRpc->pCont); - } - - return code; -} - -int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->writeWorker, pRpc); -} - -int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->readWorker, pRpc); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mmPutRpcMsgToWorker(pMgmt, &pMgmt->queryWorker, pRpc); + return mmPutRpcMsgToWorker(&pMgmt->queryWorker, pRpc); +} + +int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->writeWorker, pRpc); +} + +int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->readWorker, pRpc); +} + +int32_t mmPutMsgToSyncQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mmPutRpcMsgToWorker(&pMgmt->syncWorker, pRpc); } int32_t mmStartWorker(SMnodeMgmt *pMgmt) { @@ -153,8 +156,8 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { } void mmStopWorker(SMnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); + tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->writeWorker); tSingleWorkerCleanup(&pMgmt->syncWorker); dDebug("mnode workers are closed"); diff --git a/source/dnode/mgmt/qnode/inc/qmInt.h b/source/dnode/mgmt/qnode/inc/qmInt.h index 52d23a445c..3e975663d3 100644 --- a/source/dnode/mgmt/qnode/inc/qmInt.h +++ b/source/dnode/mgmt/qnode/inc/qmInt.h @@ -48,8 +48,8 @@ int32_t qmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype); int32_t qmStartWorker(SQnodeMgmt *pMgmt); void qmStopWorker(SQnodeMgmt *pMgmt); -int32_t qmProcessQueryMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t qmProcessFetchMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t qmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/qnode/src/qmMsg.c b/source/dnode/mgmt/qnode/src/qmMsg.c index ebe6477e81..da5ba6472a 100644 --- a/source/dnode/mgmt/qnode/src/qmMsg.c +++ b/source/dnode/mgmt/qnode/src/qmMsg.c @@ -56,14 +56,14 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { void qmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)qmProcessQueryMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)qmProcessQueryMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QND_VGID); } diff --git a/source/dnode/mgmt/qnode/src/qmWorker.c b/source/dnode/mgmt/qnode/src/qmWorker.c index 5923f5c2f4..14efb311b1 100644 --- a/source/dnode/mgmt/qnode/src/qmWorker.c +++ b/source/dnode/mgmt/qnode/src/qmWorker.c @@ -49,14 +49,22 @@ static void qmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } -static int32_t qmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { +static void qmPutMsgToWorker(SSingleWorker *pWorker, SNodeMsg *pMsg) { dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); } -int32_t qmProcessQueryMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg) { return qmPutMsgToWorker(&pMgmt->queryWorker, pMsg); } +int32_t qmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + qmPutMsgToWorker(&pMgmt->queryWorker, pMsg); + return 0; +} -int32_t qmProcessFetchMsg(SQnodeMgmt *pMgmt, SNodeMsg *pMsg) { return qmPutMsgToWorker(&pMgmt->fetchWorker, pMsg); } +int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + qmPutMsgToWorker(&pMgmt->fetchWorker, pMsg); + return 0; +} static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); @@ -66,15 +74,8 @@ static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SR dTrace("msg:%p, is created and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; - - int32_t code = taosWriteQitem(pWorker->queue, pMsg); - if (code != 0) { - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pRpc->pCont); - } - - return code; + taosWriteQitem(pWorker->queue, pMsg); + return 0; } int32_t qmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { diff --git a/source/dnode/mgmt/snode/inc/smInt.h b/source/dnode/mgmt/snode/inc/smInt.h index f2b510483c..9290384cab 100644 --- a/source/dnode/mgmt/snode/inc/smInt.h +++ b/source/dnode/mgmt/snode/inc/smInt.h @@ -46,10 +46,10 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); // smWorker.c int32_t smStartWorker(SSnodeMgmt *pMgmt); void smStopWorker(SSnodeMgmt *pMgmt); -int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessSharedMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t smProcessExecMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessSharedMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessExecMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/snode/src/smMsg.c b/source/dnode/mgmt/snode/src/smMsg.c index aea1dded56..c522ef7fc3 100644 --- a/source/dnode/mgmt/snode/src/smMsg.c +++ b/source/dnode/mgmt/snode/src/smMsg.c @@ -56,6 +56,6 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { void smInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by SNODE - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, (NodeMsgFp)smProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, (NodeMsgFp)smProcessExecMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, VND_VGID); } diff --git a/source/dnode/mgmt/snode/src/smWorker.c b/source/dnode/mgmt/snode/src/smWorker.c index 4e46ad5818..0326d7dd9f 100644 --- a/source/dnode/mgmt/snode/src/smWorker.c +++ b/source/dnode/mgmt/snode/src/smWorker.c @@ -107,7 +107,8 @@ static FORCE_INLINE int32_t smGetSWTypeFromMsg(SRpcMsg *pMsg) { return 0; } -int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, 0); if (pWorker == NULL) { terrno = TSDB_CODE_INVALID_MSG; @@ -115,10 +116,12 @@ int32_t smProcessMgmtMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { } dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; int32_t index = smGetSWIdFromMsg(&pMsg->rpcMsg); SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, index); if (pWorker == NULL) { @@ -127,21 +130,24 @@ int32_t smProcessUniqueMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { } dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessSharedMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t smProcessSharedMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->sharedWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } -int32_t smProcessExecMsg(SSnodeMgmt *pMgmt, SNodeMsg *pMsg) { - int32_t workerType = smGetSWTypeFromMsg(&pMsg->rpcMsg); +int32_t smProcessExecMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + int32_t workerType = smGetSWTypeFromMsg(&pMsg->rpcMsg); if (workerType == SND_WORKER_TYPE__SHARED) { - return smProcessSharedMsg(pMgmt, pMsg); + return smProcessSharedMsg(pWrapper, pMsg); } else { - return smProcessUniqueMsg(pMgmt, pMsg); + return smProcessUniqueMsg(pWrapper, pMsg); } } diff --git a/source/dnode/mgmt/vnode/inc/vmInt.h b/source/dnode/mgmt/vnode/inc/vmInt.h index 197c606a0d..6722fe1d65 100644 --- a/source/dnode/mgmt/vnode/inc/vmInt.h +++ b/source/dnode/mgmt/vnode/inc/vmInt.h @@ -108,12 +108,12 @@ int32_t vmPutMsgToFetchQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmPutMsgToApplyQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype); -int32_t vmProcessWriteMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessSyncMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessQueryMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessFetchMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessMergeMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); -int32_t vmProcessMgmtMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg); +int32_t vmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessMergeMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrappert, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index 97d829571f..a5986f8502 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -244,49 +244,49 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { void vmInitMsgHandles(SMgmtWrapper *pWrapper) { // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, vmProcessQueryMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, vmProcessFetchMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, VND_VGID); } diff --git a/source/dnode/mgmt/vnode/src/vmWorker.c b/source/dnode/mgmt/vnode/src/vmWorker.c index 99274ac99b..193807317f 100644 --- a/source/dnode/mgmt/vnode/src/vmWorker.c +++ b/source/dnode/mgmt/vnode/src/vmWorker.c @@ -179,9 +179,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO } static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueType qtype) { - SRpcMsg *pRpc = &pMsg->rpcMsg; - int32_t code = -1; - + SRpcMsg *pRpc = &pMsg->rpcMsg; SMsgHead *pHead = pRpc->pCont; pHead->contLen = ntohl(pHead->contLen); pHead->vgId = ntohl(pHead->vgId); @@ -192,28 +190,30 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp return -1; } + int32_t code = 0; switch (qtype) { case QUERY_QUEUE: dTrace("msg:%p, will be written into vnode-query queue", pMsg); - code = taosWriteQitem(pVnode->pQueryQ, pMsg); + taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: dTrace("msg:%p, will be written into vnode-fetch queue", pMsg); - code = taosWriteQitem(pVnode->pFetchQ, pMsg); + taosWriteQitem(pVnode->pFetchQ, pMsg); break; case WRITE_QUEUE: dTrace("msg:%p, will be written into vnode-write queue", pMsg); - code = taosWriteQitem(pVnode->pWriteQ, pMsg); + taosWriteQitem(pVnode->pWriteQ, pMsg); break; case SYNC_QUEUE: dTrace("msg:%p, will be written into vnode-sync queue", pMsg); - code = taosWriteQitem(pVnode->pSyncQ, pMsg); + taosWriteQitem(pVnode->pSyncQ, pMsg); break; case MERGE_QUEUE: dTrace("msg:%p, will be written into vnode-merge queue", pMsg); - code = taosWriteQitem(pVnode->pMergeQ, pMsg); + taosWriteQitem(pVnode->pMergeQ, pMsg); break; default: + code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } @@ -222,52 +222,73 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp return code; } -int32_t vmProcessSyncMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); } +int32_t vmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); +} -int32_t vmProcessWriteMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); } +int32_t vmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); +} -int32_t vmProcessQueryMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); } +int32_t vmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); +} -int32_t vmProcessFetchMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); } +int32_t vmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); +} -int32_t vmProcessMergeMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return vmPutNodeMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); } +int32_t vmProcessMergeMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + return vmPutNodeMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); +} -int32_t vmProcessMgmtMsg(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->mgmtWorker; dTrace("msg:%p, will be written to vnode-mgmt queue, worker:%s", pMsg, pWorker->name); - return taosWriteQitem(pWorker->queue, pMsg); + taosWriteQitem(pWorker->queue, pMsg); + return 0; } static int32_t vmPutRpcMsgToQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, EQueueType qtype) { SVnodesMgmt *pMgmt = pWrapper->pMgmt; - int32_t code = -1; SMsgHead *pHead = pRpc->pCont; SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) return -1; SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); - if (pMsg != NULL) { + int32_t code = 0; + + if (pMsg == NULL) { + code = -1; + } else { dTrace("msg:%p, is created, type:%s", pMsg, TMSG_INFO(pRpc->msgType)); pMsg->rpcMsg = *pRpc; switch (qtype) { case QUERY_QUEUE: dTrace("msg:%p, will be put into vnode-query queue", pMsg); - code = taosWriteQitem(pVnode->pQueryQ, pMsg); + taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: dTrace("msg:%p, will be put into vnode-fetch queue", pMsg); - code = taosWriteQitem(pVnode->pFetchQ, pMsg); + taosWriteQitem(pVnode->pFetchQ, pMsg); break; case APPLY_QUEUE: dTrace("msg:%p, will be put into vnode-apply queue", pMsg); - code = taosWriteQitem(pVnode->pApplyQ, pMsg); + taosWriteQitem(pVnode->pApplyQ, pMsg); break; case MERGE_QUEUE: dTrace("msg:%p, will be put into vnode-merge queue", pMsg); - code = taosWriteQitem(pVnode->pMergeQ, pMsg); + taosWriteQitem(pVnode->pMergeQ, pMsg); break; default: + code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index b01e1ea1da..3c3a8460b9 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -146,7 +146,7 @@ void taosFreeQitem(void *pItem) { taosMemoryFree(temp); } -int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { +void taosWriteQitem(STaosQueue *queue, void *pItem) { STaosQnode *pNode = (STaosQnode *)(((char *)pItem) - sizeof(STaosQnode)); pNode->next = NULL; @@ -167,8 +167,6 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { taosThreadMutexUnlock(&queue->mutex); if (queue->qset) tsem_post(&queue->qset->sem); - - return 0; } int32_t taosReadQitem(STaosQueue *queue, void **ppItem) { From 71fabef903bdfb7c34357b34620dc9036b3991ff Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 17:30:32 +0800 Subject: [PATCH 139/149] stream add shuffle dispatcher --- source/libs/stream/src/tstream.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index eb4cd2f97d..220f83bb3e 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -37,7 +37,8 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* req.taskId = pTask->fixedEpDispatcher.taskId; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { int32_t nodeId = 0; - char ctbName[TSDB_TABLE_FNAME_LEN]; + // TODO fix tbname issue + char ctbName[TSDB_TABLE_FNAME_LEN + 22]; // all groupId must be the same in an array SSDataBlock* pBlock = taosArrayGet(data, 0); sprintf(ctbName, "%s:%ld", pTask->shuffleDispatcher.stbFullName, pBlock->info.groupId); From f9d643241f64ca13585cd23d5240d0c216263874 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 17:37:42 +0800 Subject: [PATCH 140/149] TD-14351 incorrect ntables value in show databases results --- source/dnode/mnode/impl/src/mndDb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 05c7d79a1a..9521de818e 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1513,6 +1513,14 @@ static void setInformationSchemaDbCfg(SDbObj* pDbObj) { pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } +static bool mndGetTablesOfDbFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { + SVgObj *pVgroup = pObj; + int32_t *numOfTables = p1; + + *numOfTables += pVgroup->numOfTables; + return true; +} + static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rowsCapacity) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; @@ -1525,7 +1533,10 @@ static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 break; } - dumpDbInfoToPayload(data, pDb, pShow, numOfRows, rowsCapacity, 0); + int32_t numOfTables = 0; + sdbTraverse(pSdb, SDB_VGROUP, mndGetTablesOfDbFp, &numOfTables, NULL, NULL); + + dumpDbInfoToPayload(data, pDb, pShow, numOfRows, rowsCapacity, numOfTables); numOfRows++; sdbRelease(pSdb, pDb); } From 58272b6d410403d200fbba1c589135c5444e66c4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 17:57:12 +0800 Subject: [PATCH 141/149] TD-14352 faileure while execute create database if not exists group_db0 keep 36500 --- include/util/tdef.h | 4 ++++ source/dnode/mnode/impl/src/mndDb.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index 6c5208ec00..ea77fd0f1a 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -369,6 +369,10 @@ typedef enum ELogicConditionType { #define TSDB_MAX_DB_CACHE_LAST_ROW 3 #define TSDB_DEFAULT_CACHE_LAST_ROW 0 +#define TSDB_MIN_DB_STREAM_MODE 0 +#define TSDB_MAX_DB_STREAM_MODE 1 +#define TSDB_DEFAULT_DB_STREAM_MODE 0 + #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 9521de818e..d3a73418f3 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -276,6 +276,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->quorum > pCfg->replications) return -1; if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1; if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; + if (pCfg->cacheLastRow < TSDB_MIN_DB_STREAM_MODE || pCfg->cacheLastRow > TSDB_MAX_DB_STREAM_MODE) return -1; return TSDB_CODE_SUCCESS; } @@ -285,8 +286,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS; if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = TSDB_DEFAULT_KEEP; - if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = TSDB_DEFAULT_KEEP; - if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = TSDB_DEFAULT_KEEP; + if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep0; + if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep1; if (pCfg->minRows < 0) pCfg->minRows = TSDB_DEFAULT_MIN_ROW_FBLOCK; if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAX_ROW_FBLOCK; if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME; @@ -298,6 +299,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->quorum < 0) pCfg->quorum = TSDB_DEFAULT_DB_QUORUM_OPTION; if (pCfg->update < 0) pCfg->update = TSDB_DEFAULT_DB_UPDATE_OPTION; if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; + if (pCfg->streamMode < 0) pCfg->streamMode = TSDB_DEFAULT_DB_STREAM_MODE; + if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; } static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) { @@ -431,11 +434,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate .daysToKeep2 = pCreate->daysToKeep2, .minRows = pCreate->minRows, .maxRows = pCreate->maxRows, - .fsyncPeriod = pCreate->fsyncPeriod, .commitTime = pCreate->commitTime, + .fsyncPeriod = pCreate->fsyncPeriod, + .walLevel = pCreate->walLevel, .precision = pCreate->precision, .compression = pCreate->compression, - .walLevel = pCreate->walLevel, .replications = pCreate->replications, .quorum = pCreate->quorum, .update = pCreate->update, @@ -445,7 +448,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate dbObj.cfg.numOfRetensions = pCreate->numOfRetensions; dbObj.cfg.pRetensions = pCreate->pRetensions; - pCreate = NULL; + pCreate->pRetensions = NULL; mndSetDefaultDbCfg(&dbObj.cfg); From d2a2427738ab20979a05f0c3278f363a93144e62 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 28 Mar 2022 17:58:55 +0800 Subject: [PATCH 142/149] block-wise SMA adaption --- include/common/tdataformat.h | 32 +++++++------- include/common/ttypes.h | 1 + source/common/src/tdataformat.c | 7 ++- source/dnode/vnode/src/inc/tsdbReadImpl.h | 21 +++++---- source/dnode/vnode/src/tsdb/tsdbCommit.c | 50 +++++++++++++--------- source/dnode/vnode/src/tsdb/tsdbReadImpl.c | 2 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 9 +++- 7 files changed, 69 insertions(+), 53 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index a2899ead8e..4a3ce2db86 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -63,7 +63,7 @@ extern "C" { typedef struct { col_id_t colId; // column ID(start from PRIMARYKEY_TIMESTAMP_COL_ID(1)) int32_t type : 8; // column type - int32_t bytes : 24; // column bytes (restore to int32_t in case of misuse) + int32_t bytes : 24; // column bytes (0~16M) int32_t sma : 8; // block SMA: 0, no SMA, 1, sum/min/max, 2, ... int32_t offset : 24; // point offset in STpRow after the header part. } STColumn; @@ -81,12 +81,12 @@ typedef struct { // ----------------- TSDB SCHEMA DEFINITION typedef struct { - int32_t version; // version - int32_t numOfCols; // Number of columns appended - int32_t tlen; // maximum length of a STpRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + - // (bytes)) - uint16_t flen; // First part length in a STpRow after the header part - uint16_t vlen; // pure value part length, excluded the overhead (bytes only) + int32_t numOfCols; // Number of columns appended + schema_ver_t version; // schema version + uint16_t flen; // First part length in a STpRow after the header part + int32_t vlen; // pure value part length, excluded the overhead (bytes only) + int32_t tlen; // maximum length of a STpRow without the header part + // (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + (bytes)) STColumn columns[]; } STSchema; @@ -120,13 +120,13 @@ static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { // ----------------- SCHEMA BUILDER DEFINITION typedef struct { - int32_t tCols; - int32_t nCols; - int32_t tlen; - uint16_t flen; - uint16_t vlen; - int32_t version; - STColumn *columns; + int32_t tCols; + int32_t nCols; + schema_ver_t version; + uint16_t flen; + int32_t vlen; + int32_t tlen; + STColumn *columns; } STSchemaBuilder; #define TD_VTYPE_BITS 2 // val type @@ -136,9 +136,9 @@ typedef struct { #define TD_BITMAP_BYTES(cnt) (ceil((double)cnt / TD_VTYPE_PARTS)) #define TD_BIT_TO_BYTES(cnt) (ceil((double)cnt / 8)) -int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 87dc752703..19442af206 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -30,6 +30,7 @@ typedef uint8_t TDRowValT; typedef int16_t col_id_t; typedef int8_t col_type_t; typedef int32_t col_bytes_t; +typedef uint16_t schema_ver_t; #pragma pack(push, 1) typedef struct { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1b7157c49c..7fd66e95ad 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -123,7 +123,7 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) { return buf; } -int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { +int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { if (pBuilder == NULL) return -1; pBuilder->tCols = 256; @@ -140,7 +140,7 @@ void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) { } } -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { +void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { pBuilder->nCols = 0; pBuilder->tlen = 0; pBuilder->flen = 0; @@ -168,6 +168,9 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); } + // TODO: set sma value by user input + pCol->sma = 1; + if (IS_VAR_DATA_TYPE(type)) { colSetBytes(pCol, bytes); pBuilder->tlen += (TYPE_BYTES[type] + bytes); diff --git a/source/dnode/vnode/src/inc/tsdbReadImpl.h b/source/dnode/vnode/src/inc/tsdbReadImpl.h index d25ac1d194..17c220a35a 100644 --- a/source/dnode/vnode/src/inc/tsdbReadImpl.h +++ b/source/dnode/vnode/src/inc/tsdbReadImpl.h @@ -64,25 +64,24 @@ typedef enum { #define SBlockVerLatest TSDB_SBLK_VER_0 typedef struct { - uint8_t blkVer : 4; - uint8_t algorithm : 4; uint8_t last : 1; - uint8_t numOfSubBlocks : 7; - col_id_t numOfCols; // not including timestamp column - uint32_t len; // data block length - uint64_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols - uint64_t colSpan : 8; // columns split span(0~255. 0: no split; other: +1(e.g. 63->64, 127->128, 255->256)) - uint64_t schemaVer : 16; // 0~65535 - uint64_t numOfRows : 16; // 0~65535 + uint8_t blkVer : 7; + uint8_t numOfSubBlocks; + col_id_t numOfCols; // not including timestamp column + uint32_t len; // data block length + uint32_t keyLen : 20; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + uint32_t algorithm : 4; + uint32_t reserve : 8; + col_id_t numOfBSma; + uint16_t numOfRows; int64_t offset; uint64_t aggrStat : 1; uint64_t aggrOffset : 63; - uint64_t reserve; // TODO: use compact mode or reserve for future use? TSKEY keyFirst; TSKEY keyLast; } SBlockV0; -#define SBlock SBlockV0 // latest SBlock definition +#define SBlock SBlockV0 // latest SBlock definition #endif diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index eb8df61051..3e0b03f331 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -43,20 +43,20 @@ typedef struct { #define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5) -#define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) -#define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) -#define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) -#define TSDB_COMMIT_TABLE(ch) ((ch)->pTable) -#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD) -#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA) -#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) -#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD) -#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL) -#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) -#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) -#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) +#define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) +#define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) +#define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) +#define TSDB_COMMIT_TABLE(ch) ((ch)->pTable) +#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD) +#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA) +#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST) +#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD) +#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL) +#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) +#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) +#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) #define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock) -#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) +#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) static void tsdbStartCommit(STsdb *pRepo); static void tsdbEndCommit(STsdb *pTsdb, int eno); @@ -1204,9 +1204,10 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) { int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDFileAggr, SDataCols *pDataCols, SBlock *pBlock, bool isLast, bool isSuper, void **ppBuf, void **ppCBuf, void **ppExBuf) { - STsdbCfg * pCfg = REPO_CFG(pRepo); - SBlockData * pBlockData = NULL; + STsdbCfg *pCfg = REPO_CFG(pRepo); + SBlockData *pBlockData = NULL; SAggrBlkData *pAggrBlkData = NULL; + STSchema *pSchema = pTable->pSchema; int64_t offset = 0, offsetAggr = 0; int rowsToWrite = pDataCols->numOfRows; @@ -1225,10 +1226,12 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF pAggrBlkData = (SAggrBlkData *)(*ppExBuf); // Get # of cols not all NULL(not including key column) - int nColsNotAllNull = 0; + col_id_t nColsNotAllNull = 0; + col_id_t nColsOfBlockSma = 0; for (int ncol = 1; ncol < pDataCols->numOfCols; ++ncol) { // ncol from 1, we skip the timestamp column - SDataCol * pDataCol = pDataCols->cols + ncol; - SBlockCol * pBlockCol = pBlockData->cols + nColsNotAllNull; + STColumn *pColumn = pSchema->columns + ncol; + SDataCol *pDataCol = pDataCols->cols + ncol; + SBlockCol *pBlockCol = pBlockData->cols + nColsNotAllNull; SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsNotAllNull; if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it @@ -1260,7 +1263,12 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF } else { TD_SET_COL_ROWS_MISC(pBlockCol); } - nColsNotAllNull++; + + ++nColsNotAllNull; + + if (pColumn->sma) { + ++nColsOfBlockSma; + } } ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols); @@ -1357,9 +1365,8 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF return -1; } - uint32_t aggrStatus = nColsNotAllNull > 0 ? 1 : 0; + uint32_t aggrStatus = nColsOfBlockSma > 0 ? 1 : 0; if (aggrStatus > 0) { - taosCalcChecksumAppend(0, (uint8_t *)pAggrBlkData, tsizeAggr); tsdbUpdateDFileMagic(pDFileAggr, POINTER_SHIFT(pAggrBlkData, tsizeAggr - sizeof(TSCKSUM))); @@ -1378,6 +1385,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF pBlock->keyLen = keyLen; pBlock->numOfSubBlocks = isSuper ? 1 : 0; pBlock->numOfCols = nColsNotAllNull; + pBlock->numOfBSma = nColsOfBlockSma; pBlock->keyFirst = dataColsKeyFirst(pDataCols); pBlock->keyLast = dataColsKeyLast(pDataCols); pBlock->aggrStat = aggrStatus; diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 9619ac036e..304b3286fe 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -321,7 +321,7 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) { return -1; } - size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer); + size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfBSma, (uint32_t)pBlock->blkVer); if (tsdbMakeRoom((void **)(&(pReadh->pAggrBlkData)), sizeAggr) < 0) return -1; int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr); diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 29a4b7f552..d010ea4437 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -330,7 +330,6 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0); // step 2: insert data - STSmaDataWrapper *pSmaData = NULL; STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb)); STsdbCfg *pCfg = &pTsdb->config; @@ -416,6 +415,8 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { col_id_t numOfCols = 4096; ASSERT_GT(numOfCols, 0); +#if 0 + STSmaDataWrapper *pSmaData = NULL; pSmaData = (STSmaDataWrapper *)buf; printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData); pSmaData->skey = skey1; @@ -459,9 +460,13 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { pSmaData->dataLen = (len - sizeof(STSmaDataWrapper)); ASSERT_GE(bufSize, pSmaData->dataLen); - // execute ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS); +#endif + + SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); + + // step 3: query uint32_t checkDataCnt = 0; From 46d56e5778b171cfdae1caa55167d63ef171e03e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 18:17:10 +0800 Subject: [PATCH 143/149] adjust log --- source/dnode/mgmt/container/src/dndExec.c | 10 +++++----- source/dnode/mgmt/mnode/src/mmWorker.c | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index 94c996280f..8ffa53f034 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -119,14 +119,14 @@ static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t msgLen, void *pCont, int32_t contLen) { SRpcMsg *pRpc = &pMsg->rpcMsg; pRpc->pCont = pCont; - dTrace("msg:%p, get from child queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType), pRpc->handle, - pRpc->ahandle); + dTrace("msg:%p, get from child process queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType), + pRpc->handle, pRpc->ahandle); NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; int32_t code = (*msgFp)(pWrapper, pMsg); - dTrace("msg:%p, is processed, code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (code != 0) { + dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (pRpc->msgType & 1U) { SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; dndSendRsp(pWrapper, &rsp); @@ -140,8 +140,8 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, int32_t msgLen, void *pCont, int32_t contLen) { pRpc->pCont = pCont; - dTrace("msg:%p, get from parent queue, type:%s handle:%p app:%p", pRpc, TMSG_INFO(pRpc->msgType), pRpc->handle, - pRpc->ahandle); + dTrace("msg:%p, get from parent process queue, type:%s handle:%p app:%p", pRpc, TMSG_INFO(pRpc->msgType), + pRpc->handle, pRpc->ahandle); dndSendRsp(pWrapper, pRpc); taosMemoryFree(pRpc); diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mnode/src/mmWorker.c index 0897951fe3..e8d20457c4 100644 --- a/source/dnode/mgmt/mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mnode/src/mmWorker.c @@ -19,7 +19,7 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; - dTrace("msg:%p, will be processed in mnode queue", pMsg); + dTrace("msg:%p, get from mnode queue", pMsg); SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; @@ -31,9 +31,9 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } if (pRpc->msgType & 1U) { - if (pRpc->handle == NULL) return; - if (code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0) code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; dndSendRsp(pMgmt->pWrapper, &rsp); } @@ -47,7 +47,7 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; - dTrace("msg:%p, will be processed in mnode queue", pMsg); + dTrace("msg:%p, get from mnode query queue", pMsg); SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; @@ -55,8 +55,8 @@ static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { code = mndProcessMsg(pMsg); if (pRpc->msgType & 1U) { - if (pRpc->handle == NULL) return; - if (code != 0) { + if (pRpc->handle != NULL && code != 0) { + dError("msg:%p, failed to process since %s", pMsg, terrstr()); SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .ahandle = pRpc->ahandle}; dndSendRsp(pMgmt->pWrapper, &rsp); } From 187eb2999814c25831b17ae0290f53c08b4a518f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Mar 2022 18:28:24 +0800 Subject: [PATCH 144/149] fix ci --- source/dnode/mgmt/mnode/src/mmWorker.c | 6 ++++-- source/dnode/mnode/impl/src/mndDb.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/dnode/mgmt/mnode/src/mmWorker.c b/source/dnode/mgmt/mnode/src/mmWorker.c index e8d20457c4..c4aafe05e4 100644 --- a/source/dnode/mgmt/mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mnode/src/mmWorker.c @@ -32,8 +32,10 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { if (pRpc->msgType & 1U) { if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); + if (code != 0) { + code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); + } SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; dndSendRsp(pMgmt->pWrapper, &rsp); } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 00301969f9..bd66bdeae9 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -276,7 +276,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->quorum > pCfg->replications) return -1; if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1; if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; - if (pCfg->cacheLastRow < TSDB_MIN_DB_STREAM_MODE || pCfg->cacheLastRow > TSDB_MAX_DB_STREAM_MODE) return -1; + if (pCfg->streamMode < TSDB_MIN_DB_STREAM_MODE || pCfg->streamMode > TSDB_MAX_DB_STREAM_MODE) return -1; return TSDB_CODE_SUCCESS; } From 122dda07f7f421c1f63e38d5becc35971cb83e9f Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 28 Mar 2022 19:12:23 +0800 Subject: [PATCH 145/149] trigger CI From a0ef66528c8808972cba6178baeb22468933cd80 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Mon, 28 Mar 2022 07:26:06 -0400 Subject: [PATCH 146/149] sort bugfix, and pseudo column implement --- include/common/ttokendef.h | 86 +- include/libs/function/functionMgt.h | 13 +- source/libs/function/inc/builtins.h | 2 + source/libs/function/src/builtins.c | 77 + source/libs/function/src/functionMgt.c | 24 +- source/libs/parser/inc/sql.y | 36 +- source/libs/parser/src/parTokenizer.c | 12 +- source/libs/parser/src/sql.c | 3259 ++++++++++---------- source/libs/parser/test/parserAstTest.cpp | 7 + source/libs/planner/src/planLogicCreater.c | 2 +- source/libs/planner/src/planPhysiCreater.c | 13 +- source/libs/planner/test/plannerTest.cpp | 3 + 12 files changed, 1878 insertions(+), 1656 deletions(-) diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 51dd645a30..c5904904ab 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -140,45 +140,53 @@ #define TK_AS 122 #define TK_NK_BOOL 123 #define TK_NK_VARIABLE 124 -#define TK_BETWEEN 125 -#define TK_IS 126 -#define TK_NULL 127 -#define TK_NK_LT 128 -#define TK_NK_GT 129 -#define TK_NK_LE 130 -#define TK_NK_GE 131 -#define TK_NK_NE 132 -#define TK_MATCH 133 -#define TK_NMATCH 134 -#define TK_IN 135 -#define TK_JOIN 136 -#define TK_INNER 137 -#define TK_SELECT 138 -#define TK_DISTINCT 139 -#define TK_WHERE 140 -#define TK_PARTITION 141 -#define TK_BY 142 -#define TK_SESSION 143 -#define TK_STATE_WINDOW 144 -#define TK_SLIDING 145 -#define TK_FILL 146 -#define TK_VALUE 147 -#define TK_NONE 148 -#define TK_PREV 149 -#define TK_LINEAR 150 -#define TK_NEXT 151 -#define TK_GROUP 152 -#define TK_HAVING 153 -#define TK_ORDER 154 -#define TK_SLIMIT 155 -#define TK_SOFFSET 156 -#define TK_LIMIT 157 -#define TK_OFFSET 158 -#define TK_ASC 159 -#define TK_DESC 160 -#define TK_NULLS 161 -#define TK_FIRST 162 -#define TK_LAST 163 +#define TK_NK_UNDERLINE 125 +#define TK_ROWTS 126 +#define TK_TBNAME 127 +#define TK_QSTARTTS 128 +#define TK_QENDTS 129 +#define TK_WSTARTTS 130 +#define TK_WENDTS 131 +#define TK_WDURATION 132 +#define TK_BETWEEN 133 +#define TK_IS 134 +#define TK_NULL 135 +#define TK_NK_LT 136 +#define TK_NK_GT 137 +#define TK_NK_LE 138 +#define TK_NK_GE 139 +#define TK_NK_NE 140 +#define TK_MATCH 141 +#define TK_NMATCH 142 +#define TK_IN 143 +#define TK_JOIN 144 +#define TK_INNER 145 +#define TK_SELECT 146 +#define TK_DISTINCT 147 +#define TK_WHERE 148 +#define TK_PARTITION 149 +#define TK_BY 150 +#define TK_SESSION 151 +#define TK_STATE_WINDOW 152 +#define TK_SLIDING 153 +#define TK_FILL 154 +#define TK_VALUE 155 +#define TK_NONE 156 +#define TK_PREV 157 +#define TK_LINEAR 158 +#define TK_NEXT 159 +#define TK_GROUP 160 +#define TK_HAVING 161 +#define TK_ORDER 162 +#define TK_SLIMIT 163 +#define TK_SOFFSET 164 +#define TK_LIMIT 165 +#define TK_OFFSET 166 +#define TK_ASC 167 +#define TK_DESC 168 +#define TK_NULLS 169 +#define TK_FIRST 170 +#define TK_LAST 171 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 85a9cd0b23..66887f5e87 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -96,7 +96,16 @@ typedef enum EFunctionType { FUNCTION_TYPE_SERVER_SERSION, FUNCTION_TYPE_SERVER_STATUS, FUNCTION_TYPE_CURRENT_USER, - FUNCTION_TYPE_USER + FUNCTION_TYPE_USER, + + // pseudo column function + FUNCTION_TYPE_ROWTS = 3500, + FUNCTION_TYPE_TBNAME, + FUNCTION_TYPE_QSTARTTS, + FUNCTION_TYPE_QENDTS, + FUNCTION_TYPE_WSTARTTS, + FUNCTION_TYPE_WENDTS, + FUNCTION_TYPE_WDURATION } EFunctionType; struct SqlFunctionCtx; @@ -125,6 +134,8 @@ bool fmIsStringFunc(int32_t funcId); bool fmIsDatetimeFunc(int32_t funcId); bool fmIsTimelineFunc(int32_t funcId); bool fmIsTimeorderFunc(int32_t funcId); +bool fmIsWindowPseudoColumnFunc(int32_t funcId); +bool fmIsWindowClauseFunc(int32_t funcId); int32_t fmFuncScanType(int32_t funcId); diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index 598a28b2eb..2c0148e04f 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -33,6 +33,8 @@ extern "C" { #define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) #define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) #define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) +#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) +#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 70b2a48da7..08078e0561 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -291,6 +291,76 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = NULL, .sprocessFunc = NULL, .finalizeFunc = NULL + }, + { + .name = "_rowts", + .type = FUNCTION_TYPE_ROWTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "tbname", + .type = FUNCTION_TYPE_TBNAME, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_qstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_qendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_wduration", + .type = FUNCTION_TYPE_WDURATION, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL } }; @@ -329,6 +399,13 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { break; } case FUNCTION_TYPE_CONCAT: + case FUNCTION_TYPE_ROWTS: + case FUNCTION_TYPE_TBNAME: + case FUNCTION_TYPE_QSTARTTS: + case FUNCTION_TYPE_QENDTS: + case FUNCTION_TYPE_WSTARTTS: + case FUNCTION_TYPE_WENDTS: + case FUNCTION_TYPE_WDURATION: // todo break; default: diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 10ac8bbf43..3858258374 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -44,6 +44,13 @@ static void doInitFunctionHashTable() { } } +static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification); +} + int32_t fmFuncMgtInit() { taosThreadOnce(&functionHashTableInit, doInitFunctionHashTable); return initFunctionCode; @@ -89,10 +96,19 @@ int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) { } bool fmIsAggFunc(int32_t funcId) { - if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { - return false; - } - return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, FUNC_MGT_AGG_FUNC); + return isSpecificClassifyFunc(funcId, FUNC_MGT_AGG_FUNC); +} + +bool fmIsScalarFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); +} + +bool fmIsWindowPseudoColumnFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_WINDOW_PC_FUNC); +} + +bool fmIsWindowClauseFunc(int32_t funcId) { + return fmIsAggFunc(funcId) || fmIsWindowPseudoColumnFunc(funcId); } void fmFuncMgtDestroy() { diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 8f07d66a62..951fba0052 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -15,6 +15,7 @@ #include #include +#include "functionMgt.h" #include "nodes.h" #include "parToken.h" #include "ttokendef.h" @@ -417,7 +418,7 @@ topic_name(A) ::= NK_ID(B). /************************************************ expression **********************************************************/ expression(A) ::= literal(B). { A = B; } //expression(A) ::= NK_QUESTION(B). { A = B; } -//expression(A) ::= pseudo_column(B). { A = B; } +expression(A) ::= pseudo_column(B). { A = B; } expression(A) ::= column_reference(B). { A = B; } expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); } @@ -467,7 +468,38 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C). column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); } column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); } -//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); } +//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); } +pseudo_column(A) ::= NK_UNDERLINE(B) ROWTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= NK_UNDERLINE(B) QSTARTTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) QENDTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WSTARTTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WENDTS(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } +pseudo_column(A) ::= NK_UNDERLINE(B) WDURATION(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); + } /************************************************ predicate ***********************************************************/ predicate(A) ::= expression(B) compare_op(C) expression(D). { diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 766e606823..adf5523db3 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -104,12 +104,15 @@ static SKeyword keywordTable[] = { {"PRECISION", TK_PRECISION}, {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, + {"QENDTS", TK_QENDTS}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, + {"QSTARTTS", TK_QSTARTTS}, {"QUORUM", TK_QUORUM}, {"REPLICA", TK_REPLICA}, {"RETENTIONS", TK_RETENTIONS}, {"ROLLUP", TK_ROLLUP}, + {"ROWTS", TK_ROWTS}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, {"SHOW", TK_SHOW}, @@ -127,6 +130,7 @@ static SKeyword keywordTable[] = { {"TABLE", TK_TABLE}, {"TABLES", TK_TABLES}, {"TAGS", TK_TAGS}, + {"TBNAME", TK_TBNAME}, {"TIMESTAMP", TK_TIMESTAMP}, {"TINYINT", TK_TINYINT}, {"TOPIC", TK_TOPIC}, @@ -141,7 +145,10 @@ static SKeyword keywordTable[] = { {"VARCHAR", TK_VARCHAR}, {"VGROUPS", TK_VGROUPS}, {"WAL", TK_WAL}, + {"WDURATION", TK_WDURATION}, + {"WENDTS", TK_WENDTS}, {"WHERE", TK_WHERE}, + {"WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, // {"STRING", TK_STRING}, // {"EQ", TK_EQ}, @@ -233,7 +240,6 @@ static SKeyword keywordTable[] = { // {"TRIGGER", TK_TRIGGER}, // {"VIEW", TK_VIEW}, // {"SEMI", TK_SEMI}, - // {"TBNAME", TK_TBNAME}, // {"VNODES", TK_VNODES}, // {"PARTITIONS", TK_PARTITIONS}, // {"TOPICS", TK_TOPICS}, @@ -427,6 +433,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { *tokenId = TK_NK_QUESTION; return 1; } + case '_': { + *tokenId = TK_NK_UNDERLINE; + return 1; + } case '`': case '\'': case '"': { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index b64eaee628..fcc47d53fb 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -32,6 +32,7 @@ #include #include +#include "functionMgt.h" #include "nodes.h" #include "parToken.h" #include "ttokendef.h" @@ -99,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 259 +#define YYNOCODE 268 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SAlterOption yy11; - ENullOrder yy151; - EJoinType yy162; - SToken yy183; - bool yy215; - EOperatorType yy366; - SNode* yy378; - int32_t yy396; - EOrder yy400; - SNodeList* yy404; - EFillMode yy466; - SDataType yy504; + EOrder yy106; + EFillMode yy142; + SNode* yy176; + SToken yy225; + EJoinType yy236; + SAlterOption yy325; + EOperatorType yy404; + SDataType yy448; + ENullOrder yy465; + bool yy505; + int32_t yy508; + SNodeList* yy512; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 431 -#define YYNRULE 338 -#define YYNTOKEN 164 -#define YY_MAX_SHIFT 430 -#define YY_MIN_SHIFTREDUCE 664 -#define YY_MAX_SHIFTREDUCE 1001 -#define YY_ERROR_ACTION 1002 -#define YY_ACCEPT_ACTION 1003 -#define YY_NO_ACTION 1004 -#define YY_MIN_REDUCE 1005 -#define YY_MAX_REDUCE 1342 +#define YYNSTATE 432 +#define YYNRULE 346 +#define YYNTOKEN 172 +#define YY_MAX_SHIFT 431 +#define YY_MIN_SHIFTREDUCE 673 +#define YY_MAX_SHIFTREDUCE 1018 +#define YY_ERROR_ACTION 1019 +#define YY_ACCEPT_ACTION 1020 +#define YY_NO_ACTION 1021 +#define YY_MIN_REDUCE 1022 +#define YY_MAX_REDUCE 1367 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,393 +209,407 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1230) +#define YY_ACTTAB_COUNT (1291) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1235, 1220, 225, 1208, 1220, 349, 242, 346, 237, 1204, - /* 10 */ 1210, 1184, 31, 29, 27, 26, 25, 1097, 105, 1208, - /* 20 */ 1017, 1235, 362, 1208, 1235, 1204, 1209, 66, 346, 1204, - /* 30 */ 1209, 346, 320, 1235, 279, 361, 24, 170, 348, 362, - /* 40 */ 346, 348, 1196, 1108, 66, 1196, 361, 211, 1048, 250, - /* 50 */ 334, 285, 107, 1221, 1224, 61, 1221, 1224, 1260, 362, - /* 60 */ 1108, 194, 210, 1256, 269, 323, 196, 349, 283, 884, - /* 70 */ 109, 362, 282, 1185, 1321, 209, 1105, 907, 195, 43, - /* 80 */ 1108, 1148, 31, 29, 27, 26, 25, 117, 123, 335, - /* 90 */ 1334, 1319, 1108, 284, 10, 1099, 1104, 415, 414, 413, - /* 100 */ 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, - /* 110 */ 402, 401, 400, 399, 398, 270, 908, 211, 31, 29, - /* 120 */ 27, 26, 25, 9, 8, 23, 232, 1006, 902, 903, - /* 130 */ 904, 905, 906, 910, 911, 912, 1196, 27, 26, 25, - /* 140 */ 31, 29, 27, 26, 25, 1003, 1028, 907, 78, 64, - /* 150 */ 870, 77, 76, 75, 74, 73, 72, 71, 70, 69, - /* 160 */ 319, 773, 385, 384, 383, 777, 382, 779, 780, 381, - /* 170 */ 782, 378, 1274, 788, 375, 790, 791, 372, 369, 872, - /* 180 */ 291, 118, 286, 325, 321, 290, 908, 1196, 289, 1271, - /* 190 */ 287, 920, 1220, 288, 249, 23, 232, 884, 902, 903, - /* 200 */ 904, 905, 906, 910, 911, 912, 31, 29, 27, 26, - /* 210 */ 25, 324, 1235, 106, 1075, 423, 422, 78, 1321, 333, - /* 220 */ 77, 76, 75, 74, 73, 72, 71, 70, 69, 348, - /* 230 */ 43, 117, 238, 1196, 968, 1319, 1321, 218, 118, 89, - /* 240 */ 104, 874, 1220, 62, 1221, 1224, 1260, 1103, 1110, 1320, - /* 250 */ 227, 1256, 112, 1319, 316, 966, 967, 969, 970, 283, - /* 260 */ 875, 330, 1235, 282, 166, 997, 998, 870, 118, 333, - /* 270 */ 312, 1287, 1220, 219, 251, 217, 216, 263, 281, 348, - /* 280 */ 245, 244, 92, 1196, 284, 362, 264, 1175, 1177, 104, - /* 290 */ 359, 1172, 1235, 62, 1221, 1224, 1260, 1110, 120, 346, - /* 300 */ 227, 1256, 112, 1279, 939, 361, 1108, 362, 90, 348, - /* 310 */ 1027, 700, 360, 1196, 701, 1220, 700, 332, 113, 1267, - /* 320 */ 1268, 1288, 1272, 62, 1221, 1224, 1260, 277, 1108, 330, - /* 330 */ 227, 1256, 1333, 6, 702, 1235, 1026, 30, 28, 241, - /* 340 */ 240, 1294, 346, 165, 1220, 234, 258, 852, 873, 864, - /* 350 */ 92, 1196, 348, 10, 262, 397, 1196, 257, 256, 255, - /* 360 */ 254, 253, 151, 850, 1235, 857, 62, 1221, 1224, 1260, - /* 370 */ 909, 346, 12, 227, 1256, 1333, 90, 1196, 362, 21, - /* 380 */ 1086, 348, 871, 184, 1317, 1196, 114, 1267, 1268, 913, - /* 390 */ 1272, 122, 121, 1, 1155, 62, 1221, 1224, 1260, 1108, - /* 400 */ 224, 1220, 227, 1256, 1333, 1153, 30, 28, 944, 1084, - /* 410 */ 30, 28, 189, 1278, 234, 1138, 852, 427, 234, 363, - /* 420 */ 852, 1235, 943, 118, 9, 8, 270, 939, 346, 851, - /* 430 */ 305, 860, 850, 1155, 951, 1025, 850, 1024, 348, 239, - /* 440 */ 872, 12, 1196, 1085, 1153, 12, 20, 334, 853, 856, - /* 450 */ 865, 856, 201, 1221, 1224, 397, 31, 29, 27, 26, - /* 460 */ 25, 104, 1, 118, 1023, 247, 1, 30, 28, 1111, - /* 470 */ 306, 1321, 1083, 104, 1155, 234, 1196, 852, 1196, 59, - /* 480 */ 246, 1110, 1274, 1220, 117, 1153, 427, 362, 1319, 93, - /* 490 */ 427, 388, 248, 850, 1321, 1155, 1100, 1022, 851, 1270, - /* 500 */ 394, 345, 851, 1235, 393, 1196, 1176, 117, 1108, 337, - /* 510 */ 346, 1319, 1220, 52, 1021, 1020, 1076, 853, 856, 1093, - /* 520 */ 348, 853, 856, 7, 1196, 395, 1019, 1016, 1015, 394, - /* 530 */ 1101, 1014, 1235, 393, 63, 1221, 1224, 1260, 1196, 346, - /* 540 */ 330, 1259, 1256, 1095, 392, 391, 390, 427, 389, 348, - /* 550 */ 30, 28, 347, 1196, 395, 1196, 1196, 942, 234, 851, - /* 560 */ 852, 92, 1013, 63, 1221, 1224, 1260, 1196, 1196, 1196, - /* 570 */ 344, 1256, 1196, 392, 391, 390, 850, 389, 853, 856, - /* 580 */ 334, 899, 1220, 308, 30, 28, 1012, 90, 1011, 1091, - /* 590 */ 1274, 1010, 234, 118, 852, 98, 1009, 163, 1267, 329, - /* 600 */ 852, 328, 1235, 1196, 1321, 1008, 7, 1269, 137, 346, - /* 610 */ 850, 135, 30, 28, 1155, 139, 850, 117, 138, 348, - /* 620 */ 234, 1319, 852, 1196, 1005, 1154, 303, 1196, 141, 1196, - /* 630 */ 427, 140, 1196, 63, 1221, 1224, 1260, 1196, 850, 301, - /* 640 */ 7, 1257, 851, 1044, 1000, 1001, 1196, 1039, 87, 86, - /* 650 */ 85, 84, 83, 82, 81, 80, 79, 1037, 430, 387, - /* 660 */ 336, 853, 856, 58, 427, 292, 1220, 341, 1, 294, - /* 670 */ 427, 143, 187, 54, 142, 88, 851, 965, 156, 297, - /* 680 */ 859, 419, 851, 186, 338, 1220, 1235, 914, 881, 41, - /* 690 */ 154, 1018, 427, 346, 167, 853, 856, 317, 1149, 32, - /* 700 */ 32, 853, 856, 348, 851, 1235, 60, 1196, 1214, 182, - /* 710 */ 233, 160, 346, 845, 276, 1220, 858, 205, 1221, 1224, - /* 720 */ 1212, 1220, 348, 853, 856, 32, 1196, 175, 1290, 313, - /* 730 */ 331, 354, 330, 1236, 1220, 1235, 205, 1221, 1224, 173, - /* 740 */ 358, 1235, 346, 95, 342, 169, 862, 2, 346, 870, - /* 750 */ 1174, 181, 348, 92, 1235, 252, 1196, 311, 348, 339, - /* 760 */ 147, 346, 1196, 96, 260, 766, 204, 1221, 1224, 761, - /* 770 */ 259, 348, 107, 1221, 1224, 1196, 119, 98, 231, 90, - /* 780 */ 1220, 41, 861, 794, 261, 205, 1221, 1224, 1220, 115, - /* 790 */ 1267, 1268, 22, 1272, 878, 367, 265, 326, 267, 798, - /* 800 */ 1235, 804, 31, 29, 27, 26, 25, 346, 1235, 266, - /* 810 */ 1335, 96, 124, 97, 803, 346, 1220, 348, 99, 877, - /* 820 */ 268, 1196, 1220, 271, 235, 348, 98, 127, 42, 1196, - /* 830 */ 96, 205, 1221, 1224, 130, 876, 1235, 278, 280, 203, - /* 840 */ 1221, 1224, 1235, 346, 1220, 68, 307, 1098, 223, 346, - /* 850 */ 134, 1094, 136, 348, 100, 146, 101, 1196, 1096, 348, - /* 860 */ 1092, 102, 103, 1196, 1235, 149, 875, 206, 1221, 1224, - /* 870 */ 309, 346, 1220, 199, 1221, 1224, 1301, 318, 1220, 352, - /* 880 */ 856, 348, 1300, 1291, 159, 1196, 310, 314, 5, 152, - /* 890 */ 1281, 1220, 1235, 315, 226, 207, 1221, 1224, 1235, 346, - /* 900 */ 155, 4, 322, 327, 939, 346, 91, 874, 33, 348, - /* 910 */ 161, 1235, 162, 1196, 1275, 348, 228, 343, 346, 1196, - /* 920 */ 1220, 340, 17, 200, 1221, 1224, 1220, 1242, 348, 208, - /* 930 */ 1221, 1224, 1196, 110, 1183, 350, 351, 355, 177, 1220, - /* 940 */ 1235, 1318, 1232, 1221, 1224, 1336, 1235, 346, 1220, 168, - /* 950 */ 1182, 236, 357, 346, 356, 179, 188, 348, 51, 1235, - /* 960 */ 53, 1196, 1109, 348, 1051, 365, 346, 1196, 1235, 190, - /* 970 */ 185, 1231, 1221, 1224, 426, 346, 348, 1230, 1221, 1224, - /* 980 */ 1196, 197, 198, 1220, 192, 348, 193, 1190, 828, 1196, - /* 990 */ 214, 1221, 1224, 132, 1167, 1166, 111, 94, 1165, 213, - /* 1000 */ 1221, 1224, 275, 1235, 131, 1164, 1163, 1162, 1161, 1160, - /* 1010 */ 346, 1220, 830, 291, 1159, 286, 1158, 1220, 290, 1157, - /* 1020 */ 348, 289, 1156, 287, 1196, 1050, 288, 44, 1189, 1180, - /* 1030 */ 129, 1235, 126, 1087, 215, 1221, 1224, 1235, 346, 713, - /* 1040 */ 1049, 1047, 296, 274, 346, 1036, 273, 1035, 348, 272, - /* 1050 */ 1032, 1089, 1196, 67, 348, 133, 811, 304, 1196, 810, - /* 1060 */ 1088, 809, 212, 1221, 1224, 741, 1045, 1040, 202, 1221, - /* 1070 */ 1224, 145, 740, 739, 299, 738, 220, 128, 221, 293, - /* 1080 */ 737, 125, 144, 295, 736, 1038, 222, 298, 1031, 1030, - /* 1090 */ 300, 302, 65, 1188, 1187, 36, 1179, 14, 45, 150, - /* 1100 */ 148, 3, 34, 15, 32, 40, 48, 37, 39, 11, - /* 1110 */ 8, 1212, 153, 158, 986, 985, 164, 964, 229, 990, - /* 1120 */ 108, 157, 989, 900, 958, 230, 46, 1178, 957, 47, - /* 1130 */ 1004, 866, 936, 353, 935, 1004, 1004, 1004, 1004, 1004, - /* 1140 */ 991, 178, 1046, 19, 882, 366, 1004, 13, 243, 1004, - /* 1150 */ 18, 35, 172, 116, 174, 16, 370, 373, 171, 962, - /* 1160 */ 176, 376, 1004, 49, 379, 50, 772, 800, 1034, 1033, - /* 1170 */ 806, 38, 1029, 802, 795, 792, 733, 54, 725, 368, - /* 1180 */ 1211, 183, 371, 364, 789, 374, 801, 732, 396, 783, - /* 1190 */ 377, 731, 421, 781, 711, 730, 380, 729, 55, 728, - /* 1200 */ 727, 56, 57, 726, 724, 723, 787, 786, 180, 722, - /* 1210 */ 785, 386, 721, 720, 719, 784, 718, 717, 716, 416, - /* 1220 */ 417, 420, 424, 425, 428, 418, 854, 191, 429, 805, + /* 0 */ 1225, 43, 306, 1237, 1114, 350, 1221, 1227, 238, 1110, + /* 10 */ 89, 1201, 31, 29, 27, 26, 25, 1253, 1120, 24, + /* 20 */ 170, 1346, 226, 1253, 347, 31, 29, 27, 26, 25, + /* 30 */ 347, 363, 363, 1103, 1345, 362, 66, 270, 1344, 1225, + /* 40 */ 349, 1237, 307, 280, 1213, 1221, 1226, 212, 1065, 335, + /* 50 */ 321, 362, 1125, 1125, 61, 1238, 1239, 1242, 1285, 879, + /* 60 */ 212, 1253, 211, 1281, 246, 363, 271, 1346, 347, 894, + /* 70 */ 1122, 1192, 1194, 239, 1346, 106, 1092, 924, 349, 271, + /* 80 */ 117, 104, 1213, 12, 1344, 189, 1125, 117, 1155, 1127, + /* 90 */ 924, 1344, 107, 1238, 1239, 1242, 1023, 416, 415, 414, + /* 100 */ 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, + /* 110 */ 403, 402, 401, 400, 399, 43, 925, 78, 926, 346, + /* 120 */ 77, 76, 75, 74, 73, 72, 71, 70, 69, 925, + /* 130 */ 336, 1359, 1121, 23, 233, 21, 919, 920, 921, 922, + /* 140 */ 923, 927, 928, 929, 883, 930, 23, 233, 1102, 919, + /* 150 */ 920, 921, 922, 923, 927, 928, 929, 9, 8, 1237, + /* 160 */ 362, 782, 386, 385, 384, 786, 383, 788, 789, 382, + /* 170 */ 791, 379, 309, 797, 376, 799, 800, 373, 370, 1253, + /* 180 */ 30, 28, 363, 1172, 98, 118, 334, 360, 235, 225, + /* 190 */ 861, 30, 28, 961, 1170, 105, 349, 1034, 284, 235, + /* 200 */ 1213, 861, 283, 1125, 1237, 395, 859, 916, 12, 394, + /* 210 */ 62, 1238, 1239, 1242, 1285, 11, 251, 859, 228, 1281, + /* 220 */ 112, 1253, 363, 285, 1253, 937, 11, 66, 347, 1116, + /* 230 */ 396, 334, 166, 881, 286, 52, 1, 109, 313, 1312, + /* 240 */ 219, 349, 210, 1125, 243, 1213, 165, 1, 1165, 393, + /* 250 */ 392, 391, 1118, 390, 324, 62, 1238, 1239, 1242, 1285, + /* 260 */ 428, 1225, 284, 228, 1281, 112, 283, 1221, 1226, 1172, + /* 270 */ 1213, 428, 860, 325, 1237, 240, 220, 104, 218, 217, + /* 280 */ 1170, 282, 118, 860, 1313, 1128, 118, 285, 710, 1299, + /* 290 */ 709, 862, 865, 201, 1253, 907, 31, 29, 27, 26, + /* 300 */ 25, 347, 862, 865, 201, 882, 907, 1296, 711, 1101, + /* 310 */ 1237, 349, 1045, 78, 118, 1213, 77, 76, 75, 74, + /* 320 */ 73, 72, 71, 70, 69, 62, 1238, 1239, 1242, 1285, + /* 330 */ 1253, 424, 423, 228, 1281, 1358, 363, 347, 245, 350, + /* 340 */ 1237, 361, 30, 28, 1319, 1202, 104, 349, 30, 28, + /* 350 */ 235, 1213, 861, 1213, 1127, 398, 235, 1125, 861, 709, + /* 360 */ 1253, 62, 1238, 1239, 1242, 1285, 985, 347, 859, 228, + /* 370 */ 1281, 1358, 968, 1172, 859, 278, 338, 349, 881, 247, + /* 380 */ 1342, 1213, 320, 11, 1170, 1044, 317, 983, 984, 986, + /* 390 */ 987, 62, 1238, 1239, 1242, 1285, 1237, 398, 7, 228, + /* 400 */ 1281, 1358, 339, 906, 1, 908, 909, 910, 911, 912, + /* 410 */ 1303, 880, 1299, 326, 322, 342, 1253, 30, 28, 348, + /* 420 */ 1068, 59, 428, 347, 1172, 235, 1213, 861, 428, 1043, + /* 430 */ 1295, 93, 1189, 349, 860, 1193, 960, 1213, 1117, 120, + /* 440 */ 860, 363, 335, 859, 1304, 956, 184, 202, 1238, 1239, + /* 450 */ 1242, 1014, 1015, 862, 865, 201, 248, 907, 389, 862, + /* 460 */ 865, 201, 1125, 907, 104, 259, 1112, 1346, 879, 292, + /* 470 */ 1213, 287, 1127, 7, 291, 252, 118, 290, 264, 288, + /* 480 */ 117, 1035, 289, 982, 1344, 340, 1237, 265, 31, 29, + /* 490 */ 27, 26, 25, 30, 28, 41, 1299, 428, 6, 363, + /* 500 */ 343, 235, 137, 861, 249, 135, 1253, 30, 28, 860, + /* 510 */ 122, 121, 1061, 347, 1294, 235, 1237, 861, 139, 859, + /* 520 */ 1125, 138, 884, 349, 27, 26, 25, 1213, 862, 865, + /* 530 */ 201, 1108, 907, 859, 293, 337, 1253, 63, 1238, 1239, + /* 540 */ 1242, 1285, 1056, 347, 388, 1284, 1281, 1042, 1093, 7, + /* 550 */ 1054, 318, 167, 349, 1172, 263, 1041, 1213, 258, 257, + /* 560 */ 256, 255, 254, 1, 295, 1171, 431, 63, 1238, 1239, + /* 570 */ 1242, 1285, 298, 428, 1237, 345, 1281, 868, 141, 959, + /* 580 */ 187, 140, 1040, 88, 160, 860, 277, 428, 1213, 420, + /* 590 */ 1039, 186, 331, 1166, 1253, 156, 1038, 1213, 1037, 860, + /* 600 */ 956, 347, 1100, 304, 862, 865, 201, 154, 907, 9, + /* 610 */ 8, 349, 1315, 92, 60, 1213, 302, 182, 862, 865, + /* 620 */ 201, 332, 907, 1213, 151, 63, 1238, 1239, 1242, 1285, + /* 630 */ 143, 1213, 335, 142, 1282, 1237, 1036, 1213, 1254, 1213, + /* 640 */ 90, 1017, 1018, 871, 1237, 169, 58, 867, 359, 1033, + /* 650 */ 163, 1292, 330, 1032, 329, 1253, 54, 1346, 1031, 395, + /* 660 */ 1030, 879, 347, 394, 1253, 312, 931, 1029, 147, 2, + /* 670 */ 117, 347, 349, 1237, 1344, 1028, 1213, 1213, 32, 234, + /* 680 */ 1020, 349, 1237, 119, 396, 1213, 206, 1238, 1239, 1242, + /* 690 */ 1213, 1237, 1191, 1253, 1213, 204, 1238, 1239, 1242, 1213, + /* 700 */ 347, 1213, 1253, 393, 392, 391, 253, 390, 1213, 347, + /* 710 */ 349, 1253, 1027, 870, 1213, 261, 1213, 314, 347, 349, + /* 720 */ 887, 1237, 260, 1213, 206, 1238, 1239, 1242, 349, 250, + /* 730 */ 262, 124, 1213, 205, 1238, 1239, 1242, 242, 241, 1237, + /* 740 */ 266, 1253, 107, 1238, 1239, 1242, 1026, 873, 347, 267, + /* 750 */ 886, 268, 194, 1213, 1346, 127, 331, 196, 349, 1253, + /* 760 */ 42, 1025, 1213, 866, 269, 327, 347, 117, 1237, 195, + /* 770 */ 891, 1344, 207, 1238, 1239, 1242, 349, 92, 130, 123, + /* 780 */ 1213, 1360, 32, 232, 272, 885, 20, 1213, 1253, 854, + /* 790 */ 206, 1238, 1239, 1242, 279, 347, 31, 29, 27, 26, + /* 800 */ 25, 32, 1213, 68, 90, 349, 1022, 281, 1115, 1213, + /* 810 */ 134, 1231, 236, 333, 113, 1292, 1293, 364, 1297, 206, + /* 820 */ 1238, 1239, 1242, 1229, 1237, 1111, 136, 100, 101, 869, + /* 830 */ 87, 86, 85, 84, 83, 82, 81, 80, 79, 861, + /* 840 */ 64, 175, 355, 1113, 1253, 181, 1237, 132, 874, 865, + /* 850 */ 111, 347, 1237, 173, 95, 859, 276, 96, 131, 775, + /* 860 */ 1109, 349, 102, 103, 224, 1213, 1253, 308, 146, 311, + /* 870 */ 770, 98, 1253, 347, 1237, 199, 1238, 1239, 1242, 347, + /* 880 */ 118, 44, 41, 349, 129, 310, 331, 1213, 149, 349, + /* 890 */ 884, 1316, 319, 1213, 1253, 1326, 152, 208, 1238, 1239, + /* 900 */ 1242, 347, 1237, 200, 1238, 1239, 1242, 92, 803, 428, + /* 910 */ 1237, 349, 807, 353, 316, 1213, 865, 1325, 5, 155, + /* 920 */ 368, 860, 1253, 227, 96, 209, 1238, 1239, 1242, 347, + /* 930 */ 1253, 128, 323, 1306, 90, 125, 159, 347, 1237, 349, + /* 940 */ 862, 865, 315, 1213, 114, 1292, 1293, 349, 1297, 328, + /* 950 */ 4, 1213, 161, 1250, 1238, 1239, 1242, 1237, 1253, 22, + /* 960 */ 110, 1249, 1238, 1239, 1242, 347, 1237, 956, 813, 31, + /* 970 */ 29, 27, 26, 25, 883, 349, 812, 1253, 1300, 1213, + /* 980 */ 97, 91, 33, 162, 347, 1237, 1253, 229, 98, 1248, + /* 990 */ 1238, 1239, 1242, 347, 349, 1361, 344, 341, 1213, 1343, + /* 1000 */ 168, 17, 1267, 349, 99, 1253, 356, 1213, 215, 1238, + /* 1010 */ 1239, 1242, 347, 1237, 1200, 351, 96, 214, 1238, 1239, + /* 1020 */ 1242, 352, 349, 177, 1199, 237, 1213, 357, 331, 358, + /* 1030 */ 179, 188, 51, 1253, 1126, 53, 216, 1238, 1239, 1242, + /* 1040 */ 347, 1237, 366, 297, 190, 185, 427, 197, 198, 92, + /* 1050 */ 349, 193, 1207, 192, 1213, 837, 1184, 1183, 305, 94, + /* 1060 */ 1182, 1253, 1181, 1180, 213, 1238, 1239, 1242, 347, 1179, + /* 1070 */ 1178, 1177, 145, 1176, 1175, 300, 90, 839, 349, 1174, + /* 1080 */ 294, 1173, 1213, 144, 1067, 1206, 115, 1292, 1293, 1197, + /* 1090 */ 1297, 126, 203, 1238, 1239, 1242, 1104, 722, 1066, 1064, + /* 1100 */ 292, 275, 287, 273, 274, 291, 40, 1053, 290, 39, + /* 1110 */ 288, 1052, 1049, 289, 1106, 31, 29, 27, 26, 25, + /* 1120 */ 67, 133, 818, 1105, 820, 819, 750, 1062, 749, 748, + /* 1130 */ 747, 746, 745, 1057, 296, 221, 1055, 222, 223, 299, + /* 1140 */ 1048, 301, 1047, 303, 65, 1205, 1204, 36, 1196, 148, + /* 1150 */ 45, 150, 14, 3, 15, 34, 32, 37, 158, 19, + /* 1160 */ 1229, 48, 10, 164, 8, 917, 153, 1003, 1002, 230, + /* 1170 */ 1007, 981, 894, 108, 354, 1006, 157, 231, 975, 974, + /* 1180 */ 1195, 180, 875, 1021, 116, 46, 47, 1021, 1021, 953, + /* 1190 */ 1021, 952, 1021, 1021, 178, 1008, 1063, 1051, 1050, 367, + /* 1200 */ 1021, 244, 1021, 371, 892, 781, 35, 172, 1021, 16, + /* 1210 */ 979, 13, 18, 374, 171, 174, 377, 176, 49, 380, + /* 1220 */ 50, 425, 1021, 1021, 38, 815, 809, 426, 804, 742, + /* 1230 */ 811, 54, 369, 810, 1228, 183, 801, 365, 372, 1021, + /* 1240 */ 798, 375, 734, 792, 378, 422, 790, 381, 741, 740, + /* 1250 */ 720, 739, 397, 55, 738, 737, 736, 735, 56, 733, + /* 1260 */ 796, 418, 795, 794, 387, 732, 793, 731, 57, 730, + /* 1270 */ 729, 728, 727, 726, 725, 417, 1046, 421, 863, 191, + /* 1280 */ 429, 419, 430, 1021, 1021, 1021, 1021, 1021, 1021, 1021, + /* 1290 */ 814, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 187, 167, 191, 208, 167, 204, 191, 194, 207, 214, - /* 10 */ 215, 210, 12, 13, 14, 15, 16, 188, 166, 208, - /* 20 */ 168, 187, 173, 208, 187, 214, 215, 178, 194, 214, - /* 30 */ 215, 194, 219, 187, 185, 20, 222, 223, 204, 173, - /* 40 */ 194, 204, 208, 194, 178, 208, 20, 47, 0, 173, - /* 50 */ 213, 185, 218, 219, 220, 218, 219, 220, 221, 173, - /* 60 */ 194, 18, 225, 226, 178, 219, 23, 204, 57, 69, - /* 70 */ 186, 173, 61, 210, 237, 199, 178, 77, 35, 175, - /* 80 */ 194, 197, 12, 13, 14, 15, 16, 250, 45, 255, - /* 90 */ 256, 254, 194, 82, 68, 167, 192, 49, 50, 51, + /* 0 */ 216, 183, 181, 175, 196, 212, 222, 223, 215, 196, + /* 10 */ 192, 218, 12, 13, 14, 15, 16, 195, 200, 231, + /* 20 */ 232, 246, 199, 195, 202, 12, 13, 14, 15, 16, + /* 30 */ 202, 181, 181, 0, 259, 20, 186, 186, 263, 216, + /* 40 */ 212, 175, 221, 193, 216, 222, 223, 47, 0, 221, + /* 50 */ 228, 20, 202, 202, 226, 227, 228, 229, 230, 20, + /* 60 */ 47, 195, 234, 235, 204, 181, 46, 246, 202, 69, + /* 70 */ 186, 211, 212, 187, 246, 184, 185, 77, 212, 46, + /* 80 */ 259, 195, 216, 68, 263, 188, 202, 259, 191, 203, + /* 90 */ 77, 263, 226, 227, 228, 229, 0, 49, 50, 51, /* 100 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - /* 110 */ 62, 63, 64, 65, 66, 46, 116, 47, 12, 13, - /* 120 */ 14, 15, 16, 1, 2, 125, 126, 0, 128, 129, - /* 130 */ 130, 131, 132, 133, 134, 135, 208, 14, 15, 16, - /* 140 */ 12, 13, 14, 15, 16, 164, 167, 77, 21, 106, - /* 150 */ 20, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 160 */ 120, 83, 84, 85, 86, 87, 88, 89, 90, 91, - /* 170 */ 92, 93, 216, 95, 96, 97, 98, 99, 100, 20, - /* 180 */ 49, 138, 51, 143, 144, 54, 116, 208, 57, 233, - /* 190 */ 59, 69, 167, 62, 213, 125, 126, 69, 128, 129, - /* 200 */ 130, 131, 132, 133, 134, 135, 12, 13, 14, 15, - /* 210 */ 16, 20, 187, 176, 177, 170, 171, 21, 237, 194, - /* 220 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 204, - /* 230 */ 175, 250, 179, 208, 127, 254, 237, 35, 138, 184, - /* 240 */ 187, 20, 167, 218, 219, 220, 221, 192, 195, 250, - /* 250 */ 225, 226, 227, 254, 147, 148, 149, 150, 151, 57, - /* 260 */ 20, 173, 187, 61, 239, 159, 160, 20, 138, 194, - /* 270 */ 245, 246, 167, 71, 27, 73, 74, 30, 76, 204, - /* 280 */ 196, 179, 194, 208, 82, 173, 39, 203, 204, 187, - /* 290 */ 178, 194, 187, 218, 219, 220, 221, 195, 201, 194, - /* 300 */ 225, 226, 227, 136, 137, 20, 194, 173, 220, 204, - /* 310 */ 167, 22, 178, 208, 20, 167, 22, 229, 230, 231, - /* 320 */ 232, 246, 234, 218, 219, 220, 221, 38, 194, 173, - /* 330 */ 225, 226, 227, 43, 40, 187, 167, 12, 13, 12, - /* 340 */ 13, 236, 194, 122, 167, 20, 63, 22, 20, 22, - /* 350 */ 194, 208, 204, 68, 107, 46, 208, 110, 111, 112, - /* 360 */ 113, 114, 122, 38, 187, 38, 218, 219, 220, 221, - /* 370 */ 116, 194, 47, 225, 226, 227, 220, 208, 173, 125, - /* 380 */ 0, 204, 20, 178, 236, 208, 230, 231, 232, 135, - /* 390 */ 234, 108, 109, 68, 187, 218, 219, 220, 221, 194, - /* 400 */ 193, 167, 225, 226, 227, 198, 12, 13, 14, 0, - /* 410 */ 12, 13, 180, 236, 20, 183, 22, 92, 20, 92, - /* 420 */ 22, 187, 4, 138, 1, 2, 46, 137, 194, 104, - /* 430 */ 173, 104, 38, 187, 14, 167, 38, 167, 204, 193, - /* 440 */ 20, 47, 208, 0, 198, 47, 2, 213, 123, 124, - /* 450 */ 123, 124, 218, 219, 220, 46, 12, 13, 14, 15, - /* 460 */ 16, 187, 68, 138, 167, 179, 68, 12, 13, 195, - /* 470 */ 213, 237, 0, 187, 187, 20, 208, 22, 208, 172, - /* 480 */ 193, 195, 216, 167, 250, 198, 92, 173, 254, 182, - /* 490 */ 92, 79, 178, 38, 237, 187, 189, 167, 104, 233, - /* 500 */ 57, 47, 104, 187, 61, 208, 198, 250, 194, 3, - /* 510 */ 194, 254, 167, 172, 167, 167, 177, 123, 124, 188, - /* 520 */ 204, 123, 124, 68, 208, 82, 167, 167, 167, 57, - /* 530 */ 189, 167, 187, 61, 218, 219, 220, 221, 208, 194, - /* 540 */ 173, 225, 226, 188, 101, 102, 103, 92, 105, 204, - /* 550 */ 12, 13, 14, 208, 82, 208, 208, 139, 20, 104, - /* 560 */ 22, 194, 167, 218, 219, 220, 221, 208, 208, 208, - /* 570 */ 225, 226, 208, 101, 102, 103, 38, 105, 123, 124, - /* 580 */ 213, 127, 167, 69, 12, 13, 167, 220, 167, 188, - /* 590 */ 216, 167, 20, 138, 22, 81, 167, 230, 231, 232, - /* 600 */ 22, 234, 187, 208, 237, 167, 68, 233, 72, 194, - /* 610 */ 38, 75, 12, 13, 187, 72, 38, 250, 75, 204, - /* 620 */ 20, 254, 22, 208, 0, 198, 21, 208, 72, 208, - /* 630 */ 92, 75, 208, 218, 219, 220, 221, 208, 38, 34, - /* 640 */ 68, 226, 104, 0, 162, 163, 208, 0, 24, 25, - /* 650 */ 26, 27, 28, 29, 30, 31, 32, 0, 19, 188, - /* 660 */ 154, 123, 124, 68, 92, 22, 167, 81, 68, 22, - /* 670 */ 92, 72, 33, 78, 75, 36, 104, 69, 69, 22, - /* 680 */ 38, 42, 104, 44, 81, 167, 187, 69, 69, 81, - /* 690 */ 81, 168, 92, 194, 257, 123, 124, 248, 197, 81, - /* 700 */ 81, 123, 124, 204, 104, 187, 67, 208, 68, 70, - /* 710 */ 211, 242, 194, 69, 170, 167, 38, 218, 219, 220, - /* 720 */ 80, 167, 204, 123, 124, 81, 208, 69, 217, 211, - /* 730 */ 235, 69, 173, 187, 167, 187, 218, 219, 220, 81, - /* 740 */ 101, 187, 194, 81, 158, 251, 104, 238, 194, 20, - /* 750 */ 173, 69, 204, 194, 187, 202, 208, 118, 204, 156, - /* 760 */ 121, 194, 208, 81, 116, 69, 218, 219, 220, 69, - /* 770 */ 200, 204, 218, 219, 220, 208, 115, 81, 211, 220, - /* 780 */ 167, 81, 104, 69, 200, 218, 219, 220, 167, 230, - /* 790 */ 231, 232, 2, 234, 20, 81, 173, 249, 194, 69, - /* 800 */ 187, 69, 12, 13, 14, 15, 16, 194, 187, 212, - /* 810 */ 256, 81, 175, 81, 69, 194, 167, 204, 69, 20, - /* 820 */ 205, 208, 167, 173, 211, 204, 81, 175, 175, 208, - /* 830 */ 81, 218, 219, 220, 175, 20, 187, 169, 187, 218, - /* 840 */ 219, 220, 187, 194, 167, 173, 212, 187, 169, 194, - /* 850 */ 187, 187, 187, 204, 187, 172, 187, 208, 187, 204, - /* 860 */ 187, 187, 187, 208, 187, 172, 20, 218, 219, 220, - /* 870 */ 194, 194, 167, 218, 219, 220, 247, 146, 167, 145, - /* 880 */ 124, 204, 247, 217, 243, 208, 205, 141, 153, 209, - /* 890 */ 244, 167, 187, 208, 208, 218, 219, 220, 187, 194, - /* 900 */ 209, 140, 208, 152, 137, 194, 194, 20, 115, 204, - /* 910 */ 240, 187, 228, 208, 216, 204, 161, 157, 194, 208, - /* 920 */ 167, 155, 68, 218, 219, 220, 167, 224, 204, 218, - /* 930 */ 219, 220, 208, 241, 209, 208, 208, 119, 194, 167, - /* 940 */ 187, 253, 218, 219, 220, 258, 187, 194, 167, 252, - /* 950 */ 209, 208, 205, 194, 206, 172, 183, 204, 172, 187, - /* 960 */ 68, 208, 194, 204, 0, 190, 194, 208, 187, 173, - /* 970 */ 172, 218, 219, 220, 169, 194, 204, 218, 219, 220, - /* 980 */ 208, 181, 181, 167, 174, 204, 165, 0, 80, 208, - /* 990 */ 218, 219, 220, 33, 0, 0, 36, 115, 0, 218, - /* 1000 */ 219, 220, 42, 187, 44, 0, 0, 0, 0, 0, - /* 1010 */ 194, 167, 22, 49, 0, 51, 0, 167, 54, 0, - /* 1020 */ 204, 57, 0, 59, 208, 0, 62, 67, 0, 0, - /* 1030 */ 70, 187, 43, 0, 218, 219, 220, 187, 194, 48, - /* 1040 */ 0, 0, 4, 43, 194, 0, 36, 0, 204, 38, - /* 1050 */ 0, 0, 208, 77, 204, 75, 38, 19, 208, 38, - /* 1060 */ 0, 22, 218, 219, 220, 38, 0, 0, 218, 219, - /* 1070 */ 220, 33, 38, 38, 36, 38, 22, 117, 22, 41, - /* 1080 */ 38, 121, 44, 39, 38, 0, 22, 38, 0, 0, - /* 1090 */ 22, 22, 20, 0, 0, 122, 0, 142, 68, 117, - /* 1100 */ 43, 81, 136, 142, 81, 67, 4, 81, 70, 142, - /* 1110 */ 2, 80, 69, 81, 38, 38, 80, 69, 38, 38, - /* 1120 */ 68, 68, 38, 127, 69, 38, 68, 0, 69, 68, - /* 1130 */ 259, 22, 69, 120, 69, 259, 259, 259, 259, 259, - /* 1140 */ 69, 43, 0, 81, 69, 38, 259, 68, 38, 259, - /* 1150 */ 68, 81, 69, 80, 68, 81, 38, 38, 80, 69, - /* 1160 */ 68, 38, 259, 68, 38, 68, 22, 22, 0, 0, - /* 1170 */ 38, 68, 0, 38, 69, 69, 22, 78, 22, 68, - /* 1180 */ 80, 80, 68, 79, 69, 68, 38, 38, 47, 69, - /* 1190 */ 68, 38, 37, 69, 48, 38, 68, 38, 68, 38, - /* 1200 */ 38, 68, 68, 38, 38, 38, 94, 94, 117, 38, - /* 1210 */ 94, 82, 38, 38, 38, 94, 38, 38, 38, 38, - /* 1220 */ 36, 38, 22, 21, 21, 43, 22, 22, 20, 104, - /* 1230 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1240 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1250 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1260 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1270 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1280 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1290 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1300 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1310 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1320 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1330 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1340 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1350 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1360 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1370 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1380 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, - /* 1390 */ 259, 259, 259, 259, + /* 110 */ 62, 63, 64, 65, 66, 183, 116, 21, 116, 47, + /* 120 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 116, + /* 130 */ 264, 265, 200, 133, 134, 133, 136, 137, 138, 139, + /* 140 */ 140, 141, 142, 143, 20, 143, 133, 134, 0, 136, + /* 150 */ 137, 138, 139, 140, 141, 142, 143, 1, 2, 175, + /* 160 */ 20, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 170 */ 92, 93, 69, 95, 96, 97, 98, 99, 100, 195, + /* 180 */ 12, 13, 181, 195, 81, 146, 202, 186, 20, 201, + /* 190 */ 22, 12, 13, 14, 206, 174, 212, 176, 57, 20, + /* 200 */ 216, 22, 61, 202, 175, 57, 38, 135, 68, 61, + /* 210 */ 226, 227, 228, 229, 230, 47, 181, 38, 234, 235, + /* 220 */ 236, 195, 181, 82, 195, 69, 47, 186, 202, 175, + /* 230 */ 82, 202, 248, 20, 193, 180, 68, 194, 254, 255, + /* 240 */ 35, 212, 207, 202, 199, 216, 122, 68, 205, 101, + /* 250 */ 102, 103, 197, 105, 228, 226, 227, 228, 229, 230, + /* 260 */ 92, 216, 57, 234, 235, 236, 61, 222, 223, 195, + /* 270 */ 216, 92, 104, 20, 175, 201, 71, 195, 73, 74, + /* 280 */ 206, 76, 146, 104, 255, 203, 146, 82, 20, 224, + /* 290 */ 22, 123, 124, 125, 195, 127, 12, 13, 14, 15, + /* 300 */ 16, 202, 123, 124, 125, 20, 127, 242, 40, 0, + /* 310 */ 175, 212, 175, 21, 146, 216, 24, 25, 26, 27, + /* 320 */ 28, 29, 30, 31, 32, 226, 227, 228, 229, 230, + /* 330 */ 195, 178, 179, 234, 235, 236, 181, 202, 187, 212, + /* 340 */ 175, 186, 12, 13, 245, 218, 195, 212, 12, 13, + /* 350 */ 20, 216, 22, 216, 203, 46, 20, 202, 22, 22, + /* 360 */ 195, 226, 227, 228, 229, 230, 135, 202, 38, 234, + /* 370 */ 235, 236, 14, 195, 38, 38, 3, 212, 20, 201, + /* 380 */ 245, 216, 120, 47, 206, 175, 155, 156, 157, 158, + /* 390 */ 159, 226, 227, 228, 229, 230, 175, 46, 68, 234, + /* 400 */ 235, 236, 81, 126, 68, 128, 129, 130, 131, 132, + /* 410 */ 245, 20, 224, 151, 152, 81, 195, 12, 13, 14, + /* 420 */ 0, 180, 92, 202, 195, 20, 216, 22, 92, 175, + /* 430 */ 242, 190, 202, 212, 104, 206, 4, 216, 197, 209, + /* 440 */ 104, 181, 221, 38, 144, 145, 186, 226, 227, 228, + /* 450 */ 229, 167, 168, 123, 124, 125, 187, 127, 79, 123, + /* 460 */ 124, 125, 202, 127, 195, 63, 196, 246, 20, 49, + /* 470 */ 216, 51, 203, 68, 54, 27, 146, 57, 30, 59, + /* 480 */ 259, 176, 62, 69, 263, 164, 175, 39, 12, 13, + /* 490 */ 14, 15, 16, 12, 13, 81, 224, 92, 43, 181, + /* 500 */ 166, 20, 72, 22, 186, 75, 195, 12, 13, 104, + /* 510 */ 108, 109, 0, 202, 242, 20, 175, 22, 72, 38, + /* 520 */ 202, 75, 20, 212, 14, 15, 16, 216, 123, 124, + /* 530 */ 125, 196, 127, 38, 22, 162, 195, 226, 227, 228, + /* 540 */ 229, 230, 0, 202, 196, 234, 235, 175, 185, 68, + /* 550 */ 0, 257, 266, 212, 195, 107, 175, 216, 110, 111, + /* 560 */ 112, 113, 114, 68, 22, 206, 19, 226, 227, 228, + /* 570 */ 229, 230, 22, 92, 175, 234, 235, 38, 72, 147, + /* 580 */ 33, 75, 175, 36, 251, 104, 178, 92, 216, 42, + /* 590 */ 175, 44, 181, 205, 195, 69, 175, 216, 175, 104, + /* 600 */ 145, 202, 0, 21, 123, 124, 125, 81, 127, 1, + /* 610 */ 2, 212, 225, 202, 67, 216, 34, 70, 123, 124, + /* 620 */ 125, 244, 127, 216, 122, 226, 227, 228, 229, 230, + /* 630 */ 72, 216, 221, 75, 235, 175, 175, 216, 195, 216, + /* 640 */ 229, 170, 171, 104, 175, 260, 68, 38, 101, 175, + /* 650 */ 239, 240, 241, 175, 243, 195, 78, 246, 175, 57, + /* 660 */ 175, 20, 202, 61, 195, 118, 69, 175, 121, 247, + /* 670 */ 259, 202, 212, 175, 263, 175, 216, 216, 81, 219, + /* 680 */ 172, 212, 175, 115, 82, 216, 226, 227, 228, 229, + /* 690 */ 216, 175, 181, 195, 216, 226, 227, 228, 229, 216, + /* 700 */ 202, 216, 195, 101, 102, 103, 210, 105, 216, 202, + /* 710 */ 212, 195, 175, 104, 216, 116, 216, 219, 202, 212, + /* 720 */ 20, 175, 208, 216, 226, 227, 228, 229, 212, 221, + /* 730 */ 208, 183, 216, 226, 227, 228, 229, 12, 13, 175, + /* 740 */ 181, 195, 226, 227, 228, 229, 175, 22, 202, 220, + /* 750 */ 20, 202, 18, 216, 246, 183, 181, 23, 212, 195, + /* 760 */ 183, 175, 216, 38, 213, 258, 202, 259, 175, 35, + /* 770 */ 69, 263, 226, 227, 228, 229, 212, 202, 183, 45, + /* 780 */ 216, 265, 81, 219, 181, 20, 2, 216, 195, 69, + /* 790 */ 226, 227, 228, 229, 177, 202, 12, 13, 14, 15, + /* 800 */ 16, 81, 216, 181, 229, 212, 0, 195, 195, 216, + /* 810 */ 195, 68, 219, 238, 239, 240, 241, 92, 243, 226, + /* 820 */ 227, 228, 229, 80, 175, 195, 195, 195, 195, 104, + /* 830 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 22, + /* 840 */ 106, 69, 69, 195, 195, 69, 175, 33, 123, 124, + /* 850 */ 36, 202, 175, 81, 81, 38, 42, 81, 44, 69, + /* 860 */ 195, 212, 195, 195, 177, 216, 195, 220, 180, 213, + /* 870 */ 69, 81, 195, 202, 175, 226, 227, 228, 229, 202, + /* 880 */ 146, 67, 81, 212, 70, 202, 181, 216, 180, 212, + /* 890 */ 20, 225, 154, 216, 195, 256, 217, 226, 227, 228, + /* 900 */ 229, 202, 175, 226, 227, 228, 229, 202, 69, 92, + /* 910 */ 175, 212, 69, 153, 216, 216, 124, 256, 161, 217, + /* 920 */ 81, 104, 195, 216, 81, 226, 227, 228, 229, 202, + /* 930 */ 195, 117, 216, 253, 229, 121, 252, 202, 175, 212, + /* 940 */ 123, 124, 149, 216, 239, 240, 241, 212, 243, 160, + /* 950 */ 148, 216, 249, 226, 227, 228, 229, 175, 195, 2, + /* 960 */ 250, 226, 227, 228, 229, 202, 175, 145, 69, 12, + /* 970 */ 13, 14, 15, 16, 20, 212, 69, 195, 224, 216, + /* 980 */ 81, 202, 115, 237, 202, 175, 195, 169, 81, 226, + /* 990 */ 227, 228, 229, 202, 212, 267, 165, 163, 216, 262, + /* 1000 */ 261, 68, 233, 212, 69, 195, 119, 216, 226, 227, + /* 1010 */ 228, 229, 202, 175, 217, 216, 81, 226, 227, 228, + /* 1020 */ 229, 216, 212, 202, 217, 216, 216, 214, 181, 213, + /* 1030 */ 180, 191, 180, 195, 202, 68, 226, 227, 228, 229, + /* 1040 */ 202, 175, 198, 4, 181, 180, 177, 189, 189, 202, + /* 1050 */ 212, 173, 0, 182, 216, 80, 0, 0, 19, 115, + /* 1060 */ 0, 195, 0, 0, 226, 227, 228, 229, 202, 0, + /* 1070 */ 0, 0, 33, 0, 0, 36, 229, 22, 212, 0, + /* 1080 */ 41, 0, 216, 44, 0, 0, 239, 240, 241, 0, + /* 1090 */ 243, 43, 226, 227, 228, 229, 0, 48, 0, 0, + /* 1100 */ 49, 43, 51, 38, 36, 54, 67, 0, 57, 70, + /* 1110 */ 59, 0, 0, 62, 0, 12, 13, 14, 15, 16, + /* 1120 */ 77, 75, 22, 0, 38, 38, 38, 0, 38, 38, + /* 1130 */ 38, 38, 38, 0, 39, 22, 0, 22, 22, 38, + /* 1140 */ 0, 22, 0, 22, 20, 0, 0, 122, 0, 43, + /* 1150 */ 68, 117, 150, 81, 150, 144, 81, 81, 81, 81, + /* 1160 */ 80, 4, 150, 80, 2, 135, 69, 38, 38, 38, + /* 1170 */ 38, 69, 69, 68, 120, 38, 68, 38, 69, 69, + /* 1180 */ 0, 117, 22, 268, 80, 68, 68, 268, 268, 69, + /* 1190 */ 268, 69, 268, 268, 43, 69, 0, 0, 0, 38, + /* 1200 */ 268, 38, 268, 38, 69, 22, 81, 69, 268, 81, + /* 1210 */ 69, 68, 68, 38, 80, 68, 38, 68, 68, 38, + /* 1220 */ 68, 22, 268, 268, 68, 38, 22, 21, 69, 22, + /* 1230 */ 38, 78, 68, 38, 80, 80, 69, 79, 68, 268, + /* 1240 */ 69, 68, 22, 69, 68, 37, 69, 68, 38, 38, + /* 1250 */ 48, 38, 47, 68, 38, 38, 38, 38, 68, 38, + /* 1260 */ 94, 36, 94, 94, 82, 38, 94, 38, 68, 38, + /* 1270 */ 38, 38, 38, 38, 38, 38, 0, 38, 22, 22, + /* 1280 */ 21, 43, 20, 268, 268, 268, 268, 268, 268, 268, + /* 1290 */ 104, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1300 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1310 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1320 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1330 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1340 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1350 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1360 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1370 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1380 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1390 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1400 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1410 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1420 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1430 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1440 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1450 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, + /* 1460 */ 268, 268, 268, }; -#define YY_SHIFT_COUNT (430) +#define YY_SHIFT_COUNT (431) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1208) +#define YY_SHIFT_MAX (1276) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 43, 325, 394, 398, 398, 398, 398, 455, 398, 398, - /* 10 */ 285, 572, 600, 538, 572, 572, 572, 572, 572, 572, - /* 20 */ 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - /* 30 */ 572, 572, 572, 26, 26, 26, 130, 327, 327, 15, - /* 40 */ 15, 327, 15, 15, 69, 159, 191, 191, 100, 328, - /* 50 */ 159, 15, 15, 159, 15, 159, 328, 159, 159, 15, - /* 60 */ 309, 0, 70, 70, 247, 196, 202, 578, 131, 578, - /* 70 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, - /* 80 */ 578, 578, 578, 578, 578, 578, 578, 578, 294, 380, - /* 90 */ 221, 221, 221, 409, 362, 328, 159, 159, 159, 412, - /* 100 */ 78, 78, 78, 78, 78, 127, 964, 106, 107, 11, - /* 110 */ 40, 289, 240, 167, 290, 167, 420, 506, 418, 729, - /* 120 */ 661, 648, 648, 729, 774, 69, 362, 799, 69, 69, - /* 130 */ 729, 69, 815, 159, 159, 159, 159, 159, 159, 159, - /* 140 */ 159, 159, 159, 159, 729, 815, 774, 309, 362, 799, - /* 150 */ 309, 846, 731, 734, 756, 731, 734, 756, 756, 735, - /* 160 */ 751, 746, 761, 767, 362, 887, 793, 755, 760, 766, - /* 170 */ 854, 159, 734, 756, 756, 734, 756, 818, 362, 799, - /* 180 */ 309, 412, 309, 362, 892, 729, 309, 815, 1230, 1230, - /* 190 */ 1230, 1230, 48, 624, 639, 960, 1038, 443, 472, 444, - /* 200 */ 790, 128, 194, 194, 194, 194, 194, 194, 194, 283, - /* 210 */ 122, 254, 123, 123, 123, 123, 536, 543, 556, 599, - /* 220 */ 643, 647, 657, 605, 514, 608, 609, 423, 482, 603, - /* 230 */ 586, 618, 454, 619, 640, 644, 658, 662, 682, 696, - /* 240 */ 642, 678, 700, 714, 730, 732, 745, 749, 595, 987, - /* 250 */ 908, 994, 995, 882, 998, 1005, 1006, 1007, 1008, 1009, - /* 260 */ 990, 1014, 1016, 1019, 1022, 1025, 1028, 1029, 989, 1033, - /* 270 */ 991, 1040, 1041, 1011, 1010, 1000, 1045, 1047, 1050, 1051, - /* 280 */ 976, 980, 1018, 1021, 1039, 1060, 1027, 1034, 1035, 1037, - /* 290 */ 1042, 1046, 1066, 1054, 1067, 1056, 1044, 1085, 1064, 1049, - /* 300 */ 1088, 1068, 1089, 1069, 1072, 1093, 1094, 973, 1096, 1030, - /* 310 */ 1057, 982, 1020, 1023, 955, 1043, 1026, 1048, 1052, 1053, - /* 320 */ 1055, 1058, 1059, 1032, 1031, 1061, 1062, 961, 1063, 1065, - /* 330 */ 1036, 966, 1070, 1073, 1071, 1074, 967, 1102, 1076, 1077, - /* 340 */ 1080, 1081, 1084, 1087, 1108, 996, 1078, 1075, 1079, 1082, - /* 350 */ 1083, 1090, 1086, 1092, 1013, 1095, 1127, 1098, 1091, 1097, - /* 360 */ 1099, 1100, 1101, 1109, 1103, 1104, 1105, 1107, 1110, 1111, - /* 370 */ 1106, 1118, 1114, 1115, 1119, 1117, 1120, 1123, 1122, 1124, - /* 380 */ 1126, 1128, 1112, 1113, 1116, 1121, 1144, 1129, 1130, 1132, - /* 390 */ 1125, 1133, 1134, 1135, 1148, 1145, 1146, 1141, 1154, 1149, - /* 400 */ 1153, 1157, 1159, 1161, 1162, 1165, 1156, 1166, 1167, 1171, - /* 410 */ 1174, 1175, 1176, 1178, 1179, 1180, 1142, 1181, 1184, 1182, - /* 420 */ 1168, 1183, 1155, 1169, 1172, 1200, 1202, 1204, 1205, 1203, - /* 430 */ 1208, + /* 0 */ 734, 168, 179, 336, 336, 336, 336, 330, 336, 336, + /* 10 */ 481, 495, 140, 405, 481, 481, 481, 481, 481, 481, + /* 20 */ 481, 481, 481, 481, 481, 481, 481, 481, 481, 481, + /* 30 */ 481, 481, 481, 15, 15, 15, 39, 725, 725, 31, + /* 40 */ 31, 725, 31, 31, 20, 213, 253, 253, 136, 285, + /* 50 */ 213, 31, 31, 213, 31, 213, 285, 213, 213, 31, + /* 60 */ 351, 0, 13, 13, 448, 292, 205, 817, 1051, 817, + /* 70 */ 817, 817, 817, 817, 817, 817, 817, 817, 817, 817, + /* 80 */ 817, 817, 817, 817, 817, 817, 817, 817, 268, 33, + /* 90 */ 124, 124, 124, 309, 391, 285, 213, 213, 213, 379, + /* 100 */ 78, 78, 78, 78, 78, 96, 420, 284, 231, 141, + /* 110 */ 262, 337, 502, 300, 455, 300, 358, 373, 432, 641, + /* 120 */ 568, 599, 599, 641, 700, 20, 391, 730, 20, 20, + /* 130 */ 641, 20, 765, 213, 213, 213, 213, 213, 213, 213, + /* 140 */ 213, 213, 213, 213, 641, 765, 700, 351, 391, 730, + /* 150 */ 351, 870, 738, 760, 792, 738, 760, 792, 792, 757, + /* 160 */ 789, 793, 802, 822, 391, 954, 867, 818, 831, 834, + /* 170 */ 933, 213, 760, 792, 792, 760, 792, 887, 391, 730, + /* 180 */ 351, 379, 351, 391, 967, 641, 351, 765, 1291, 1291, + /* 190 */ 1291, 1291, 48, 806, 547, 814, 1039, 148, 602, 784, + /* 200 */ 957, 277, 1103, 476, 476, 476, 476, 476, 476, 476, + /* 210 */ 402, 156, 2, 510, 510, 510, 510, 430, 446, 506, + /* 220 */ 558, 512, 542, 550, 582, 103, 414, 526, 608, 471, + /* 230 */ 321, 334, 597, 72, 701, 743, 720, 772, 773, 776, + /* 240 */ 790, 539, 609, 801, 839, 843, 899, 907, 935, 578, + /* 250 */ 1052, 975, 1056, 1057, 944, 1060, 1062, 1063, 1069, 1070, + /* 260 */ 1071, 1055, 1073, 1074, 1079, 1081, 1084, 1085, 1089, 1048, + /* 270 */ 1096, 1049, 1098, 1099, 1065, 1068, 1058, 1107, 1111, 1112, + /* 280 */ 1114, 1043, 1046, 1086, 1087, 1100, 1123, 1088, 1090, 1091, + /* 290 */ 1092, 1093, 1094, 1127, 1113, 1133, 1115, 1095, 1136, 1116, + /* 300 */ 1101, 1140, 1119, 1142, 1121, 1124, 1145, 1146, 1025, 1148, + /* 310 */ 1082, 1106, 1034, 1072, 1075, 1002, 1097, 1076, 1102, 1105, + /* 320 */ 1108, 1109, 1117, 1110, 1077, 1080, 1118, 1078, 1004, 1120, + /* 330 */ 1122, 1083, 1011, 1125, 1104, 1126, 1128, 1012, 1157, 1129, + /* 340 */ 1130, 1131, 1132, 1137, 1139, 1162, 1030, 1134, 1135, 1143, + /* 350 */ 1144, 1138, 1141, 1147, 1149, 1054, 1150, 1180, 1151, 1064, + /* 360 */ 1152, 1153, 1154, 1155, 1160, 1156, 1158, 1159, 1161, 1163, + /* 370 */ 1164, 1167, 1165, 1170, 1171, 1175, 1173, 1174, 1178, 1176, + /* 380 */ 1177, 1181, 1179, 1166, 1168, 1169, 1172, 1183, 1182, 1185, + /* 390 */ 1187, 1186, 1190, 1200, 1192, 1195, 1204, 1202, 1205, 1207, + /* 400 */ 1210, 1211, 1213, 1216, 1217, 1218, 1219, 1220, 1221, 1227, + /* 410 */ 1229, 1231, 1232, 1233, 1234, 1235, 1236, 1196, 1237, 1225, + /* 420 */ 1238, 1197, 1239, 1208, 1198, 1276, 1199, 1206, 1256, 1257, + /* 430 */ 1259, 1262, }; #define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-205) -#define YY_REDUCE_MAX (850) +#define YY_REDUCE_MIN (-225) +#define YY_REDUCE_MAX (878) static const short yy_reduce_ofst[] = { - /* 0 */ -19, -163, 25, 75, 105, 148, 177, 234, 316, 345, - /* 10 */ 367, -166, 415, 499, 518, 548, 554, 567, 613, 621, - /* 20 */ 649, 655, 677, 705, 711, 724, 753, 759, 772, 781, - /* 30 */ 816, 844, 850, 88, 156, 559, 257, -189, -185, -151, - /* 40 */ -134, -205, -114, -102, 55, 207, -187, -154, -1, -199, - /* 50 */ 53, 112, 134, 246, 205, 102, 84, 287, 286, 314, - /* 60 */ 307, -186, -186, -186, -124, -148, -116, -72, 37, -21, - /* 70 */ 143, 169, 268, 270, 297, 330, 347, 348, 359, 360, - /* 80 */ 361, 364, 395, 419, 421, 424, 429, 438, 45, -96, - /* 90 */ -44, 266, 374, 341, 97, -137, 274, 308, 427, 232, - /* 100 */ -171, 331, 355, 401, 471, 523, 339, 437, 449, 501, - /* 110 */ 469, 544, 511, 495, 495, 495, 546, 494, 509, 577, - /* 120 */ 553, 570, 584, 623, 597, 637, 604, 615, 652, 653, - /* 130 */ 650, 659, 668, 651, 660, 663, 664, 665, 667, 669, - /* 140 */ 671, 673, 674, 675, 672, 679, 634, 683, 676, 681, - /* 150 */ 693, 666, 629, 680, 685, 635, 691, 686, 694, 646, - /* 160 */ 641, 692, 670, 495, 712, 698, 684, 687, 688, 697, - /* 170 */ 703, 546, 725, 727, 728, 741, 743, 748, 744, 747, - /* 180 */ 783, 773, 786, 768, 775, 796, 798, 805, 800, 801, - /* 190 */ 810, 821, + /* 0 */ 508, -172, -16, 29, 99, 135, 165, 221, 311, 341, + /* 10 */ -134, 399, 411, 460, 498, 507, 516, 564, 593, 469, + /* 20 */ 546, 649, 671, 677, 699, 727, 735, 763, 782, 791, + /* 30 */ 810, 838, 866, 575, 705, 847, -179, -177, 45, -150, + /* 40 */ 41, -216, -149, -116, -182, -12, -178, 26, -225, -207, + /* 50 */ -114, 1, 155, 74, 260, 151, -140, 178, 269, 318, + /* 60 */ 241, -212, -212, -212, 35, 21, 43, 54, -109, 137, + /* 70 */ 210, 254, 372, 381, 407, 415, 421, 423, 461, 474, + /* 80 */ 478, 483, 485, 492, 500, 537, 571, 586, 153, -68, + /* 90 */ 65, 188, 272, 55, 230, 127, 82, 229, 359, -103, + /* 100 */ -192, -187, 270, 335, 348, 305, 363, 286, 294, 388, + /* 110 */ 333, 408, 387, 377, 377, 377, 443, 385, 422, 511, + /* 120 */ 496, 514, 522, 559, 529, 548, 549, 551, 572, 577, + /* 130 */ 603, 595, 617, 612, 613, 615, 630, 631, 632, 633, + /* 140 */ 648, 665, 667, 668, 622, 687, 647, 688, 683, 656, + /* 150 */ 708, 666, 639, 679, 698, 661, 702, 707, 716, 680, + /* 160 */ 684, 710, 703, 377, 779, 754, 746, 728, 737, 739, + /* 170 */ 769, 443, 797, 799, 805, 807, 809, 813, 821, 816, + /* 180 */ 850, 840, 852, 832, 844, 863, 865, 869, 858, 859, + /* 190 */ 871, 878, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 10 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 20 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 30 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 40 */ 1002, 1002, 1002, 1002, 1055, 1002, 1002, 1002, 1002, 1002, - /* 50 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 60 */ 1053, 1002, 1262, 1002, 1168, 1002, 1002, 1002, 1002, 1002, - /* 70 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 80 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1055, - /* 90 */ 1273, 1273, 1273, 1053, 1002, 1002, 1002, 1002, 1002, 1137, - /* 100 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1337, 1002, 1090, - /* 110 */ 1297, 1002, 1289, 1265, 1279, 1266, 1002, 1322, 1282, 1002, - /* 120 */ 1173, 1170, 1170, 1002, 1002, 1055, 1002, 1002, 1055, 1055, - /* 130 */ 1002, 1055, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 140 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1053, 1002, 1002, - /* 150 */ 1053, 1002, 1304, 1302, 1002, 1304, 1302, 1002, 1002, 1316, - /* 160 */ 1312, 1295, 1293, 1279, 1002, 1002, 1002, 1340, 1328, 1324, - /* 170 */ 1002, 1002, 1302, 1002, 1002, 1302, 1002, 1181, 1002, 1002, - /* 180 */ 1053, 1002, 1053, 1002, 1106, 1002, 1053, 1002, 1140, 1140, - /* 190 */ 1056, 1007, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 200 */ 1002, 1002, 1234, 1315, 1314, 1233, 1239, 1238, 1237, 1002, - /* 210 */ 1002, 1002, 1228, 1229, 1227, 1226, 1002, 1002, 1002, 1002, - /* 220 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1263, 1002, 1325, - /* 230 */ 1329, 1002, 1002, 1002, 1213, 1002, 1002, 1002, 1002, 1002, - /* 240 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 250 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 260 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 270 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 280 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 290 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 300 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 310 */ 1002, 1002, 1286, 1296, 1002, 1002, 1002, 1002, 1002, 1002, - /* 320 */ 1002, 1002, 1002, 1002, 1213, 1002, 1313, 1002, 1272, 1268, - /* 330 */ 1002, 1002, 1264, 1002, 1002, 1323, 1002, 1002, 1002, 1002, - /* 340 */ 1002, 1002, 1002, 1002, 1258, 1002, 1002, 1002, 1002, 1002, - /* 350 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 360 */ 1002, 1212, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1134, - /* 370 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 380 */ 1002, 1002, 1119, 1117, 1116, 1115, 1002, 1112, 1002, 1002, - /* 390 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 400 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 410 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 420 */ 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, - /* 430 */ 1002, + /* 0 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 10 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 20 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 30 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 40 */ 1019, 1019, 1019, 1019, 1072, 1019, 1019, 1019, 1019, 1019, + /* 50 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 60 */ 1070, 1019, 1287, 1019, 1185, 1019, 1019, 1019, 1019, 1019, + /* 70 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 80 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1072, + /* 90 */ 1298, 1298, 1298, 1070, 1019, 1019, 1019, 1019, 1019, 1154, + /* 100 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1362, 1019, 1107, + /* 110 */ 1322, 1019, 1314, 1290, 1304, 1291, 1019, 1347, 1307, 1019, + /* 120 */ 1190, 1187, 1187, 1019, 1019, 1072, 1019, 1019, 1072, 1072, + /* 130 */ 1019, 1072, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 140 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1070, 1019, 1019, + /* 150 */ 1070, 1019, 1329, 1327, 1019, 1329, 1327, 1019, 1019, 1341, + /* 160 */ 1337, 1320, 1318, 1304, 1019, 1019, 1019, 1365, 1353, 1349, + /* 170 */ 1019, 1019, 1327, 1019, 1019, 1327, 1019, 1198, 1019, 1019, + /* 180 */ 1070, 1019, 1070, 1019, 1123, 1019, 1070, 1019, 1157, 1157, + /* 190 */ 1073, 1024, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 200 */ 1019, 1019, 1019, 1252, 1340, 1339, 1251, 1264, 1263, 1262, + /* 210 */ 1019, 1019, 1019, 1246, 1247, 1245, 1244, 1019, 1019, 1019, + /* 220 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1288, 1019, + /* 230 */ 1350, 1354, 1019, 1019, 1019, 1230, 1019, 1019, 1019, 1019, + /* 240 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 250 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 260 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 270 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 280 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 290 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 300 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 310 */ 1019, 1019, 1019, 1311, 1321, 1019, 1019, 1019, 1019, 1019, + /* 320 */ 1019, 1019, 1019, 1019, 1019, 1230, 1019, 1338, 1019, 1297, + /* 330 */ 1293, 1019, 1019, 1289, 1019, 1019, 1348, 1019, 1019, 1019, + /* 340 */ 1019, 1019, 1019, 1019, 1019, 1283, 1019, 1019, 1019, 1019, + /* 350 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 360 */ 1019, 1019, 1229, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 370 */ 1151, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 380 */ 1019, 1019, 1019, 1136, 1134, 1133, 1132, 1019, 1129, 1019, + /* 390 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 400 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 410 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 420 */ 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, 1019, + /* 430 */ 1019, 1019, }; /********** End of lemon-generated parsing tables *****************************/ @@ -826,140 +841,149 @@ static const char *const yyTokenName[] = { /* 122 */ "AS", /* 123 */ "NK_BOOL", /* 124 */ "NK_VARIABLE", - /* 125 */ "BETWEEN", - /* 126 */ "IS", - /* 127 */ "NULL", - /* 128 */ "NK_LT", - /* 129 */ "NK_GT", - /* 130 */ "NK_LE", - /* 131 */ "NK_GE", - /* 132 */ "NK_NE", - /* 133 */ "MATCH", - /* 134 */ "NMATCH", - /* 135 */ "IN", - /* 136 */ "JOIN", - /* 137 */ "INNER", - /* 138 */ "SELECT", - /* 139 */ "DISTINCT", - /* 140 */ "WHERE", - /* 141 */ "PARTITION", - /* 142 */ "BY", - /* 143 */ "SESSION", - /* 144 */ "STATE_WINDOW", - /* 145 */ "SLIDING", - /* 146 */ "FILL", - /* 147 */ "VALUE", - /* 148 */ "NONE", - /* 149 */ "PREV", - /* 150 */ "LINEAR", - /* 151 */ "NEXT", - /* 152 */ "GROUP", - /* 153 */ "HAVING", - /* 154 */ "ORDER", - /* 155 */ "SLIMIT", - /* 156 */ "SOFFSET", - /* 157 */ "LIMIT", - /* 158 */ "OFFSET", - /* 159 */ "ASC", - /* 160 */ "DESC", - /* 161 */ "NULLS", - /* 162 */ "FIRST", - /* 163 */ "LAST", - /* 164 */ "cmd", - /* 165 */ "account_options", - /* 166 */ "alter_account_options", - /* 167 */ "literal", - /* 168 */ "alter_account_option", - /* 169 */ "user_name", - /* 170 */ "dnode_endpoint", - /* 171 */ "dnode_host_name", - /* 172 */ "not_exists_opt", - /* 173 */ "db_name", - /* 174 */ "db_options", - /* 175 */ "exists_opt", - /* 176 */ "alter_db_options", - /* 177 */ "alter_db_option", - /* 178 */ "full_table_name", - /* 179 */ "column_def_list", - /* 180 */ "tags_def_opt", - /* 181 */ "table_options", - /* 182 */ "multi_create_clause", - /* 183 */ "tags_def", - /* 184 */ "multi_drop_clause", - /* 185 */ "alter_table_clause", - /* 186 */ "alter_table_options", - /* 187 */ "column_name", - /* 188 */ "type_name", - /* 189 */ "create_subtable_clause", - /* 190 */ "specific_tags_opt", - /* 191 */ "literal_list", - /* 192 */ "drop_table_clause", - /* 193 */ "col_name_list", - /* 194 */ "table_name", - /* 195 */ "column_def", - /* 196 */ "func_name_list", - /* 197 */ "alter_table_option", - /* 198 */ "col_name", - /* 199 */ "db_name_cond_opt", - /* 200 */ "like_pattern_opt", - /* 201 */ "table_name_cond", - /* 202 */ "from_db_opt", - /* 203 */ "func_name", - /* 204 */ "function_name", - /* 205 */ "index_name", - /* 206 */ "index_options", - /* 207 */ "func_list", - /* 208 */ "duration_literal", - /* 209 */ "sliding_opt", - /* 210 */ "func", - /* 211 */ "expression_list", - /* 212 */ "topic_name", - /* 213 */ "query_expression", - /* 214 */ "signed", - /* 215 */ "signed_literal", - /* 216 */ "table_alias", - /* 217 */ "column_alias", - /* 218 */ "expression", - /* 219 */ "column_reference", - /* 220 */ "subquery", - /* 221 */ "predicate", - /* 222 */ "compare_op", - /* 223 */ "in_op", - /* 224 */ "in_predicate_value", - /* 225 */ "boolean_value_expression", - /* 226 */ "boolean_primary", - /* 227 */ "common_expression", - /* 228 */ "from_clause", - /* 229 */ "table_reference_list", - /* 230 */ "table_reference", - /* 231 */ "table_primary", - /* 232 */ "joined_table", - /* 233 */ "alias_opt", - /* 234 */ "parenthesized_joined_table", - /* 235 */ "join_type", - /* 236 */ "search_condition", - /* 237 */ "query_specification", - /* 238 */ "set_quantifier_opt", - /* 239 */ "select_list", - /* 240 */ "where_clause_opt", - /* 241 */ "partition_by_clause_opt", - /* 242 */ "twindow_clause_opt", - /* 243 */ "group_by_clause_opt", - /* 244 */ "having_clause_opt", - /* 245 */ "select_sublist", - /* 246 */ "select_item", - /* 247 */ "fill_opt", - /* 248 */ "fill_mode", - /* 249 */ "group_by_list", - /* 250 */ "query_expression_body", - /* 251 */ "order_by_clause_opt", - /* 252 */ "slimit_clause_opt", - /* 253 */ "limit_clause_opt", - /* 254 */ "query_primary", - /* 255 */ "sort_specification_list", - /* 256 */ "sort_specification", - /* 257 */ "ordering_specification_opt", - /* 258 */ "null_ordering_opt", + /* 125 */ "NK_UNDERLINE", + /* 126 */ "ROWTS", + /* 127 */ "TBNAME", + /* 128 */ "QSTARTTS", + /* 129 */ "QENDTS", + /* 130 */ "WSTARTTS", + /* 131 */ "WENDTS", + /* 132 */ "WDURATION", + /* 133 */ "BETWEEN", + /* 134 */ "IS", + /* 135 */ "NULL", + /* 136 */ "NK_LT", + /* 137 */ "NK_GT", + /* 138 */ "NK_LE", + /* 139 */ "NK_GE", + /* 140 */ "NK_NE", + /* 141 */ "MATCH", + /* 142 */ "NMATCH", + /* 143 */ "IN", + /* 144 */ "JOIN", + /* 145 */ "INNER", + /* 146 */ "SELECT", + /* 147 */ "DISTINCT", + /* 148 */ "WHERE", + /* 149 */ "PARTITION", + /* 150 */ "BY", + /* 151 */ "SESSION", + /* 152 */ "STATE_WINDOW", + /* 153 */ "SLIDING", + /* 154 */ "FILL", + /* 155 */ "VALUE", + /* 156 */ "NONE", + /* 157 */ "PREV", + /* 158 */ "LINEAR", + /* 159 */ "NEXT", + /* 160 */ "GROUP", + /* 161 */ "HAVING", + /* 162 */ "ORDER", + /* 163 */ "SLIMIT", + /* 164 */ "SOFFSET", + /* 165 */ "LIMIT", + /* 166 */ "OFFSET", + /* 167 */ "ASC", + /* 168 */ "DESC", + /* 169 */ "NULLS", + /* 170 */ "FIRST", + /* 171 */ "LAST", + /* 172 */ "cmd", + /* 173 */ "account_options", + /* 174 */ "alter_account_options", + /* 175 */ "literal", + /* 176 */ "alter_account_option", + /* 177 */ "user_name", + /* 178 */ "dnode_endpoint", + /* 179 */ "dnode_host_name", + /* 180 */ "not_exists_opt", + /* 181 */ "db_name", + /* 182 */ "db_options", + /* 183 */ "exists_opt", + /* 184 */ "alter_db_options", + /* 185 */ "alter_db_option", + /* 186 */ "full_table_name", + /* 187 */ "column_def_list", + /* 188 */ "tags_def_opt", + /* 189 */ "table_options", + /* 190 */ "multi_create_clause", + /* 191 */ "tags_def", + /* 192 */ "multi_drop_clause", + /* 193 */ "alter_table_clause", + /* 194 */ "alter_table_options", + /* 195 */ "column_name", + /* 196 */ "type_name", + /* 197 */ "create_subtable_clause", + /* 198 */ "specific_tags_opt", + /* 199 */ "literal_list", + /* 200 */ "drop_table_clause", + /* 201 */ "col_name_list", + /* 202 */ "table_name", + /* 203 */ "column_def", + /* 204 */ "func_name_list", + /* 205 */ "alter_table_option", + /* 206 */ "col_name", + /* 207 */ "db_name_cond_opt", + /* 208 */ "like_pattern_opt", + /* 209 */ "table_name_cond", + /* 210 */ "from_db_opt", + /* 211 */ "func_name", + /* 212 */ "function_name", + /* 213 */ "index_name", + /* 214 */ "index_options", + /* 215 */ "func_list", + /* 216 */ "duration_literal", + /* 217 */ "sliding_opt", + /* 218 */ "func", + /* 219 */ "expression_list", + /* 220 */ "topic_name", + /* 221 */ "query_expression", + /* 222 */ "signed", + /* 223 */ "signed_literal", + /* 224 */ "table_alias", + /* 225 */ "column_alias", + /* 226 */ "expression", + /* 227 */ "pseudo_column", + /* 228 */ "column_reference", + /* 229 */ "subquery", + /* 230 */ "predicate", + /* 231 */ "compare_op", + /* 232 */ "in_op", + /* 233 */ "in_predicate_value", + /* 234 */ "boolean_value_expression", + /* 235 */ "boolean_primary", + /* 236 */ "common_expression", + /* 237 */ "from_clause", + /* 238 */ "table_reference_list", + /* 239 */ "table_reference", + /* 240 */ "table_primary", + /* 241 */ "joined_table", + /* 242 */ "alias_opt", + /* 243 */ "parenthesized_joined_table", + /* 244 */ "join_type", + /* 245 */ "search_condition", + /* 246 */ "query_specification", + /* 247 */ "set_quantifier_opt", + /* 248 */ "select_list", + /* 249 */ "where_clause_opt", + /* 250 */ "partition_by_clause_opt", + /* 251 */ "twindow_clause_opt", + /* 252 */ "group_by_clause_opt", + /* 253 */ "having_clause_opt", + /* 254 */ "select_sublist", + /* 255 */ "select_item", + /* 256 */ "fill_opt", + /* 257 */ "fill_mode", + /* 258 */ "group_by_list", + /* 259 */ "query_expression_body", + /* 260 */ "order_by_clause_opt", + /* 261 */ "slimit_clause_opt", + /* 262 */ "limit_clause_opt", + /* 263 */ "query_primary", + /* 264 */ "sort_specification_list", + /* 265 */ "sort_specification", + /* 266 */ "ordering_specification_opt", + /* 267 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1183,128 +1207,136 @@ static const char *const yyRuleName[] = { /* 213 */ "index_name ::= NK_ID", /* 214 */ "topic_name ::= NK_ID", /* 215 */ "expression ::= literal", - /* 216 */ "expression ::= column_reference", - /* 217 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 218 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 219 */ "expression ::= subquery", - /* 220 */ "expression ::= NK_LP expression NK_RP", - /* 221 */ "expression ::= NK_PLUS expression", - /* 222 */ "expression ::= NK_MINUS expression", - /* 223 */ "expression ::= expression NK_PLUS expression", - /* 224 */ "expression ::= expression NK_MINUS expression", - /* 225 */ "expression ::= expression NK_STAR expression", - /* 226 */ "expression ::= expression NK_SLASH expression", - /* 227 */ "expression ::= expression NK_REM expression", - /* 228 */ "expression_list ::= expression", - /* 229 */ "expression_list ::= expression_list NK_COMMA expression", - /* 230 */ "column_reference ::= column_name", - /* 231 */ "column_reference ::= table_name NK_DOT column_name", - /* 232 */ "predicate ::= expression compare_op expression", - /* 233 */ "predicate ::= expression BETWEEN expression AND expression", - /* 234 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 235 */ "predicate ::= expression IS NULL", - /* 236 */ "predicate ::= expression IS NOT NULL", - /* 237 */ "predicate ::= expression in_op in_predicate_value", - /* 238 */ "compare_op ::= NK_LT", - /* 239 */ "compare_op ::= NK_GT", - /* 240 */ "compare_op ::= NK_LE", - /* 241 */ "compare_op ::= NK_GE", - /* 242 */ "compare_op ::= NK_NE", - /* 243 */ "compare_op ::= NK_EQ", - /* 244 */ "compare_op ::= LIKE", - /* 245 */ "compare_op ::= NOT LIKE", - /* 246 */ "compare_op ::= MATCH", - /* 247 */ "compare_op ::= NMATCH", - /* 248 */ "in_op ::= IN", - /* 249 */ "in_op ::= NOT IN", - /* 250 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 251 */ "boolean_value_expression ::= boolean_primary", - /* 252 */ "boolean_value_expression ::= NOT boolean_primary", - /* 253 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 254 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 255 */ "boolean_primary ::= predicate", - /* 256 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 257 */ "common_expression ::= expression", - /* 258 */ "common_expression ::= boolean_value_expression", - /* 259 */ "from_clause ::= FROM table_reference_list", - /* 260 */ "table_reference_list ::= table_reference", - /* 261 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 262 */ "table_reference ::= table_primary", - /* 263 */ "table_reference ::= joined_table", - /* 264 */ "table_primary ::= table_name alias_opt", - /* 265 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 266 */ "table_primary ::= subquery alias_opt", - /* 267 */ "table_primary ::= parenthesized_joined_table", - /* 268 */ "alias_opt ::=", - /* 269 */ "alias_opt ::= table_alias", - /* 270 */ "alias_opt ::= AS table_alias", - /* 271 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 272 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 273 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 274 */ "join_type ::=", - /* 275 */ "join_type ::= INNER", - /* 276 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 277 */ "set_quantifier_opt ::=", - /* 278 */ "set_quantifier_opt ::= DISTINCT", - /* 279 */ "set_quantifier_opt ::= ALL", - /* 280 */ "select_list ::= NK_STAR", - /* 281 */ "select_list ::= select_sublist", - /* 282 */ "select_sublist ::= select_item", - /* 283 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 284 */ "select_item ::= common_expression", - /* 285 */ "select_item ::= common_expression column_alias", - /* 286 */ "select_item ::= common_expression AS column_alias", - /* 287 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 288 */ "where_clause_opt ::=", - /* 289 */ "where_clause_opt ::= WHERE search_condition", - /* 290 */ "partition_by_clause_opt ::=", - /* 291 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 292 */ "twindow_clause_opt ::=", - /* 293 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 294 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 295 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 296 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 297 */ "sliding_opt ::=", - /* 298 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 299 */ "fill_opt ::=", - /* 300 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 301 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 302 */ "fill_mode ::= NONE", - /* 303 */ "fill_mode ::= PREV", - /* 304 */ "fill_mode ::= NULL", - /* 305 */ "fill_mode ::= LINEAR", - /* 306 */ "fill_mode ::= NEXT", - /* 307 */ "group_by_clause_opt ::=", - /* 308 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 309 */ "group_by_list ::= expression", - /* 310 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 311 */ "having_clause_opt ::=", - /* 312 */ "having_clause_opt ::= HAVING search_condition", - /* 313 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 314 */ "query_expression_body ::= query_primary", - /* 315 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 316 */ "query_primary ::= query_specification", - /* 317 */ "order_by_clause_opt ::=", - /* 318 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 319 */ "slimit_clause_opt ::=", - /* 320 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 321 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 322 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 323 */ "limit_clause_opt ::=", - /* 324 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 325 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 326 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 327 */ "subquery ::= NK_LP query_expression NK_RP", - /* 328 */ "search_condition ::= common_expression", - /* 329 */ "sort_specification_list ::= sort_specification", - /* 330 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 331 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 332 */ "ordering_specification_opt ::=", - /* 333 */ "ordering_specification_opt ::= ASC", - /* 334 */ "ordering_specification_opt ::= DESC", - /* 335 */ "null_ordering_opt ::=", - /* 336 */ "null_ordering_opt ::= NULLS FIRST", - /* 337 */ "null_ordering_opt ::= NULLS LAST", + /* 216 */ "expression ::= pseudo_column", + /* 217 */ "expression ::= column_reference", + /* 218 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 219 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 220 */ "expression ::= subquery", + /* 221 */ "expression ::= NK_LP expression NK_RP", + /* 222 */ "expression ::= NK_PLUS expression", + /* 223 */ "expression ::= NK_MINUS expression", + /* 224 */ "expression ::= expression NK_PLUS expression", + /* 225 */ "expression ::= expression NK_MINUS expression", + /* 226 */ "expression ::= expression NK_STAR expression", + /* 227 */ "expression ::= expression NK_SLASH expression", + /* 228 */ "expression ::= expression NK_REM expression", + /* 229 */ "expression_list ::= expression", + /* 230 */ "expression_list ::= expression_list NK_COMMA expression", + /* 231 */ "column_reference ::= column_name", + /* 232 */ "column_reference ::= table_name NK_DOT column_name", + /* 233 */ "pseudo_column ::= NK_UNDERLINE ROWTS", + /* 234 */ "pseudo_column ::= TBNAME", + /* 235 */ "pseudo_column ::= NK_UNDERLINE QSTARTTS", + /* 236 */ "pseudo_column ::= NK_UNDERLINE QENDTS", + /* 237 */ "pseudo_column ::= NK_UNDERLINE WSTARTTS", + /* 238 */ "pseudo_column ::= NK_UNDERLINE WENDTS", + /* 239 */ "pseudo_column ::= NK_UNDERLINE WDURATION", + /* 240 */ "predicate ::= expression compare_op expression", + /* 241 */ "predicate ::= expression BETWEEN expression AND expression", + /* 242 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 243 */ "predicate ::= expression IS NULL", + /* 244 */ "predicate ::= expression IS NOT NULL", + /* 245 */ "predicate ::= expression in_op in_predicate_value", + /* 246 */ "compare_op ::= NK_LT", + /* 247 */ "compare_op ::= NK_GT", + /* 248 */ "compare_op ::= NK_LE", + /* 249 */ "compare_op ::= NK_GE", + /* 250 */ "compare_op ::= NK_NE", + /* 251 */ "compare_op ::= NK_EQ", + /* 252 */ "compare_op ::= LIKE", + /* 253 */ "compare_op ::= NOT LIKE", + /* 254 */ "compare_op ::= MATCH", + /* 255 */ "compare_op ::= NMATCH", + /* 256 */ "in_op ::= IN", + /* 257 */ "in_op ::= NOT IN", + /* 258 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 259 */ "boolean_value_expression ::= boolean_primary", + /* 260 */ "boolean_value_expression ::= NOT boolean_primary", + /* 261 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 262 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 263 */ "boolean_primary ::= predicate", + /* 264 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 265 */ "common_expression ::= expression", + /* 266 */ "common_expression ::= boolean_value_expression", + /* 267 */ "from_clause ::= FROM table_reference_list", + /* 268 */ "table_reference_list ::= table_reference", + /* 269 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 270 */ "table_reference ::= table_primary", + /* 271 */ "table_reference ::= joined_table", + /* 272 */ "table_primary ::= table_name alias_opt", + /* 273 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 274 */ "table_primary ::= subquery alias_opt", + /* 275 */ "table_primary ::= parenthesized_joined_table", + /* 276 */ "alias_opt ::=", + /* 277 */ "alias_opt ::= table_alias", + /* 278 */ "alias_opt ::= AS table_alias", + /* 279 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 280 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 281 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 282 */ "join_type ::=", + /* 283 */ "join_type ::= INNER", + /* 284 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 285 */ "set_quantifier_opt ::=", + /* 286 */ "set_quantifier_opt ::= DISTINCT", + /* 287 */ "set_quantifier_opt ::= ALL", + /* 288 */ "select_list ::= NK_STAR", + /* 289 */ "select_list ::= select_sublist", + /* 290 */ "select_sublist ::= select_item", + /* 291 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 292 */ "select_item ::= common_expression", + /* 293 */ "select_item ::= common_expression column_alias", + /* 294 */ "select_item ::= common_expression AS column_alias", + /* 295 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 296 */ "where_clause_opt ::=", + /* 297 */ "where_clause_opt ::= WHERE search_condition", + /* 298 */ "partition_by_clause_opt ::=", + /* 299 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 300 */ "twindow_clause_opt ::=", + /* 301 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 302 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 303 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 304 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 305 */ "sliding_opt ::=", + /* 306 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 307 */ "fill_opt ::=", + /* 308 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 309 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 310 */ "fill_mode ::= NONE", + /* 311 */ "fill_mode ::= PREV", + /* 312 */ "fill_mode ::= NULL", + /* 313 */ "fill_mode ::= LINEAR", + /* 314 */ "fill_mode ::= NEXT", + /* 315 */ "group_by_clause_opt ::=", + /* 316 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 317 */ "group_by_list ::= expression", + /* 318 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 319 */ "having_clause_opt ::=", + /* 320 */ "having_clause_opt ::= HAVING search_condition", + /* 321 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 322 */ "query_expression_body ::= query_primary", + /* 323 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 324 */ "query_primary ::= query_specification", + /* 325 */ "order_by_clause_opt ::=", + /* 326 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 327 */ "slimit_clause_opt ::=", + /* 328 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 329 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 330 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 331 */ "limit_clause_opt ::=", + /* 332 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 333 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 334 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 335 */ "subquery ::= NK_LP query_expression NK_RP", + /* 336 */ "search_condition ::= common_expression", + /* 337 */ "sort_specification_list ::= sort_specification", + /* 338 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 339 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 340 */ "ordering_specification_opt ::=", + /* 341 */ "ordering_specification_opt ::= ASC", + /* 342 */ "ordering_specification_opt ::= DESC", + /* 343 */ "null_ordering_opt ::=", + /* 344 */ "null_ordering_opt ::= NULLS FIRST", + /* 345 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1431,145 +1463,146 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 164: /* cmd */ - case 167: /* literal */ - case 174: /* db_options */ - case 176: /* alter_db_options */ - case 178: /* full_table_name */ - case 181: /* table_options */ - case 185: /* alter_table_clause */ - case 186: /* alter_table_options */ - case 189: /* create_subtable_clause */ - case 192: /* drop_table_clause */ - case 195: /* column_def */ - case 198: /* col_name */ - case 199: /* db_name_cond_opt */ - case 200: /* like_pattern_opt */ - case 201: /* table_name_cond */ - case 202: /* from_db_opt */ - case 203: /* func_name */ - case 206: /* index_options */ - case 208: /* duration_literal */ - case 209: /* sliding_opt */ - case 210: /* func */ - case 213: /* query_expression */ - case 214: /* signed */ - case 215: /* signed_literal */ - case 218: /* expression */ - case 219: /* column_reference */ - case 220: /* subquery */ - case 221: /* predicate */ - case 224: /* in_predicate_value */ - case 225: /* boolean_value_expression */ - case 226: /* boolean_primary */ - case 227: /* common_expression */ - case 228: /* from_clause */ - case 229: /* table_reference_list */ - case 230: /* table_reference */ - case 231: /* table_primary */ - case 232: /* joined_table */ - case 234: /* parenthesized_joined_table */ - case 236: /* search_condition */ - case 237: /* query_specification */ - case 240: /* where_clause_opt */ - case 242: /* twindow_clause_opt */ - case 244: /* having_clause_opt */ - case 246: /* select_item */ - case 247: /* fill_opt */ - case 250: /* query_expression_body */ - case 252: /* slimit_clause_opt */ - case 253: /* limit_clause_opt */ - case 254: /* query_primary */ - case 256: /* sort_specification */ + case 172: /* cmd */ + case 175: /* literal */ + case 182: /* db_options */ + case 184: /* alter_db_options */ + case 186: /* full_table_name */ + case 189: /* table_options */ + case 193: /* alter_table_clause */ + case 194: /* alter_table_options */ + case 197: /* create_subtable_clause */ + case 200: /* drop_table_clause */ + case 203: /* column_def */ + case 206: /* col_name */ + case 207: /* db_name_cond_opt */ + case 208: /* like_pattern_opt */ + case 209: /* table_name_cond */ + case 210: /* from_db_opt */ + case 211: /* func_name */ + case 214: /* index_options */ + case 216: /* duration_literal */ + case 217: /* sliding_opt */ + case 218: /* func */ + case 221: /* query_expression */ + case 222: /* signed */ + case 223: /* signed_literal */ + case 226: /* expression */ + case 227: /* pseudo_column */ + case 228: /* column_reference */ + case 229: /* subquery */ + case 230: /* predicate */ + case 233: /* in_predicate_value */ + case 234: /* boolean_value_expression */ + case 235: /* boolean_primary */ + case 236: /* common_expression */ + case 237: /* from_clause */ + case 238: /* table_reference_list */ + case 239: /* table_reference */ + case 240: /* table_primary */ + case 241: /* joined_table */ + case 243: /* parenthesized_joined_table */ + case 245: /* search_condition */ + case 246: /* query_specification */ + case 249: /* where_clause_opt */ + case 251: /* twindow_clause_opt */ + case 253: /* having_clause_opt */ + case 255: /* select_item */ + case 256: /* fill_opt */ + case 259: /* query_expression_body */ + case 261: /* slimit_clause_opt */ + case 262: /* limit_clause_opt */ + case 263: /* query_primary */ + case 265: /* sort_specification */ { - nodesDestroyNode((yypminor->yy378)); + nodesDestroyNode((yypminor->yy176)); } break; - case 165: /* account_options */ - case 166: /* alter_account_options */ - case 168: /* alter_account_option */ + case 173: /* account_options */ + case 174: /* alter_account_options */ + case 176: /* alter_account_option */ { } break; - case 169: /* user_name */ - case 170: /* dnode_endpoint */ - case 171: /* dnode_host_name */ - case 173: /* db_name */ - case 187: /* column_name */ - case 194: /* table_name */ - case 204: /* function_name */ - case 205: /* index_name */ - case 212: /* topic_name */ - case 216: /* table_alias */ - case 217: /* column_alias */ - case 233: /* alias_opt */ + case 177: /* user_name */ + case 178: /* dnode_endpoint */ + case 179: /* dnode_host_name */ + case 181: /* db_name */ + case 195: /* column_name */ + case 202: /* table_name */ + case 212: /* function_name */ + case 213: /* index_name */ + case 220: /* topic_name */ + case 224: /* table_alias */ + case 225: /* column_alias */ + case 242: /* alias_opt */ { } break; - case 172: /* not_exists_opt */ - case 175: /* exists_opt */ - case 238: /* set_quantifier_opt */ + case 180: /* not_exists_opt */ + case 183: /* exists_opt */ + case 247: /* set_quantifier_opt */ { } break; - case 177: /* alter_db_option */ - case 197: /* alter_table_option */ + case 185: /* alter_db_option */ + case 205: /* alter_table_option */ { } break; - case 179: /* column_def_list */ - case 180: /* tags_def_opt */ - case 182: /* multi_create_clause */ - case 183: /* tags_def */ - case 184: /* multi_drop_clause */ - case 190: /* specific_tags_opt */ - case 191: /* literal_list */ - case 193: /* col_name_list */ - case 196: /* func_name_list */ - case 207: /* func_list */ - case 211: /* expression_list */ - case 239: /* select_list */ - case 241: /* partition_by_clause_opt */ - case 243: /* group_by_clause_opt */ - case 245: /* select_sublist */ - case 249: /* group_by_list */ - case 251: /* order_by_clause_opt */ - case 255: /* sort_specification_list */ + case 187: /* column_def_list */ + case 188: /* tags_def_opt */ + case 190: /* multi_create_clause */ + case 191: /* tags_def */ + case 192: /* multi_drop_clause */ + case 198: /* specific_tags_opt */ + case 199: /* literal_list */ + case 201: /* col_name_list */ + case 204: /* func_name_list */ + case 215: /* func_list */ + case 219: /* expression_list */ + case 248: /* select_list */ + case 250: /* partition_by_clause_opt */ + case 252: /* group_by_clause_opt */ + case 254: /* select_sublist */ + case 258: /* group_by_list */ + case 260: /* order_by_clause_opt */ + case 264: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy404)); + nodesDestroyList((yypminor->yy512)); } break; - case 188: /* type_name */ + case 196: /* type_name */ { } break; - case 222: /* compare_op */ - case 223: /* in_op */ + case 231: /* compare_op */ + case 232: /* in_op */ { } break; - case 235: /* join_type */ + case 244: /* join_type */ { } break; - case 248: /* fill_mode */ + case 257: /* fill_mode */ { } break; - case 257: /* ordering_specification_opt */ + case 266: /* ordering_specification_opt */ { } break; - case 258: /* null_ordering_opt */ + case 267: /* null_ordering_opt */ { } @@ -1868,344 +1901,352 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 164, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 164, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 165, 0 }, /* (2) account_options ::= */ - { 165, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 165, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 165, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 165, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 165, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 165, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 165, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 165, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 165, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 166, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 166, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 168, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 168, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 168, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 168, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 168, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 168, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 168, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 168, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 168, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 168, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 164, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 164, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 164, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 164, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 164, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 164, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 164, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 164, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 164, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 164, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 164, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 164, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 170, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 171, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 171, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 164, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 164, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 164, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 164, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 164, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 164, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ - { 164, -2 }, /* (45) cmd ::= USE db_name */ - { 164, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 172, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ - { 172, 0 }, /* (48) not_exists_opt ::= */ - { 175, -2 }, /* (49) exists_opt ::= IF EXISTS */ - { 175, 0 }, /* (50) exists_opt ::= */ - { 174, 0 }, /* (51) db_options ::= */ - { 174, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ - { 174, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ - { 174, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ - { 174, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ - { 174, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ - { 174, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ - { 174, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ - { 174, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ - { 174, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ - { 174, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ - { 174, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ - { 174, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ - { 174, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ - { 174, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ - { 174, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ - { 174, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 174, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 174, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ - { 176, -1 }, /* (70) alter_db_options ::= alter_db_option */ - { 176, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ - { 177, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ - { 177, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ - { 177, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ - { 177, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ - { 177, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ - { 177, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ - { 164, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 164, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ - { 164, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 164, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ - { 164, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ - { 164, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ - { 164, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ - { 185, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ - { 185, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 185, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 185, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 185, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 185, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 185, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 185, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 185, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 185, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 182, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ - { 182, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 189, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 184, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ - { 184, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 192, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ - { 190, 0 }, /* (101) specific_tags_opt ::= */ - { 190, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 178, -1 }, /* (103) full_table_name ::= table_name */ - { 178, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ - { 179, -1 }, /* (105) column_def_list ::= column_def */ - { 179, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ - { 195, -2 }, /* (107) column_def ::= column_name type_name */ - { 195, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ - { 188, -1 }, /* (109) type_name ::= BOOL */ - { 188, -1 }, /* (110) type_name ::= TINYINT */ - { 188, -1 }, /* (111) type_name ::= SMALLINT */ - { 188, -1 }, /* (112) type_name ::= INT */ - { 188, -1 }, /* (113) type_name ::= INTEGER */ - { 188, -1 }, /* (114) type_name ::= BIGINT */ - { 188, -1 }, /* (115) type_name ::= FLOAT */ - { 188, -1 }, /* (116) type_name ::= DOUBLE */ - { 188, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (118) type_name ::= TIMESTAMP */ - { 188, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 188, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ - { 188, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ - { 188, -2 }, /* (122) type_name ::= INT UNSIGNED */ - { 188, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ - { 188, -1 }, /* (124) type_name ::= JSON */ - { 188, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (126) type_name ::= MEDIUMBLOB */ - { 188, -1 }, /* (127) type_name ::= BLOB */ - { 188, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 188, -1 }, /* (129) type_name ::= DECIMAL */ - { 188, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 188, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 180, 0 }, /* (132) tags_def_opt ::= */ - { 180, -1 }, /* (133) tags_def_opt ::= tags_def */ - { 183, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 181, 0 }, /* (135) table_options ::= */ - { 181, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ - { 181, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ - { 181, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ - { 181, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 181, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 181, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 181, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ - { 186, -1 }, /* (143) alter_table_options ::= alter_table_option */ - { 186, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ - { 197, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ - { 197, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ - { 197, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ - { 193, -1 }, /* (148) col_name_list ::= col_name */ - { 193, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ - { 198, -1 }, /* (150) col_name ::= column_name */ - { 164, -2 }, /* (151) cmd ::= SHOW DNODES */ - { 164, -2 }, /* (152) cmd ::= SHOW USERS */ - { 164, -2 }, /* (153) cmd ::= SHOW DATABASES */ - { 164, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 164, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 164, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 164, -2 }, /* (157) cmd ::= SHOW MNODES */ - { 164, -2 }, /* (158) cmd ::= SHOW MODULES */ - { 164, -2 }, /* (159) cmd ::= SHOW QNODES */ - { 164, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ - { 164, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 164, -2 }, /* (162) cmd ::= SHOW STREAMS */ - { 199, 0 }, /* (163) db_name_cond_opt ::= */ - { 199, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ - { 200, 0 }, /* (165) like_pattern_opt ::= */ - { 200, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ - { 201, -1 }, /* (167) table_name_cond ::= table_name */ - { 202, 0 }, /* (168) from_db_opt ::= */ - { 202, -2 }, /* (169) from_db_opt ::= FROM db_name */ - { 196, -1 }, /* (170) func_name_list ::= func_name */ - { 196, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ - { 203, -1 }, /* (172) func_name ::= function_name */ - { 164, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 164, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 164, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 206, 0 }, /* (176) index_options ::= */ - { 206, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 206, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 207, -1 }, /* (179) func_list ::= func */ - { 207, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ - { 210, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ - { 164, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 164, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 164, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ - { 164, -1 }, /* (185) cmd ::= query_expression */ - { 167, -1 }, /* (186) literal ::= NK_INTEGER */ - { 167, -1 }, /* (187) literal ::= NK_FLOAT */ - { 167, -1 }, /* (188) literal ::= NK_STRING */ - { 167, -1 }, /* (189) literal ::= NK_BOOL */ - { 167, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ - { 167, -1 }, /* (191) literal ::= duration_literal */ - { 208, -1 }, /* (192) duration_literal ::= NK_VARIABLE */ - { 214, -1 }, /* (193) signed ::= NK_INTEGER */ - { 214, -2 }, /* (194) signed ::= NK_PLUS NK_INTEGER */ - { 214, -2 }, /* (195) signed ::= NK_MINUS NK_INTEGER */ - { 214, -1 }, /* (196) signed ::= NK_FLOAT */ - { 214, -2 }, /* (197) signed ::= NK_PLUS NK_FLOAT */ - { 214, -2 }, /* (198) signed ::= NK_MINUS NK_FLOAT */ - { 215, -1 }, /* (199) signed_literal ::= signed */ - { 215, -1 }, /* (200) signed_literal ::= NK_STRING */ - { 215, -1 }, /* (201) signed_literal ::= NK_BOOL */ - { 215, -2 }, /* (202) signed_literal ::= TIMESTAMP NK_STRING */ - { 215, -1 }, /* (203) signed_literal ::= duration_literal */ - { 191, -1 }, /* (204) literal_list ::= signed_literal */ - { 191, -3 }, /* (205) literal_list ::= literal_list NK_COMMA signed_literal */ - { 173, -1 }, /* (206) db_name ::= NK_ID */ - { 194, -1 }, /* (207) table_name ::= NK_ID */ - { 187, -1 }, /* (208) column_name ::= NK_ID */ - { 204, -1 }, /* (209) function_name ::= NK_ID */ - { 216, -1 }, /* (210) table_alias ::= NK_ID */ - { 217, -1 }, /* (211) column_alias ::= NK_ID */ - { 169, -1 }, /* (212) user_name ::= NK_ID */ - { 205, -1 }, /* (213) index_name ::= NK_ID */ - { 212, -1 }, /* (214) topic_name ::= NK_ID */ - { 218, -1 }, /* (215) expression ::= literal */ - { 218, -1 }, /* (216) expression ::= column_reference */ - { 218, -4 }, /* (217) expression ::= function_name NK_LP expression_list NK_RP */ - { 218, -4 }, /* (218) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 218, -1 }, /* (219) expression ::= subquery */ - { 218, -3 }, /* (220) expression ::= NK_LP expression NK_RP */ - { 218, -2 }, /* (221) expression ::= NK_PLUS expression */ - { 218, -2 }, /* (222) expression ::= NK_MINUS expression */ - { 218, -3 }, /* (223) expression ::= expression NK_PLUS expression */ - { 218, -3 }, /* (224) expression ::= expression NK_MINUS expression */ - { 218, -3 }, /* (225) expression ::= expression NK_STAR expression */ - { 218, -3 }, /* (226) expression ::= expression NK_SLASH expression */ - { 218, -3 }, /* (227) expression ::= expression NK_REM expression */ - { 211, -1 }, /* (228) expression_list ::= expression */ - { 211, -3 }, /* (229) expression_list ::= expression_list NK_COMMA expression */ - { 219, -1 }, /* (230) column_reference ::= column_name */ - { 219, -3 }, /* (231) column_reference ::= table_name NK_DOT column_name */ - { 221, -3 }, /* (232) predicate ::= expression compare_op expression */ - { 221, -5 }, /* (233) predicate ::= expression BETWEEN expression AND expression */ - { 221, -6 }, /* (234) predicate ::= expression NOT BETWEEN expression AND expression */ - { 221, -3 }, /* (235) predicate ::= expression IS NULL */ - { 221, -4 }, /* (236) predicate ::= expression IS NOT NULL */ - { 221, -3 }, /* (237) predicate ::= expression in_op in_predicate_value */ - { 222, -1 }, /* (238) compare_op ::= NK_LT */ - { 222, -1 }, /* (239) compare_op ::= NK_GT */ - { 222, -1 }, /* (240) compare_op ::= NK_LE */ - { 222, -1 }, /* (241) compare_op ::= NK_GE */ - { 222, -1 }, /* (242) compare_op ::= NK_NE */ - { 222, -1 }, /* (243) compare_op ::= NK_EQ */ - { 222, -1 }, /* (244) compare_op ::= LIKE */ - { 222, -2 }, /* (245) compare_op ::= NOT LIKE */ - { 222, -1 }, /* (246) compare_op ::= MATCH */ - { 222, -1 }, /* (247) compare_op ::= NMATCH */ - { 223, -1 }, /* (248) in_op ::= IN */ - { 223, -2 }, /* (249) in_op ::= NOT IN */ - { 224, -3 }, /* (250) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 225, -1 }, /* (251) boolean_value_expression ::= boolean_primary */ - { 225, -2 }, /* (252) boolean_value_expression ::= NOT boolean_primary */ - { 225, -3 }, /* (253) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 225, -3 }, /* (254) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 226, -1 }, /* (255) boolean_primary ::= predicate */ - { 226, -3 }, /* (256) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 227, -1 }, /* (257) common_expression ::= expression */ - { 227, -1 }, /* (258) common_expression ::= boolean_value_expression */ - { 228, -2 }, /* (259) from_clause ::= FROM table_reference_list */ - { 229, -1 }, /* (260) table_reference_list ::= table_reference */ - { 229, -3 }, /* (261) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 230, -1 }, /* (262) table_reference ::= table_primary */ - { 230, -1 }, /* (263) table_reference ::= joined_table */ - { 231, -2 }, /* (264) table_primary ::= table_name alias_opt */ - { 231, -4 }, /* (265) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 231, -2 }, /* (266) table_primary ::= subquery alias_opt */ - { 231, -1 }, /* (267) table_primary ::= parenthesized_joined_table */ - { 233, 0 }, /* (268) alias_opt ::= */ - { 233, -1 }, /* (269) alias_opt ::= table_alias */ - { 233, -2 }, /* (270) alias_opt ::= AS table_alias */ - { 234, -3 }, /* (271) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 234, -3 }, /* (272) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 232, -6 }, /* (273) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 235, 0 }, /* (274) join_type ::= */ - { 235, -1 }, /* (275) join_type ::= INNER */ - { 237, -9 }, /* (276) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 238, 0 }, /* (277) set_quantifier_opt ::= */ - { 238, -1 }, /* (278) set_quantifier_opt ::= DISTINCT */ - { 238, -1 }, /* (279) set_quantifier_opt ::= ALL */ - { 239, -1 }, /* (280) select_list ::= NK_STAR */ - { 239, -1 }, /* (281) select_list ::= select_sublist */ - { 245, -1 }, /* (282) select_sublist ::= select_item */ - { 245, -3 }, /* (283) select_sublist ::= select_sublist NK_COMMA select_item */ - { 246, -1 }, /* (284) select_item ::= common_expression */ - { 246, -2 }, /* (285) select_item ::= common_expression column_alias */ - { 246, -3 }, /* (286) select_item ::= common_expression AS column_alias */ - { 246, -3 }, /* (287) select_item ::= table_name NK_DOT NK_STAR */ - { 240, 0 }, /* (288) where_clause_opt ::= */ - { 240, -2 }, /* (289) where_clause_opt ::= WHERE search_condition */ - { 241, 0 }, /* (290) partition_by_clause_opt ::= */ - { 241, -3 }, /* (291) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 242, 0 }, /* (292) twindow_clause_opt ::= */ - { 242, -6 }, /* (293) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 242, -4 }, /* (294) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 242, -6 }, /* (295) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 242, -8 }, /* (296) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 209, 0 }, /* (297) sliding_opt ::= */ - { 209, -4 }, /* (298) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 247, 0 }, /* (299) fill_opt ::= */ - { 247, -4 }, /* (300) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 247, -6 }, /* (301) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 248, -1 }, /* (302) fill_mode ::= NONE */ - { 248, -1 }, /* (303) fill_mode ::= PREV */ - { 248, -1 }, /* (304) fill_mode ::= NULL */ - { 248, -1 }, /* (305) fill_mode ::= LINEAR */ - { 248, -1 }, /* (306) fill_mode ::= NEXT */ - { 243, 0 }, /* (307) group_by_clause_opt ::= */ - { 243, -3 }, /* (308) group_by_clause_opt ::= GROUP BY group_by_list */ - { 249, -1 }, /* (309) group_by_list ::= expression */ - { 249, -3 }, /* (310) group_by_list ::= group_by_list NK_COMMA expression */ - { 244, 0 }, /* (311) having_clause_opt ::= */ - { 244, -2 }, /* (312) having_clause_opt ::= HAVING search_condition */ - { 213, -4 }, /* (313) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 250, -1 }, /* (314) query_expression_body ::= query_primary */ - { 250, -4 }, /* (315) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 254, -1 }, /* (316) query_primary ::= query_specification */ - { 251, 0 }, /* (317) order_by_clause_opt ::= */ - { 251, -3 }, /* (318) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 252, 0 }, /* (319) slimit_clause_opt ::= */ - { 252, -2 }, /* (320) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 252, -4 }, /* (321) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 252, -4 }, /* (322) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 253, 0 }, /* (323) limit_clause_opt ::= */ - { 253, -2 }, /* (324) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 253, -4 }, /* (325) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 253, -4 }, /* (326) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 220, -3 }, /* (327) subquery ::= NK_LP query_expression NK_RP */ - { 236, -1 }, /* (328) search_condition ::= common_expression */ - { 255, -1 }, /* (329) sort_specification_list ::= sort_specification */ - { 255, -3 }, /* (330) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 256, -3 }, /* (331) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 257, 0 }, /* (332) ordering_specification_opt ::= */ - { 257, -1 }, /* (333) ordering_specification_opt ::= ASC */ - { 257, -1 }, /* (334) ordering_specification_opt ::= DESC */ - { 258, 0 }, /* (335) null_ordering_opt ::= */ - { 258, -2 }, /* (336) null_ordering_opt ::= NULLS FIRST */ - { 258, -2 }, /* (337) null_ordering_opt ::= NULLS LAST */ + { 172, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 172, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 173, 0 }, /* (2) account_options ::= */ + { 173, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 173, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 173, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 173, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 173, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 173, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 173, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 173, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 173, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 174, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 174, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 176, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 176, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 176, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 176, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 176, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 176, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 176, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 176, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 176, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 176, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 172, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 172, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 172, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 172, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 172, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 172, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 172, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 172, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 172, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 172, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 172, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 172, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 178, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 179, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 179, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 172, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 172, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 172, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 172, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 172, -5 }, /* (43) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 172, -4 }, /* (44) cmd ::= DROP DATABASE exists_opt db_name */ + { 172, -2 }, /* (45) cmd ::= USE db_name */ + { 172, -4 }, /* (46) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 180, -3 }, /* (47) not_exists_opt ::= IF NOT EXISTS */ + { 180, 0 }, /* (48) not_exists_opt ::= */ + { 183, -2 }, /* (49) exists_opt ::= IF EXISTS */ + { 183, 0 }, /* (50) exists_opt ::= */ + { 182, 0 }, /* (51) db_options ::= */ + { 182, -3 }, /* (52) db_options ::= db_options BLOCKS NK_INTEGER */ + { 182, -3 }, /* (53) db_options ::= db_options CACHE NK_INTEGER */ + { 182, -3 }, /* (54) db_options ::= db_options CACHELAST NK_INTEGER */ + { 182, -3 }, /* (55) db_options ::= db_options COMP NK_INTEGER */ + { 182, -3 }, /* (56) db_options ::= db_options DAYS NK_INTEGER */ + { 182, -3 }, /* (57) db_options ::= db_options FSYNC NK_INTEGER */ + { 182, -3 }, /* (58) db_options ::= db_options MAXROWS NK_INTEGER */ + { 182, -3 }, /* (59) db_options ::= db_options MINROWS NK_INTEGER */ + { 182, -3 }, /* (60) db_options ::= db_options KEEP NK_INTEGER */ + { 182, -3 }, /* (61) db_options ::= db_options PRECISION NK_STRING */ + { 182, -3 }, /* (62) db_options ::= db_options QUORUM NK_INTEGER */ + { 182, -3 }, /* (63) db_options ::= db_options REPLICA NK_INTEGER */ + { 182, -3 }, /* (64) db_options ::= db_options TTL NK_INTEGER */ + { 182, -3 }, /* (65) db_options ::= db_options WAL NK_INTEGER */ + { 182, -3 }, /* (66) db_options ::= db_options VGROUPS NK_INTEGER */ + { 182, -3 }, /* (67) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 182, -3 }, /* (68) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 182, -3 }, /* (69) db_options ::= db_options RETENTIONS NK_STRING */ + { 184, -1 }, /* (70) alter_db_options ::= alter_db_option */ + { 184, -2 }, /* (71) alter_db_options ::= alter_db_options alter_db_option */ + { 185, -2 }, /* (72) alter_db_option ::= BLOCKS NK_INTEGER */ + { 185, -2 }, /* (73) alter_db_option ::= FSYNC NK_INTEGER */ + { 185, -2 }, /* (74) alter_db_option ::= KEEP NK_INTEGER */ + { 185, -2 }, /* (75) alter_db_option ::= WAL NK_INTEGER */ + { 185, -2 }, /* (76) alter_db_option ::= QUORUM NK_INTEGER */ + { 185, -2 }, /* (77) alter_db_option ::= CACHELAST NK_INTEGER */ + { 172, -9 }, /* (78) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 172, -3 }, /* (79) cmd ::= CREATE TABLE multi_create_clause */ + { 172, -9 }, /* (80) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 172, -3 }, /* (81) cmd ::= DROP TABLE multi_drop_clause */ + { 172, -4 }, /* (82) cmd ::= DROP STABLE exists_opt full_table_name */ + { 172, -3 }, /* (83) cmd ::= ALTER TABLE alter_table_clause */ + { 172, -3 }, /* (84) cmd ::= ALTER STABLE alter_table_clause */ + { 193, -2 }, /* (85) alter_table_clause ::= full_table_name alter_table_options */ + { 193, -5 }, /* (86) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 193, -4 }, /* (87) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 193, -5 }, /* (88) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 193, -5 }, /* (89) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 193, -5 }, /* (90) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 193, -4 }, /* (91) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 193, -5 }, /* (92) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 193, -5 }, /* (93) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 193, -6 }, /* (94) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 190, -1 }, /* (95) multi_create_clause ::= create_subtable_clause */ + { 190, -2 }, /* (96) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 197, -9 }, /* (97) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 192, -1 }, /* (98) multi_drop_clause ::= drop_table_clause */ + { 192, -2 }, /* (99) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 200, -2 }, /* (100) drop_table_clause ::= exists_opt full_table_name */ + { 198, 0 }, /* (101) specific_tags_opt ::= */ + { 198, -3 }, /* (102) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 186, -1 }, /* (103) full_table_name ::= table_name */ + { 186, -3 }, /* (104) full_table_name ::= db_name NK_DOT table_name */ + { 187, -1 }, /* (105) column_def_list ::= column_def */ + { 187, -3 }, /* (106) column_def_list ::= column_def_list NK_COMMA column_def */ + { 203, -2 }, /* (107) column_def ::= column_name type_name */ + { 203, -4 }, /* (108) column_def ::= column_name type_name COMMENT NK_STRING */ + { 196, -1 }, /* (109) type_name ::= BOOL */ + { 196, -1 }, /* (110) type_name ::= TINYINT */ + { 196, -1 }, /* (111) type_name ::= SMALLINT */ + { 196, -1 }, /* (112) type_name ::= INT */ + { 196, -1 }, /* (113) type_name ::= INTEGER */ + { 196, -1 }, /* (114) type_name ::= BIGINT */ + { 196, -1 }, /* (115) type_name ::= FLOAT */ + { 196, -1 }, /* (116) type_name ::= DOUBLE */ + { 196, -4 }, /* (117) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (118) type_name ::= TIMESTAMP */ + { 196, -4 }, /* (119) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 196, -2 }, /* (120) type_name ::= TINYINT UNSIGNED */ + { 196, -2 }, /* (121) type_name ::= SMALLINT UNSIGNED */ + { 196, -2 }, /* (122) type_name ::= INT UNSIGNED */ + { 196, -2 }, /* (123) type_name ::= BIGINT UNSIGNED */ + { 196, -1 }, /* (124) type_name ::= JSON */ + { 196, -4 }, /* (125) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (126) type_name ::= MEDIUMBLOB */ + { 196, -1 }, /* (127) type_name ::= BLOB */ + { 196, -4 }, /* (128) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 196, -1 }, /* (129) type_name ::= DECIMAL */ + { 196, -4 }, /* (130) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 196, -6 }, /* (131) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 188, 0 }, /* (132) tags_def_opt ::= */ + { 188, -1 }, /* (133) tags_def_opt ::= tags_def */ + { 191, -4 }, /* (134) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 189, 0 }, /* (135) table_options ::= */ + { 189, -3 }, /* (136) table_options ::= table_options COMMENT NK_STRING */ + { 189, -3 }, /* (137) table_options ::= table_options KEEP NK_INTEGER */ + { 189, -3 }, /* (138) table_options ::= table_options TTL NK_INTEGER */ + { 189, -5 }, /* (139) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 189, -5 }, /* (140) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 189, -3 }, /* (141) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 189, -3 }, /* (142) table_options ::= table_options DELAY NK_INTEGER */ + { 194, -1 }, /* (143) alter_table_options ::= alter_table_option */ + { 194, -2 }, /* (144) alter_table_options ::= alter_table_options alter_table_option */ + { 205, -2 }, /* (145) alter_table_option ::= COMMENT NK_STRING */ + { 205, -2 }, /* (146) alter_table_option ::= KEEP NK_INTEGER */ + { 205, -2 }, /* (147) alter_table_option ::= TTL NK_INTEGER */ + { 201, -1 }, /* (148) col_name_list ::= col_name */ + { 201, -3 }, /* (149) col_name_list ::= col_name_list NK_COMMA col_name */ + { 206, -1 }, /* (150) col_name ::= column_name */ + { 172, -2 }, /* (151) cmd ::= SHOW DNODES */ + { 172, -2 }, /* (152) cmd ::= SHOW USERS */ + { 172, -2 }, /* (153) cmd ::= SHOW DATABASES */ + { 172, -4 }, /* (154) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 172, -4 }, /* (155) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 172, -3 }, /* (156) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 172, -2 }, /* (157) cmd ::= SHOW MNODES */ + { 172, -2 }, /* (158) cmd ::= SHOW MODULES */ + { 172, -2 }, /* (159) cmd ::= SHOW QNODES */ + { 172, -2 }, /* (160) cmd ::= SHOW FUNCTIONS */ + { 172, -5 }, /* (161) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 172, -2 }, /* (162) cmd ::= SHOW STREAMS */ + { 207, 0 }, /* (163) db_name_cond_opt ::= */ + { 207, -2 }, /* (164) db_name_cond_opt ::= db_name NK_DOT */ + { 208, 0 }, /* (165) like_pattern_opt ::= */ + { 208, -2 }, /* (166) like_pattern_opt ::= LIKE NK_STRING */ + { 209, -1 }, /* (167) table_name_cond ::= table_name */ + { 210, 0 }, /* (168) from_db_opt ::= */ + { 210, -2 }, /* (169) from_db_opt ::= FROM db_name */ + { 204, -1 }, /* (170) func_name_list ::= func_name */ + { 204, -3 }, /* (171) func_name_list ::= func_name_list NK_COMMA col_name */ + { 211, -1 }, /* (172) func_name ::= function_name */ + { 172, -8 }, /* (173) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 172, -10 }, /* (174) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 172, -6 }, /* (175) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 214, 0 }, /* (176) index_options ::= */ + { 214, -9 }, /* (177) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 214, -11 }, /* (178) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 215, -1 }, /* (179) func_list ::= func */ + { 215, -3 }, /* (180) func_list ::= func_list NK_COMMA func */ + { 218, -4 }, /* (181) func ::= function_name NK_LP expression_list NK_RP */ + { 172, -6 }, /* (182) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 172, -6 }, /* (183) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 172, -4 }, /* (184) cmd ::= DROP TOPIC exists_opt topic_name */ + { 172, -1 }, /* (185) cmd ::= query_expression */ + { 175, -1 }, /* (186) literal ::= NK_INTEGER */ + { 175, -1 }, /* (187) literal ::= NK_FLOAT */ + { 175, -1 }, /* (188) literal ::= NK_STRING */ + { 175, -1 }, /* (189) literal ::= NK_BOOL */ + { 175, -2 }, /* (190) literal ::= TIMESTAMP NK_STRING */ + { 175, -1 }, /* (191) literal ::= duration_literal */ + { 216, -1 }, /* (192) duration_literal ::= NK_VARIABLE */ + { 222, -1 }, /* (193) signed ::= NK_INTEGER */ + { 222, -2 }, /* (194) signed ::= NK_PLUS NK_INTEGER */ + { 222, -2 }, /* (195) signed ::= NK_MINUS NK_INTEGER */ + { 222, -1 }, /* (196) signed ::= NK_FLOAT */ + { 222, -2 }, /* (197) signed ::= NK_PLUS NK_FLOAT */ + { 222, -2 }, /* (198) signed ::= NK_MINUS NK_FLOAT */ + { 223, -1 }, /* (199) signed_literal ::= signed */ + { 223, -1 }, /* (200) signed_literal ::= NK_STRING */ + { 223, -1 }, /* (201) signed_literal ::= NK_BOOL */ + { 223, -2 }, /* (202) signed_literal ::= TIMESTAMP NK_STRING */ + { 223, -1 }, /* (203) signed_literal ::= duration_literal */ + { 199, -1 }, /* (204) literal_list ::= signed_literal */ + { 199, -3 }, /* (205) literal_list ::= literal_list NK_COMMA signed_literal */ + { 181, -1 }, /* (206) db_name ::= NK_ID */ + { 202, -1 }, /* (207) table_name ::= NK_ID */ + { 195, -1 }, /* (208) column_name ::= NK_ID */ + { 212, -1 }, /* (209) function_name ::= NK_ID */ + { 224, -1 }, /* (210) table_alias ::= NK_ID */ + { 225, -1 }, /* (211) column_alias ::= NK_ID */ + { 177, -1 }, /* (212) user_name ::= NK_ID */ + { 213, -1 }, /* (213) index_name ::= NK_ID */ + { 220, -1 }, /* (214) topic_name ::= NK_ID */ + { 226, -1 }, /* (215) expression ::= literal */ + { 226, -1 }, /* (216) expression ::= pseudo_column */ + { 226, -1 }, /* (217) expression ::= column_reference */ + { 226, -4 }, /* (218) expression ::= function_name NK_LP expression_list NK_RP */ + { 226, -4 }, /* (219) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 226, -1 }, /* (220) expression ::= subquery */ + { 226, -3 }, /* (221) expression ::= NK_LP expression NK_RP */ + { 226, -2 }, /* (222) expression ::= NK_PLUS expression */ + { 226, -2 }, /* (223) expression ::= NK_MINUS expression */ + { 226, -3 }, /* (224) expression ::= expression NK_PLUS expression */ + { 226, -3 }, /* (225) expression ::= expression NK_MINUS expression */ + { 226, -3 }, /* (226) expression ::= expression NK_STAR expression */ + { 226, -3 }, /* (227) expression ::= expression NK_SLASH expression */ + { 226, -3 }, /* (228) expression ::= expression NK_REM expression */ + { 219, -1 }, /* (229) expression_list ::= expression */ + { 219, -3 }, /* (230) expression_list ::= expression_list NK_COMMA expression */ + { 228, -1 }, /* (231) column_reference ::= column_name */ + { 228, -3 }, /* (232) column_reference ::= table_name NK_DOT column_name */ + { 227, -2 }, /* (233) pseudo_column ::= NK_UNDERLINE ROWTS */ + { 227, -1 }, /* (234) pseudo_column ::= TBNAME */ + { 227, -2 }, /* (235) pseudo_column ::= NK_UNDERLINE QSTARTTS */ + { 227, -2 }, /* (236) pseudo_column ::= NK_UNDERLINE QENDTS */ + { 227, -2 }, /* (237) pseudo_column ::= NK_UNDERLINE WSTARTTS */ + { 227, -2 }, /* (238) pseudo_column ::= NK_UNDERLINE WENDTS */ + { 227, -2 }, /* (239) pseudo_column ::= NK_UNDERLINE WDURATION */ + { 230, -3 }, /* (240) predicate ::= expression compare_op expression */ + { 230, -5 }, /* (241) predicate ::= expression BETWEEN expression AND expression */ + { 230, -6 }, /* (242) predicate ::= expression NOT BETWEEN expression AND expression */ + { 230, -3 }, /* (243) predicate ::= expression IS NULL */ + { 230, -4 }, /* (244) predicate ::= expression IS NOT NULL */ + { 230, -3 }, /* (245) predicate ::= expression in_op in_predicate_value */ + { 231, -1 }, /* (246) compare_op ::= NK_LT */ + { 231, -1 }, /* (247) compare_op ::= NK_GT */ + { 231, -1 }, /* (248) compare_op ::= NK_LE */ + { 231, -1 }, /* (249) compare_op ::= NK_GE */ + { 231, -1 }, /* (250) compare_op ::= NK_NE */ + { 231, -1 }, /* (251) compare_op ::= NK_EQ */ + { 231, -1 }, /* (252) compare_op ::= LIKE */ + { 231, -2 }, /* (253) compare_op ::= NOT LIKE */ + { 231, -1 }, /* (254) compare_op ::= MATCH */ + { 231, -1 }, /* (255) compare_op ::= NMATCH */ + { 232, -1 }, /* (256) in_op ::= IN */ + { 232, -2 }, /* (257) in_op ::= NOT IN */ + { 233, -3 }, /* (258) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 234, -1 }, /* (259) boolean_value_expression ::= boolean_primary */ + { 234, -2 }, /* (260) boolean_value_expression ::= NOT boolean_primary */ + { 234, -3 }, /* (261) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 234, -3 }, /* (262) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 235, -1 }, /* (263) boolean_primary ::= predicate */ + { 235, -3 }, /* (264) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 236, -1 }, /* (265) common_expression ::= expression */ + { 236, -1 }, /* (266) common_expression ::= boolean_value_expression */ + { 237, -2 }, /* (267) from_clause ::= FROM table_reference_list */ + { 238, -1 }, /* (268) table_reference_list ::= table_reference */ + { 238, -3 }, /* (269) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 239, -1 }, /* (270) table_reference ::= table_primary */ + { 239, -1 }, /* (271) table_reference ::= joined_table */ + { 240, -2 }, /* (272) table_primary ::= table_name alias_opt */ + { 240, -4 }, /* (273) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 240, -2 }, /* (274) table_primary ::= subquery alias_opt */ + { 240, -1 }, /* (275) table_primary ::= parenthesized_joined_table */ + { 242, 0 }, /* (276) alias_opt ::= */ + { 242, -1 }, /* (277) alias_opt ::= table_alias */ + { 242, -2 }, /* (278) alias_opt ::= AS table_alias */ + { 243, -3 }, /* (279) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 243, -3 }, /* (280) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 241, -6 }, /* (281) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 244, 0 }, /* (282) join_type ::= */ + { 244, -1 }, /* (283) join_type ::= INNER */ + { 246, -9 }, /* (284) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 247, 0 }, /* (285) set_quantifier_opt ::= */ + { 247, -1 }, /* (286) set_quantifier_opt ::= DISTINCT */ + { 247, -1 }, /* (287) set_quantifier_opt ::= ALL */ + { 248, -1 }, /* (288) select_list ::= NK_STAR */ + { 248, -1 }, /* (289) select_list ::= select_sublist */ + { 254, -1 }, /* (290) select_sublist ::= select_item */ + { 254, -3 }, /* (291) select_sublist ::= select_sublist NK_COMMA select_item */ + { 255, -1 }, /* (292) select_item ::= common_expression */ + { 255, -2 }, /* (293) select_item ::= common_expression column_alias */ + { 255, -3 }, /* (294) select_item ::= common_expression AS column_alias */ + { 255, -3 }, /* (295) select_item ::= table_name NK_DOT NK_STAR */ + { 249, 0 }, /* (296) where_clause_opt ::= */ + { 249, -2 }, /* (297) where_clause_opt ::= WHERE search_condition */ + { 250, 0 }, /* (298) partition_by_clause_opt ::= */ + { 250, -3 }, /* (299) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 251, 0 }, /* (300) twindow_clause_opt ::= */ + { 251, -6 }, /* (301) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 251, -4 }, /* (302) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 251, -6 }, /* (303) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 251, -8 }, /* (304) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 217, 0 }, /* (305) sliding_opt ::= */ + { 217, -4 }, /* (306) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 256, 0 }, /* (307) fill_opt ::= */ + { 256, -4 }, /* (308) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 256, -6 }, /* (309) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 257, -1 }, /* (310) fill_mode ::= NONE */ + { 257, -1 }, /* (311) fill_mode ::= PREV */ + { 257, -1 }, /* (312) fill_mode ::= NULL */ + { 257, -1 }, /* (313) fill_mode ::= LINEAR */ + { 257, -1 }, /* (314) fill_mode ::= NEXT */ + { 252, 0 }, /* (315) group_by_clause_opt ::= */ + { 252, -3 }, /* (316) group_by_clause_opt ::= GROUP BY group_by_list */ + { 258, -1 }, /* (317) group_by_list ::= expression */ + { 258, -3 }, /* (318) group_by_list ::= group_by_list NK_COMMA expression */ + { 253, 0 }, /* (319) having_clause_opt ::= */ + { 253, -2 }, /* (320) having_clause_opt ::= HAVING search_condition */ + { 221, -4 }, /* (321) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 259, -1 }, /* (322) query_expression_body ::= query_primary */ + { 259, -4 }, /* (323) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 263, -1 }, /* (324) query_primary ::= query_specification */ + { 260, 0 }, /* (325) order_by_clause_opt ::= */ + { 260, -3 }, /* (326) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 261, 0 }, /* (327) slimit_clause_opt ::= */ + { 261, -2 }, /* (328) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 261, -4 }, /* (329) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 261, -4 }, /* (330) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 262, 0 }, /* (331) limit_clause_opt ::= */ + { 262, -2 }, /* (332) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 262, -4 }, /* (333) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 262, -4 }, /* (334) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 229, -3 }, /* (335) subquery ::= NK_LP query_expression NK_RP */ + { 245, -1 }, /* (336) search_condition ::= common_expression */ + { 264, -1 }, /* (337) sort_specification_list ::= sort_specification */ + { 264, -3 }, /* (338) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 265, -3 }, /* (339) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 266, 0 }, /* (340) ordering_specification_opt ::= */ + { 266, -1 }, /* (341) ordering_specification_opt ::= ASC */ + { 266, -1 }, /* (342) ordering_specification_opt ::= DESC */ + { 267, 0 }, /* (343) null_ordering_opt ::= */ + { 267, -2 }, /* (344) null_ordering_opt ::= NULLS FIRST */ + { 267, -2 }, /* (345) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2294,11 +2335,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,165,&yymsp[0].minor); + yy_destructor(yypParser,173,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,166,&yymsp[0].minor); + yy_destructor(yypParser,174,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2312,20 +2353,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,165,&yymsp[-2].minor); +{ yy_destructor(yypParser,173,&yymsp[-2].minor); { } - yy_destructor(yypParser,167,&yymsp[0].minor); + yy_destructor(yypParser,175,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,168,&yymsp[0].minor); +{ yy_destructor(yypParser,176,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,166,&yymsp[-1].minor); +{ yy_destructor(yypParser,174,&yymsp[-1].minor); { } - yy_destructor(yypParser,168,&yymsp[0].minor); + yy_destructor(yypParser,176,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2339,31 +2380,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,167,&yymsp[0].minor); + yy_destructor(yypParser,175,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy183, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy225, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy183, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy225, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy225); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy183, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy225, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy225); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2389,8 +2430,8 @@ static YYACTIONTYPE yy_reduce( case 212: /* user_name ::= NK_ID */ yytestcase(yyruleno==212); case 213: /* index_name ::= NK_ID */ yytestcase(yyruleno==213); case 214: /* topic_name ::= NK_ID */ yytestcase(yyruleno==214); -{ yylhsminor.yy183 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy183 = yylhsminor.yy183; +{ yylhsminor.yy225 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy225 = yylhsminor.yy225; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2405,186 +2446,186 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropQnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 43: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy215, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy505, &yymsp[-1].minor.yy225, yymsp[0].minor.yy176); } break; case 44: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy505, &yymsp[0].minor.yy225); } break; case 45: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy225); } break; case 46: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy225, yymsp[0].minor.yy176); } break; case 47: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy215 = true; } +{ yymsp[-2].minor.yy505 = true; } break; case 48: /* not_exists_opt ::= */ case 50: /* exists_opt ::= */ yytestcase(yyruleno==50); - case 277: /* set_quantifier_opt ::= */ yytestcase(yyruleno==277); -{ yymsp[1].minor.yy215 = false; } + case 285: /* set_quantifier_opt ::= */ yytestcase(yyruleno==285); +{ yymsp[1].minor.yy505 = false; } break; case 49: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy215 = true; } +{ yymsp[-1].minor.yy505 = true; } break; case 51: /* db_options ::= */ -{ yymsp[1].minor.yy378 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy176 = createDefaultDatabaseOptions(pCxt); } break; case 52: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 53: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 54: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 55: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 56: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 57: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 58: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 59: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 60: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 61: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 62: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 63: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 64: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 65: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 66: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 67: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 68: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 69: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-2].minor.yy378, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-2].minor.yy176, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 70: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy378 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy378 = setDatabaseOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy176 = setDatabaseOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 71: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy378 = setDatabaseOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setDatabaseOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 72: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 73: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 74: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_KEEP; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 75: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_WAL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_WAL; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 76: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 77: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 78: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 80: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==80); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy215, yymsp[-5].minor.yy378, yymsp[-3].minor.yy404, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy505, yymsp[-5].minor.yy176, yymsp[-3].minor.yy512, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } break; case 79: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy404); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy512); } break; case 81: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy404); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy512); } break; case 82: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } break; case 83: /* cmd ::= ALTER TABLE alter_table_clause */ case 84: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==84); case 185: /* cmd ::= query_expression */ yytestcase(yyruleno==185); -{ pCxt->pRootNode = yymsp[0].minor.yy378; } +{ pCxt->pRootNode = yymsp[0].minor.yy176; } break; case 85: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy378 = createAlterTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 86: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 87: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; case 88: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 89: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 90: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 91: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy378 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy378, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy176, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; case 92: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy378 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 93: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy378 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy378, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy176, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 94: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy378 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy378, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy176, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176); } + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; case 95: /* multi_create_clause ::= create_subtable_clause */ case 98: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==98); @@ -2593,186 +2634,186 @@ static YYACTIONTYPE yy_reduce( case 170: /* func_name_list ::= func_name */ yytestcase(yyruleno==170); case 179: /* func_list ::= func */ yytestcase(yyruleno==179); case 204: /* literal_list ::= signed_literal */ yytestcase(yyruleno==204); - case 282: /* select_sublist ::= select_item */ yytestcase(yyruleno==282); - case 329: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==329); -{ yylhsminor.yy404 = createNodeList(pCxt, yymsp[0].minor.yy378); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 290: /* select_sublist ::= select_item */ yytestcase(yyruleno==290); + case 337: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==337); +{ yylhsminor.yy512 = createNodeList(pCxt, yymsp[0].minor.yy176); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; case 96: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 99: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==99); -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-1].minor.yy404, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy404 = yylhsminor.yy404; +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-1].minor.yy512, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy512 = yylhsminor.yy512; break; case 97: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy378 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy215, yymsp[-7].minor.yy378, yymsp[-5].minor.yy378, yymsp[-4].minor.yy404, yymsp[-1].minor.yy404); } - yymsp[-8].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy505, yymsp[-7].minor.yy176, yymsp[-5].minor.yy176, yymsp[-4].minor.yy512, yymsp[-1].minor.yy512); } + yymsp[-8].minor.yy176 = yylhsminor.yy176; break; case 100: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy378 = createDropTableClause(pCxt, yymsp[-1].minor.yy215, yymsp[0].minor.yy378); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createDropTableClause(pCxt, yymsp[-1].minor.yy505, yymsp[0].minor.yy176); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 101: /* specific_tags_opt ::= */ case 132: /* tags_def_opt ::= */ yytestcase(yyruleno==132); - case 290: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==290); - case 307: /* group_by_clause_opt ::= */ yytestcase(yyruleno==307); - case 317: /* order_by_clause_opt ::= */ yytestcase(yyruleno==317); -{ yymsp[1].minor.yy404 = NULL; } + case 298: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==298); + case 315: /* group_by_clause_opt ::= */ yytestcase(yyruleno==315); + case 325: /* order_by_clause_opt ::= */ yytestcase(yyruleno==325); +{ yymsp[1].minor.yy512 = NULL; } break; case 102: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy404 = yymsp[-1].minor.yy404; } +{ yymsp[-2].minor.yy512 = yymsp[-1].minor.yy512; } break; case 103: /* full_table_name ::= table_name */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy183, NULL); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy225, NULL); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 104: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, NULL); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRealTableNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, NULL); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 106: /* column_def_list ::= column_def_list NK_COMMA column_def */ case 149: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==149); case 171: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==171); case 180: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==180); case 205: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==205); - case 283: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==283); - case 330: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==330); -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, yymsp[0].minor.yy378); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 291: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==291); + case 338: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==338); +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, yymsp[0].minor.yy176); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; case 107: /* column_def ::= column_name type_name */ -{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy183, yymsp[0].minor.yy504, NULL); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy225, yymsp[0].minor.yy448, NULL); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 108: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy378 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-2].minor.yy448, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; case 109: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 110: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 111: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 112: /* type_name ::= INT */ case 113: /* type_name ::= INTEGER */ yytestcase(yyruleno==113); -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_INT); } break; case 114: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 115: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 116: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 117: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 118: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 119: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 120: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 121: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 122: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 123: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 124: /* type_name ::= JSON */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 125: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 126: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 127: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 128: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 129: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 130: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 131: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 133: /* tags_def_opt ::= tags_def */ - case 281: /* select_list ::= select_sublist */ yytestcase(yyruleno==281); -{ yylhsminor.yy404 = yymsp[0].minor.yy404; } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 289: /* select_list ::= select_sublist */ yytestcase(yyruleno==289); +{ yylhsminor.yy512 = yymsp[0].minor.yy512; } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; case 134: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy404 = yymsp[-1].minor.yy404; } +{ yymsp[-3].minor.yy512 = yymsp[-1].minor.yy512; } break; case 135: /* table_options ::= */ -{ yymsp[1].minor.yy378 = createDefaultTableOptions(pCxt); } +{ yymsp[1].minor.yy176 = createDefaultTableOptions(pCxt); } break; case 136: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 137: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 138: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 139: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy378 = setTableSmaOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableSmaOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 140: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy378 = setTableRollupOption(pCxt, yymsp[-4].minor.yy378, yymsp[-1].minor.yy404); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableRollupOption(pCxt, yymsp[-4].minor.yy176, yymsp[-1].minor.yy512); } + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; case 141: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 142: /* table_options ::= table_options DELAY NK_INTEGER */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-2].minor.yy378, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-2].minor.yy176, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; case 143: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy378 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy378 = setTableOption(pCxt, yylhsminor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy176 = setTableOption(pCxt, yylhsminor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 144: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy378 = setTableOption(pCxt, yymsp[-1].minor.yy378, yymsp[0].minor.yy11.type, &yymsp[0].minor.yy11.val); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = setTableOption(pCxt, yymsp[-1].minor.yy176, yymsp[0].minor.yy325.type, &yymsp[0].minor.yy325.val); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 145: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 146: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 147: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy11.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy11.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy325.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy325.val = yymsp[0].minor.yy0; } break; case 150: /* col_name ::= column_name */ -{ yylhsminor.yy378 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 151: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -2784,13 +2825,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; case 154: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } break; case 155: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } break; case 156: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy378, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy176, NULL); } break; case 157: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -2805,526 +2846,544 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; case 161: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; case 162: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } break; case 163: /* db_name_cond_opt ::= */ case 168: /* from_db_opt ::= */ yytestcase(yyruleno==168); -{ yymsp[1].minor.yy378 = createDefaultDatabaseCondValue(pCxt); } +{ yymsp[1].minor.yy176 = createDefaultDatabaseCondValue(pCxt); } break; case 164: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 165: /* like_pattern_opt ::= */ case 176: /* index_options ::= */ yytestcase(yyruleno==176); - case 288: /* where_clause_opt ::= */ yytestcase(yyruleno==288); - case 292: /* twindow_clause_opt ::= */ yytestcase(yyruleno==292); - case 297: /* sliding_opt ::= */ yytestcase(yyruleno==297); - case 299: /* fill_opt ::= */ yytestcase(yyruleno==299); - case 311: /* having_clause_opt ::= */ yytestcase(yyruleno==311); - case 319: /* slimit_clause_opt ::= */ yytestcase(yyruleno==319); - case 323: /* limit_clause_opt ::= */ yytestcase(yyruleno==323); -{ yymsp[1].minor.yy378 = NULL; } + case 296: /* where_clause_opt ::= */ yytestcase(yyruleno==296); + case 300: /* twindow_clause_opt ::= */ yytestcase(yyruleno==300); + case 305: /* sliding_opt ::= */ yytestcase(yyruleno==305); + case 307: /* fill_opt ::= */ yytestcase(yyruleno==307); + case 319: /* having_clause_opt ::= */ yytestcase(yyruleno==319); + case 327: /* slimit_clause_opt ::= */ yytestcase(yyruleno==327); + case 331: /* limit_clause_opt ::= */ yytestcase(yyruleno==331); +{ yymsp[1].minor.yy176 = NULL; } break; case 166: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 167: /* table_name_cond ::= table_name */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 169: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy183); } +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy225); } break; case 172: /* func_name ::= function_name */ -{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[0].minor.yy183, NULL); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[0].minor.yy225, NULL); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 173: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy215, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, NULL, yymsp[0].minor.yy378); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy505, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, NULL, yymsp[0].minor.yy176); } break; case 174: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy215, &yymsp[-5].minor.yy183, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404, NULL); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy505, &yymsp[-5].minor.yy225, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512, NULL); } break; case 175: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225); } break; case 177: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy378 = createIndexOption(pCxt, yymsp[-6].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL, yymsp[0].minor.yy378); } +{ yymsp[-8].minor.yy176 = createIndexOption(pCxt, yymsp[-6].minor.yy512, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL, yymsp[0].minor.yy176); } break; case 178: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy378 = createIndexOption(pCxt, yymsp[-8].minor.yy404, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[0].minor.yy378); } +{ yymsp[-10].minor.yy176 = createIndexOption(pCxt, yymsp[-8].minor.yy512, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[0].minor.yy176); } break; case 181: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; case 182: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, yymsp[0].minor.yy378, NULL); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, yymsp[0].minor.yy176, NULL); } break; case 183: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy215, &yymsp[-2].minor.yy183, NULL, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy505, &yymsp[-2].minor.yy225, NULL, &yymsp[0].minor.yy225); } break; case 184: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy215, &yymsp[0].minor.yy183); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy505, &yymsp[0].minor.yy225); } break; case 186: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 187: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 188: /* literal ::= NK_STRING */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 189: /* literal ::= NK_BOOL */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 190: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 191: /* literal ::= duration_literal */ case 199: /* signed_literal ::= signed */ yytestcase(yyruleno==199); case 215: /* expression ::= literal */ yytestcase(yyruleno==215); - case 216: /* expression ::= column_reference */ yytestcase(yyruleno==216); - case 219: /* expression ::= subquery */ yytestcase(yyruleno==219); - case 251: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==251); - case 255: /* boolean_primary ::= predicate */ yytestcase(yyruleno==255); - case 257: /* common_expression ::= expression */ yytestcase(yyruleno==257); - case 258: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==258); - case 260: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==260); - case 262: /* table_reference ::= table_primary */ yytestcase(yyruleno==262); - case 263: /* table_reference ::= joined_table */ yytestcase(yyruleno==263); - case 267: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==267); - case 314: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==314); - case 316: /* query_primary ::= query_specification */ yytestcase(yyruleno==316); -{ yylhsminor.yy378 = yymsp[0].minor.yy378; } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 216: /* expression ::= pseudo_column */ yytestcase(yyruleno==216); + case 217: /* expression ::= column_reference */ yytestcase(yyruleno==217); + case 220: /* expression ::= subquery */ yytestcase(yyruleno==220); + case 259: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==259); + case 263: /* boolean_primary ::= predicate */ yytestcase(yyruleno==263); + case 265: /* common_expression ::= expression */ yytestcase(yyruleno==265); + case 266: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==266); + case 268: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==268); + case 270: /* table_reference ::= table_primary */ yytestcase(yyruleno==270); + case 271: /* table_reference ::= joined_table */ yytestcase(yyruleno==271); + case 275: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==275); + case 322: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==322); + case 324: /* query_primary ::= query_specification */ yytestcase(yyruleno==324); +{ yylhsminor.yy176 = yymsp[0].minor.yy176; } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 192: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 193: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 194: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 195: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 196: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 197: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; case 198: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; case 200: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 201: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy378 = yylhsminor.yy378; +{ yylhsminor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; case 202: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy378 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy176 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; case 203: /* signed_literal ::= duration_literal */ - case 328: /* search_condition ::= common_expression */ yytestcase(yyruleno==328); -{ yylhsminor.yy378 = releaseRawExprNode(pCxt, yymsp[0].minor.yy378); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 336: /* search_condition ::= common_expression */ yytestcase(yyruleno==336); +{ yylhsminor.yy176 = releaseRawExprNode(pCxt, yymsp[0].minor.yy176); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 217: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, yymsp[-1].minor.yy404)); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 218: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, yymsp[-1].minor.yy512)); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 218: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy183, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy183, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 219: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy225, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy225, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 220: /* expression ::= NK_LP expression NK_RP */ - case 256: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==256); -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 221: /* expression ::= NK_LP expression NK_RP */ + case 264: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==264); +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 221: /* expression ::= NK_PLUS expression */ + case 222: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 222: /* expression ::= NK_MINUS expression */ + case 223: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), NULL)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 223: /* expression ::= expression NK_PLUS expression */ + case 224: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 224: /* expression ::= expression NK_MINUS expression */ + case 225: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 225: /* expression ::= expression NK_STAR expression */ + case 226: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 226: /* expression ::= expression NK_SLASH expression */ + case 227: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 227: /* expression ::= expression NK_REM expression */ + case 228: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 228: /* expression_list ::= expression */ -{ yylhsminor.yy404 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 229: /* expression_list ::= expression */ +{ yylhsminor.yy512 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 229: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, releaseRawExprNode(pCxt, yymsp[0].minor.yy378)); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 230: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, releaseRawExprNode(pCxt, yymsp[0].minor.yy176)); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; - case 230: /* column_reference ::= column_name */ -{ yylhsminor.yy378 = createRawExprNode(pCxt, &yymsp[0].minor.yy183, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy183)); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + case 231: /* column_reference ::= column_name */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy225, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy225)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 231: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183, createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy183)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 232: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225, createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy225)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 232: /* predicate ::= expression compare_op expression */ - case 237: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==237); + case 233: /* pseudo_column ::= NK_UNDERLINE ROWTS */ + case 235: /* pseudo_column ::= NK_UNDERLINE QSTARTTS */ yytestcase(yyruleno==235); + case 236: /* pseudo_column ::= NK_UNDERLINE QENDTS */ yytestcase(yyruleno==236); + case 237: /* pseudo_column ::= NK_UNDERLINE WSTARTTS */ yytestcase(yyruleno==237); + case 238: /* pseudo_column ::= NK_UNDERLINE WENDTS */ yytestcase(yyruleno==238); + case 239: /* pseudo_column ::= NK_UNDERLINE WDURATION */ yytestcase(yyruleno==239); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy366, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken t = yymsp[-1].minor.yy0; + t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; + yylhsminor.yy176 = createRawExprNode(pCxt, &t, createFunctionNode(pCxt, &t, NULL)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 233: /* predicate ::= expression BETWEEN expression AND expression */ + case 234: /* pseudo_column ::= TBNAME */ +{ yylhsminor.yy176 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy176 = yylhsminor.yy176; + break; + case 240: /* predicate ::= expression compare_op expression */ + case 245: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==245); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy378), releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy404, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-4].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 234: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 241: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy176), releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; + yymsp[-4].minor.yy176 = yylhsminor.yy176; break; - case 235: /* predicate ::= expression IS NULL */ + case 242: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; - case 236: /* predicate ::= expression IS NOT NULL */ + case 243: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), NULL)); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 238: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_THAN; } - break; - case 239: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_THAN; } - break; - case 240: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy366 = OP_TYPE_LOWER_EQUAL; } - break; - case 241: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy366 = OP_TYPE_GREATER_EQUAL; } - break; - case 242: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy366 = OP_TYPE_NOT_EQUAL; } - break; - case 243: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy366 = OP_TYPE_EQUAL; } - break; - case 244: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy366 = OP_TYPE_LIKE; } - break; - case 245: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_LIKE; } - break; - case 246: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy366 = OP_TYPE_MATCH; } - break; - case 247: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy366 = OP_TYPE_NMATCH; } - break; - case 248: /* in_op ::= IN */ -{ yymsp[0].minor.yy366 = OP_TYPE_IN; } - break; - case 249: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy366 = OP_TYPE_NOT_IN; } - break; - case 250: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; - break; - case 252: /* boolean_value_expression ::= NOT boolean_primary */ + case 244: /* predicate ::= expression IS NOT NULL */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), NULL)); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 253: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 246: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_THAN; } + break; + case 247: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_THAN; } + break; + case 248: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy404 = OP_TYPE_LOWER_EQUAL; } + break; + case 249: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy404 = OP_TYPE_GREATER_EQUAL; } + break; + case 250: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy404 = OP_TYPE_NOT_EQUAL; } + break; + case 251: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy404 = OP_TYPE_EQUAL; } + break; + case 252: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy404 = OP_TYPE_LIKE; } + break; + case 253: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_LIKE; } + break; + case 254: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy404 = OP_TYPE_MATCH; } + break; + case 255: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy404 = OP_TYPE_NMATCH; } + break; + case 256: /* in_op ::= IN */ +{ yymsp[0].minor.yy404 = OP_TYPE_IN; } + break; + case 257: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy404 = OP_TYPE_NOT_IN; } + break; + case 258: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; + break; + case 260: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), NULL)); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 254: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 261: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy378); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 259: /* from_clause ::= FROM table_reference_list */ - case 289: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==289); - case 312: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==312); -{ yymsp[-1].minor.yy378 = yymsp[0].minor.yy378; } + case 262: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy176); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); + } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 261: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy378 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy378, yymsp[0].minor.yy378, NULL); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 267: /* from_clause ::= FROM table_reference_list */ + case 297: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==297); + case 320: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==320); +{ yymsp[-1].minor.yy176 = yymsp[0].minor.yy176; } break; - case 264: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 269: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy176 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy176, yymsp[0].minor.yy176, NULL); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 265: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy378 = createRealTableNode(pCxt, &yymsp[-3].minor.yy183, &yymsp[-1].minor.yy183, &yymsp[0].minor.yy183); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 272: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 266: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy378 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 273: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy176 = createRealTableNode(pCxt, &yymsp[-3].minor.yy225, &yymsp[-1].minor.yy225, &yymsp[0].minor.yy225); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 268: /* alias_opt ::= */ -{ yymsp[1].minor.yy183 = nil_token; } + case 274: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy176 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 269: /* alias_opt ::= table_alias */ -{ yylhsminor.yy183 = yymsp[0].minor.yy183; } - yymsp[0].minor.yy183 = yylhsminor.yy183; + case 276: /* alias_opt ::= */ +{ yymsp[1].minor.yy225 = nil_token; } break; - case 270: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy183 = yymsp[0].minor.yy183; } + case 277: /* alias_opt ::= table_alias */ +{ yylhsminor.yy225 = yymsp[0].minor.yy225; } + yymsp[0].minor.yy225 = yylhsminor.yy225; break; - case 271: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 272: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==272); -{ yymsp[-2].minor.yy378 = yymsp[-1].minor.yy378; } + case 278: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy225 = yymsp[0].minor.yy225; } break; - case 273: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy378 = createJoinTableNode(pCxt, yymsp[-4].minor.yy162, yymsp[-5].minor.yy378, yymsp[-2].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-5].minor.yy378 = yylhsminor.yy378; + case 279: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 280: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==280); +{ yymsp[-2].minor.yy176 = yymsp[-1].minor.yy176; } break; - case 274: /* join_type ::= */ -{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } + case 281: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy176 = createJoinTableNode(pCxt, yymsp[-4].minor.yy236, yymsp[-5].minor.yy176, yymsp[-2].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-5].minor.yy176 = yylhsminor.yy176; break; - case 275: /* join_type ::= INNER */ -{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } + case 282: /* join_type ::= */ +{ yymsp[1].minor.yy236 = JOIN_TYPE_INNER; } break; - case 276: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 283: /* join_type ::= INNER */ +{ yymsp[0].minor.yy236 = JOIN_TYPE_INNER; } + break; + case 284: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy378 = createSelectStmt(pCxt, yymsp[-7].minor.yy215, yymsp[-6].minor.yy404, yymsp[-5].minor.yy378); - yymsp[-8].minor.yy378 = addWhereClause(pCxt, yymsp[-8].minor.yy378, yymsp[-4].minor.yy378); - yymsp[-8].minor.yy378 = addPartitionByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-3].minor.yy404); - yymsp[-8].minor.yy378 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy378, yymsp[-2].minor.yy378); - yymsp[-8].minor.yy378 = addGroupByClause(pCxt, yymsp[-8].minor.yy378, yymsp[-1].minor.yy404); - yymsp[-8].minor.yy378 = addHavingClause(pCxt, yymsp[-8].minor.yy378, yymsp[0].minor.yy378); + yymsp[-8].minor.yy176 = createSelectStmt(pCxt, yymsp[-7].minor.yy505, yymsp[-6].minor.yy512, yymsp[-5].minor.yy176); + yymsp[-8].minor.yy176 = addWhereClause(pCxt, yymsp[-8].minor.yy176, yymsp[-4].minor.yy176); + yymsp[-8].minor.yy176 = addPartitionByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-3].minor.yy512); + yymsp[-8].minor.yy176 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy176, yymsp[-2].minor.yy176); + yymsp[-8].minor.yy176 = addGroupByClause(pCxt, yymsp[-8].minor.yy176, yymsp[-1].minor.yy512); + yymsp[-8].minor.yy176 = addHavingClause(pCxt, yymsp[-8].minor.yy176, yymsp[0].minor.yy176); } break; - case 278: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy215 = true; } + case 286: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy505 = true; } break; - case 279: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy215 = false; } + case 287: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy505 = false; } break; - case 280: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy404 = NULL; } + case 288: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy512 = NULL; } break; - case 284: /* select_item ::= common_expression */ + case 292: /* select_item ::= common_expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy378); - yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378), &t); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy176); + yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176), &t); } - yymsp[0].minor.yy378 = yylhsminor.yy378; + yymsp[0].minor.yy176 = yylhsminor.yy176; break; - case 285: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-1].minor.yy378 = yylhsminor.yy378; + case 293: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-1].minor.yy176 = yylhsminor.yy176; break; - case 286: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy378 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), &yymsp[0].minor.yy183); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 294: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy176 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), &yymsp[0].minor.yy225); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 287: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy378 = createColumnNode(pCxt, &yymsp[-2].minor.yy183, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 295: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy176 = createColumnNode(pCxt, &yymsp[-2].minor.yy225, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 291: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 308: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==308); - case 318: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==318); -{ yymsp[-2].minor.yy404 = yymsp[0].minor.yy404; } + case 299: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 316: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==316); + case 326: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==326); +{ yymsp[-2].minor.yy512 = yymsp[0].minor.yy512; } break; - case 293: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy378 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } + case 301: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy176 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } break; - case 294: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy378 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy378)); } + case 302: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy176 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy176)); } break; - case 295: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), NULL, yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } + case 303: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), NULL, yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; - case 296: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy378 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy378), releaseRawExprNode(pCxt, yymsp[-3].minor.yy378), yymsp[-1].minor.yy378, yymsp[0].minor.yy378); } + case 304: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy176 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy176), releaseRawExprNode(pCxt, yymsp[-3].minor.yy176), yymsp[-1].minor.yy176, yymsp[0].minor.yy176); } break; - case 298: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy378 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy378); } + case 306: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy176 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy176); } break; - case 300: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy378 = createFillNode(pCxt, yymsp[-1].minor.yy466, NULL); } + case 308: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy176 = createFillNode(pCxt, yymsp[-1].minor.yy142, NULL); } break; - case 301: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy378 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } + case 309: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy176 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy512)); } break; - case 302: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy466 = FILL_MODE_NONE; } + case 310: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy142 = FILL_MODE_NONE; } break; - case 303: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy466 = FILL_MODE_PREV; } + case 311: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy142 = FILL_MODE_PREV; } break; - case 304: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy466 = FILL_MODE_NULL; } + case 312: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy142 = FILL_MODE_NULL; } break; - case 305: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy466 = FILL_MODE_LINEAR; } + case 313: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy142 = FILL_MODE_LINEAR; } break; - case 306: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy466 = FILL_MODE_NEXT; } + case 314: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy142 = FILL_MODE_NEXT; } break; - case 309: /* group_by_list ::= expression */ -{ yylhsminor.yy404 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[0].minor.yy404 = yylhsminor.yy404; + case 317: /* group_by_list ::= expression */ +{ yylhsminor.yy512 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } + yymsp[0].minor.yy512 = yylhsminor.yy512; break; - case 310: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy378))); } - yymsp[-2].minor.yy404 = yylhsminor.yy404; + case 318: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy512 = addNodeToList(pCxt, yymsp[-2].minor.yy512, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy176))); } + yymsp[-2].minor.yy512 = yylhsminor.yy512; break; - case 313: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 321: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy378 = addOrderByClause(pCxt, yymsp[-3].minor.yy378, yymsp[-2].minor.yy404); - yylhsminor.yy378 = addSlimitClause(pCxt, yylhsminor.yy378, yymsp[-1].minor.yy378); - yylhsminor.yy378 = addLimitClause(pCxt, yylhsminor.yy378, yymsp[0].minor.yy378); + yylhsminor.yy176 = addOrderByClause(pCxt, yymsp[-3].minor.yy176, yymsp[-2].minor.yy512); + yylhsminor.yy176 = addSlimitClause(pCxt, yylhsminor.yy176, yymsp[-1].minor.yy176); + yylhsminor.yy176 = addLimitClause(pCxt, yylhsminor.yy176, yymsp[0].minor.yy176); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 315: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy378 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy378, yymsp[0].minor.yy378); } - yymsp[-3].minor.yy378 = yylhsminor.yy378; + case 323: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy176 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy176, yymsp[0].minor.yy176); } + yymsp[-3].minor.yy176 = yylhsminor.yy176; break; - case 320: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 324: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==324); -{ yymsp[-1].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 328: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 332: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==332); +{ yymsp[-1].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 321: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 325: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==325); -{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 329: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 333: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==333); +{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 322: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 326: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==326); -{ yymsp[-3].minor.yy378 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 330: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 334: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==334); +{ yymsp[-3].minor.yy176 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 327: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy378 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy378); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 335: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy176 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy176); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 331: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy378 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy378), yymsp[-1].minor.yy400, yymsp[0].minor.yy151); } - yymsp[-2].minor.yy378 = yylhsminor.yy378; + case 339: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy176 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy176), yymsp[-1].minor.yy106, yymsp[0].minor.yy465); } + yymsp[-2].minor.yy176 = yylhsminor.yy176; break; - case 332: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy400 = ORDER_ASC; } + case 340: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy106 = ORDER_ASC; } break; - case 333: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy400 = ORDER_ASC; } + case 341: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy106 = ORDER_ASC; } break; - case 334: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy400 = ORDER_DESC; } + case 342: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy106 = ORDER_DESC; } break; - case 335: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy151 = NULL_ORDER_DEFAULT; } + case 343: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy465 = NULL_ORDER_DEFAULT; } break; - case 336: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy151 = NULL_ORDER_FIRST; } + case 344: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy465 = NULL_ORDER_FIRST; } break; - case 337: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy151 = NULL_ORDER_LAST; } + case 345: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy465 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 3057e06fe1..88708ef369 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -206,6 +206,13 @@ TEST_F(ParserTest, selectExpression) { ASSERT_TRUE(run()); } +TEST_F(ParserTest, selectPseudoColumn) { + setDatabase("root", "test"); + + bind("SELECT _wstartts, _wendts, count(*) FROM t1 interval(10s)"); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, selectClause) { setDatabase("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 740fb678fd..915c8bff83 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -411,7 +411,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, } static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { - int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pWindow->pFuncs); + int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs); if (TSDB_CODE_SUCCESS == code) { code = rewriteExpr(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW); diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index c95845f8c7..b8226eb949 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -36,10 +36,6 @@ typedef struct SPhysiPlanContext { } SPhysiPlanContext; static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { - if (QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode)) { - return getSlotKey(((SOrderByExprNode*)pNode)->pExpr, pStmtName, pKey); - } - if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; if (NULL != pStmtName) { @@ -184,15 +180,16 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0; SNode* pNode = NULL; FOREACH(pNode, pList) { + SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; - int32_t len = getSlotKey(pNode, pStmtName, name); + int32_t len = getSlotKey(pExpr, pStmtName, name); SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { - code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, nextSlotId, output)); + code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pExpr, nextSlotId, output)); if (TSDB_CODE_SUCCESS == code) { code = putSlotToHashImpl(pDataBlockDesc->dataBlockId, nextSlotId, name, len, pHash); } - pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes; + pDataBlockDesc->resultRowSize += ((SExprNode*)pExpr)->resType.bytes; slotId = nextSlotId; ++nextSlotId; } else { @@ -600,7 +597,7 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { return collectAndRewrite(pContext, pNode); } case QUERY_NODE_FUNCTION: { - if (!fmIsAggFunc(((SFunctionNode*)(*pNode))->funcId)) { + if (fmIsScalarFunc(((SFunctionNode*)(*pNode))->funcId)) { return collectAndRewrite(pContext, pNode); } } diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 3d17cc260b..1de5e96335 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -192,6 +192,9 @@ TEST_F(PlannerTest, interval) { bind("SELECT count(*) FROM t1 interval(10s)"); ASSERT_TRUE(run()); + + bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + ASSERT_TRUE(run()); } TEST_F(PlannerTest, sessionWindow) { From baede29bd5a223b66c702ead803d680adc549782 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Mon, 28 Mar 2022 19:56:19 +0800 Subject: [PATCH 147/149] [add tmq sim] --- .../script/sh/massiveTable/compileVersion.sh | 2 + tests/test/c/CMakeLists.txt | 8 + tests/test/c/tmqSim.c | 301 ++++++++++++++++++ 3 files changed, 311 insertions(+) create mode 100644 tests/test/c/tmqSim.c diff --git a/tests/script/sh/massiveTable/compileVersion.sh b/tests/script/sh/massiveTable/compileVersion.sh index dd6382992a..13b2baae32 100755 --- a/tests/script/sh/massiveTable/compileVersion.sh +++ b/tests/script/sh/massiveTable/compileVersion.sh @@ -75,10 +75,12 @@ rm -f /usr/bin/taos rm -f /usr/bin/taosd rm -f /usr/bin/create_table rm -f /usr/bin/tmq_demo +rm -f /usr/bin/tmq_sim ln -s $taos_dir/taos /usr/bin/taos ln -s $taosd_dir/taosd /usr/bin/taosd ln -s $exec_process_dir/create_table /usr/bin/create_table ln -s $exec_process_dir/tmq_demo /usr/bin/tmq_demo +ln -s $exec_process_dir/tmq_sim /usr/bin/tmq_sim diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index e186491bd4..804894a69d 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(create_table create_table.c) add_executable(tmq_demo tmqDemo.c) +add_executable(tmq_sim tmqSim.c) target_link_libraries( create_table PUBLIC taos @@ -14,3 +15,10 @@ target_link_libraries( PUBLIC common PUBLIC os ) +target_link_libraries( + tmq_sim + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os +) diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c new file mode 100644 index 0000000000..57fc6eb6f9 --- /dev/null +++ b/tests/test/c/tmqSim.c @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +// clang-format off + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "taos.h" +#include "taoserror.h" +#include "tlog.h" + +#define GREEN "\033[1;32m" +#define NC "\033[0m" +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) + +typedef struct { + // input from argvs + char dbName[32]; + char topicString[256]; + char keyString[1024]; + int32_t showMsgFlag; + + // save result after parse agrvs + int32_t numOfTopic; + char topics[32][64]; + + int32_t numOfKey; + char key[32][64]; + char value[32][64]; +} SConfInfo; + +static SConfInfo g_stConfInfo; + +//char* g_pRowValue = NULL; +//TdFilePtr g_fp = NULL; + +static void printHelp() { + char indent[10] = " "; + printf("Used to test the tmq feature with sim cases\n"); + + printf("%s%s\n", indent, "-c"); + printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); + printf("%s%s\n", indent, "-d"); + printf("%s%s%s\n", indent, indent, "The name of the database for cosumer, no default "); + printf("%s%s\n", indent, "-t"); + printf("%s%s%s\n", indent, indent, "The topic string for cosumer, no default "); + printf("%s%s\n", indent, "-k"); + printf("%s%s%s\n", indent, indent, "The key-value string for cosumer, no default "); + printf("%s%s\n", indent, "-g"); + printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag); + exit(EXIT_SUCCESS); +} + +void parseArgument(int32_t argc, char *argv[]) { + + memset(&g_stConfInfo, 0, sizeof(SConfInfo)); + + for (int32_t i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + printHelp(); + exit(0); + } else if (strcmp(argv[i], "-d") == 0) { + strcpy(g_stConfInfo.dbName, argv[++i]); + } else if (strcmp(argv[i], "-c") == 0) { + strcpy(configDir, argv[++i]); + } else if (strcmp(argv[i], "-t") == 0) { + strcpy(g_stConfInfo.topicString, argv[++i]); + } else if (strcmp(argv[i], "-k") == 0) { + strcpy(g_stConfInfo.keyString, argv[++i]); + } else if (strcmp(argv[i], "-g") == 0) { + g_stConfInfo.showMsgFlag = atol(argv[++i]); + } else { + printf("%s unknow para: %s %s", GREEN, argv[++i], NC); + exit(-1); + } + } + +#if 1 + pPrint("%s configDir:%s %s", GREEN, configDir, NC); + pPrint("%s dbName:%s %s", GREEN, g_stConfInfo.dbName, NC); + pPrint("%s topicString:%s %s", GREEN, g_stConfInfo.topicString, NC); + pPrint("%s keyString:%s %s", GREEN, g_stConfInfo.keyString, NC); + pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC); +#endif +} + +void splitStr(char **arr, char *str, const char *del) { + char *s = strtok(str, del); + while(s != NULL) { + *arr++ = s; + s = strtok(NULL, del); + } +} + +void ltrim(char *str) +{ + if (str == NULL || *str == '\0') + { + return; + } + int len = 0; + char *p = str; + while (*p != '\0' && isspace(*p)) + { + ++p; ++len; + } + memmove(str, p, strlen(str) - len + 1); + //return str; +} + + +void parseInputString() { + //printf("topicString: %s\n", g_stConfInfo.topicString); + //printf("keyString: %s\n\n", g_stConfInfo.keyString); + + char *token; + const char delim[2] = ","; + const char ch = ':'; + + token = strtok(g_stConfInfo.topicString, delim); + while(token != NULL) { + //printf("%s\n", token ); + strcpy(g_stConfInfo.topics[g_stConfInfo.numOfTopic], token); + ltrim(g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + //printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + g_stConfInfo.numOfTopic++; + + token = strtok(NULL, delim); + } + + printf("\n\n"); + + token = strtok(g_stConfInfo.keyString, delim); + while(token != NULL) { + //printf("%s\n", token ); + { + char* pstr = token; + ltrim(pstr); + char *ret = strchr(pstr, ch); + memcpy(g_stConfInfo.key[g_stConfInfo.numOfKey], pstr, ret-pstr); + strcpy(g_stConfInfo.value[g_stConfInfo.numOfKey], ret+1); + //printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], g_stConfInfo.value[g_stConfInfo.numOfKey]); + g_stConfInfo.numOfKey++; + } + + token = strtok(NULL, delim); + } +} + + +static int running = 1; +static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } + + +int queryDB(TAOS *taos, char *command) { + TAOS_RES *pRes = taos_query(taos, command); + int code = taos_errno(pRes); + //if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { + if (code != 0) { + pError("failed to reason:%s, sql: %s", tstrerror(code), command); + taos_free_result(pRes); + return -1; + } + taos_free_result(pRes); + return 0 ; +} + +tmq_t* build_consumer() { + char sqlStr[1024] = {0}; + + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + sprintf(sqlStr, "use %s", g_stConfInfo.dbName); + TAOS_RES* pRes = taos_query(pConn, sqlStr); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + tmq_conf_t* conf = tmq_conf_new(); + //tmq_conf_set(conf, "group.id", "tg2"); + for (int32_t i = 0; i < g_stConfInfo.numOfKey; i++) { + tmq_conf_set(conf, g_stConfInfo.key[i], g_stConfInfo.value[i]); + } + tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + return tmq; +} + +tmq_list_t* build_topic_list() { + tmq_list_t* topic_list = tmq_list_new(); + //tmq_list_append(topic_list, "test_stb_topic_1"); + for (int32_t i = 0; i < g_stConfInfo.numOfTopic; i++) { + tmq_list_append(topic_list, g_stConfInfo.topics[i]); + } + return topic_list; +} + +void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + static const int MIN_COMMIT_COUNT = 1000; + + int msg_count = 0; + tmq_resp_err_t err; + + if ((err = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); + return; + } + + while (running) { + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); + if (tmqmessage) { + msg_process(tmqmessage); + tmq_message_destroy(tmqmessage); + + if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); + } + } + + err = tmq_consumer_close(tmq); + if (err) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +void perf_loop(tmq_t* tmq, tmq_list_t* topics) { + tmq_resp_err_t err; + + if ((err = tmq_subscribe(tmq, topics))) { + printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); + return; + } + + int32_t totalMsgs = 0; + int32_t skipLogNum = 0; + //int64_t startTime = taosGetTimestampUs(); + while (running) { + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); + if (tmqmessage) { + totalMsgs++; + skipLogNum += tmqGetSkipLogNum(tmqmessage); + if (0 != g_stConfInfo.showMsgFlag) { + msg_process(tmqmessage); + } + tmq_message_destroy(tmqmessage); + } else { + break; + } + } + //int64_t endTime = taosGetTimestampUs(); + //double consumeTime = (double)(endTime - startTime) / 1000000; + + + err = tmq_consumer_close(tmq); + if (err) { + printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + + printf("{consume success: %d}", totalMsgs); +} + +int main(int32_t argc, char *argv[]) { + parseArgument(argc, argv); + parseInputString(); + + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = build_topic_list(); + if ((NULL == tmq) || (NULL == topic_list)){ + return -1; + } + + perf_loop(tmq, topic_list); + + return 0; +} + From a5386ee10263a55674dbfed4e9c87a4f1a515cf7 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 20:31:05 +0800 Subject: [PATCH 148/149] refact stream shuffle dispatch --- include/common/tmsg.h | 5 +- source/dnode/mgmt/vnode/src/vmMsg.c | 1 + source/dnode/mnode/impl/src/mndScheduler.c | 117 ++++++++++++++++++--- source/dnode/vnode/src/tq/tq.c | 4 +- source/libs/stream/src/tstream.c | 9 +- 5 files changed, 114 insertions(+), 22 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 6494e06c45..2ac652342a 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -801,7 +801,10 @@ typedef struct SVgroupInfo { uint32_t hashBegin; uint32_t hashEnd; SEpSet epSet; - int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + union { + int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int32_t taskId; // used in stream + }; } SVgroupInfo; typedef struct { diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index 1682c6043d..fed539ce7d 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -281,6 +281,7 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, (NodeMsgFp)vmProcessMgmtMsg, VND_VGID); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 305912a72a..566bd1d282 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -119,6 +119,53 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) { return pVgroup; } +int32_t mndAddSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) { + SSdb* pSdb = pMnode->pSdb; + void* pIter = NULL; + SArray* tasks = taosArrayGetP(pStream->tasks, 0); + + ASSERT(taosArrayGetSize(pStream->tasks) == 1); + + while (1) { + SVgObj* pVgroup; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pStream->dbUid) { + sdbRelease(pSdb, pVgroup); + continue; + } + SStreamTask* pTask = tNewSStreamTask(pStream->uid); + if (pTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + taosArrayPush(tasks, &pTask); + + pTask->nodeId = pVgroup->vgId; + pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); + + // source + pTask->sourceType = TASK_SOURCE__MERGE; + + // exec + pTask->execType = TASK_EXEC__NONE; + + // sink + if (smaId != -1) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = smaId; + } else { + pTask->sinkType = TASK_SINK__TABLE; + } + + // dispatch + pTask->dispatchType = TASK_DISPATCH__NONE; + + mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); + } + return 0; +} + int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) { SSdb* pSdb = pMnode->pSdb; SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); @@ -132,6 +179,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i ASSERT(totLevel <= 2); pStream->tasks = taosArrayInit(totLevel, sizeof(void*)); + bool hasExtraSink = false; + if (totLevel == 2) { + SArray* taskOneLevel = taosArrayInit(0, sizeof(void*)); + taosArrayPush(pStream->tasks, &taskOneLevel); + // add extra sink + hasExtraSink = true; + mndAddSinkToStream(pMnode, pTrans, pStream, smaId); + } + for (int32_t level = 0; level < totLevel; level++) { SArray* taskOneLevel = taosArrayInit(0, sizeof(void*)); SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level); @@ -164,9 +220,13 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i // only for inplace pTask->sinkType = TASK_SINK__SHOW; pTask->showSink.reserved = 0; - if (smaId != -1) { - pTask->sinkType = TASK_SINK__SMA; - pTask->smaSink.smaId = smaId; + if (!hasExtraSink) { + if (smaId != -1) { + pTask->sinkType = TASK_SINK__SMA; + pTask->smaSink.smaId = smaId; + } else { + pTask->sinkType = TASK_SINK__TABLE; + } } } else { pTask->sinkType = TASK_SINK__NONE; @@ -175,17 +235,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i // dispatch part if (level == 0) { pTask->dispatchType = TASK_DISPATCH__NONE; - // if inplace sink, no dispatcher - // if fixed ep, add fixed ep dispatcher - // if shuffle, add shuffle dispatcher } else { // add fixed ep dispatcher int32_t lastLevel = level - 1; ASSERT(lastLevel == 0); + if (hasExtraSink) lastLevel++; SArray* pArray = taosArrayGetP(pStream->tasks, lastLevel); // one merge only ASSERT(taosArrayGetSize(pArray) == 1); - SStreamTask* lastLevelTask = taosArrayGetP(pArray, lastLevel); + SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0); pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC; pTask->dispatchType = TASK_DISPATCH__FIXED; @@ -222,18 +280,43 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i /*pTask->sinkType = TASK_SINK__NONE;*/ // dispatch part - pTask->dispatchType = TASK_DISPATCH__NONE; -#if 0 - pTask->dispatchType = TASK_DISPATCH__SHUFFLE; - pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; - SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); - ASSERT(pDb); - if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { + ASSERT(hasExtraSink); + /*pTask->dispatchType = TASK_DISPATCH__NONE;*/ +#if 1 + + if (hasExtraSink) { + // add dispatcher + pTask->dispatchType = TASK_DISPATCH__SHUFFLE; + + pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; + SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); + ASSERT(pDb); + if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { + sdbRelease(pSdb, pDb); + qDestroyQueryPlan(pPlan); + return -1; + } sdbRelease(pSdb, pDb); - qDestroyQueryPlan(pPlan); - return -1; + + // put taskId to useDbRsp + // TODO: optimize + SArray* pVgs = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t sz = taosArrayGetSize(pVgs); + SArray* sinkLv = taosArrayGetP(pStream->tasks, 0); + int32_t sinkLvSize = taosArrayGetSize(sinkLv); + for (int32_t i = 0; i < sz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i); + for (int32_t j = 0; j < sinkLvSize; j++) { + SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j); + /*printf("vgid %d node id %d\n", pVgInfo->vgId, pTask->nodeId);*/ + if (pLastLevelTask->nodeId == pVgInfo->vgId) { + pVgInfo->taskId = pLastLevelTask->taskId; + /*printf("taskid %d set to %d\n", pVgInfo->taskId, pTask->taskId);*/ + break; + } + } + } } - sdbRelease(pSdb, pDb); #endif // exec part diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index efc7ac80e9..159ec5b3e8 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -508,7 +508,9 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) { SStreamTaskExecReq req; tDecodeSStreamTaskExecReq(msg, &req); - int32_t taskId = req.taskId; + int32_t taskId = req.taskId; + ASSERT(taskId); + SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); ASSERT(pTask); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 220f83bb3e..70651840f7 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -31,12 +31,13 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { ((SMsgHead*)buf)->vgId = 0; req.taskId = pTask->inplaceDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); *ppEpSet = &pTask->fixedEpDispatcher.epSet; req.taskId = pTask->fixedEpDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - int32_t nodeId = 0; // TODO fix tbname issue char ctbName[TSDB_TABLE_FNAME_LEN + 22]; // all groupId must be the same in an array @@ -52,10 +53,12 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* // TODO: optimize search process SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; int32_t sz = taosArrayGetSize(vgInfo); + int32_t nodeId = 0; for (int32_t i = 0; i < sz; i++) { SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); if (hashValue >= pVgInfo->hashBegin && hashValue <= pVgInfo->hashEnd) { nodeId = pVgInfo->vgId; + req.taskId = pVgInfo->taskId; *ppEpSet = &pVgInfo->epSet; break; } @@ -71,6 +74,7 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg->contLen = tlen; pMsg->code = 0; pMsg->msgType = pTask->dispatchMsgType; + /*pMsg->noResp = 1;*/ return 0; } @@ -80,7 +84,7 @@ static int32_t streamShuffleDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SHashOb while (1) { pIter = taosHashIterate(data, pIter); if (pIter == NULL) return 0; - SArray* pData = (SArray*)pIter; + SArray* pData = *(SArray**)pIter; SRpcMsg dispatchMsg = {0}; SEpSet* pEpSet; if (streamBuildDispatchMsg(pTask, pData, &dispatchMsg, &pEpSet) < 0) { @@ -98,7 +102,6 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK && pTask->sourceType != TASK_SOURCE__SCAN) return 0; // exec - // TODO: for shuffle dispatcher, merge data by groupId if (pTask->execType != TASK_EXEC__NONE) { ASSERT(workId < pTask->exec.numOfRunners); void* exec = pTask->exec.runners[workId].executor; From 98d8327ccff4ef84dcf9304125ba728e7eabcdef Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 28 Mar 2022 20:38:03 +0800 Subject: [PATCH 149/149] merge from 3.0 --- source/dnode/mgmt/vnode/src/vmMsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index 7bf21bdafe..7a6494cfa1 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -281,6 +281,7 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, VND_VGID);