Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add support for indexes on expressions to incremental_index_check. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | checkindex |
Files: | files | file ages | folders |
SHA3-256: |
8c1c701fdbe0d56ee7f6f7d7b583aafd |
User & Date: | dan 2017-10-30 19:38:41.046 |
Context
2017-10-31
| ||
12:01 | Fix a couple of issues in incremental_index_check to do with CREATE INDEX statements that contain embedded SQL comments. (check-in: 2aef41815a user: dan tags: checkindex) | |
2017-10-30
| ||
19:38 | Add support for indexes on expressions to incremental_index_check. (check-in: 8c1c701fdb user: dan tags: checkindex) | |
17:05 | In checkindex.c, use C code instead of SQL/group_concat() to compose various SQL clauses. This is to make it easier to support indexes on expressions. (check-in: 940606b3af user: dan tags: checkindex) | |
Changes
Changes to ext/repair/checkindex.c.
︙ | |||
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - | int i; for(i=0; i<pIdx->nCol; i++){ sqlite3_free(pIdx->aCol[i].zExpr); } sqlite3_free(pIdx); } } #define CIDX_PARSE_EOF 0 #define CIDX_PARSE_COMMA 1 /* "," */ #define CIDX_PARSE_OPEN 2 /* "(" */ #define CIDX_PARSE_CLOSE 3 /* ")" */ static int cidxFindNext(const char *zIn, const char **pzOut){ const char *z = zIn; while( 1 ){ *pzOut = z; switch( *z ){ case '\0': return CIDX_PARSE_EOF; case '(': return CIDX_PARSE_OPEN; case ')': return CIDX_PARSE_CLOSE; case ',': return CIDX_PARSE_COMMA; case '"': case '\'': case '`': { char q = *z; z++; while( *z ){ if( *z==q ){ z++; if( *z!=q ) break; } z++; } break; } case '[': while( *z++!=']' ); break; default: z++; } } assert( 0 ); return -1; } static int cidx_isspace(char c){ return c==' ' || c=='\t' || c=='\r' || c=='\n'; } static int cidx_isident(char c){ return c<0 || (c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='_'; } static int cidxParseSQL(CidxCursor *pCsr, CidxIndex *pIdx, const char *zSql){ const char *z = zSql; const char *z1; int e; int rc = SQLITE_OK; int nParen = 1; CidxColumn *pCol = pIdx->aCol; e = cidxFindNext(z, &z); if( e!=CIDX_PARSE_OPEN ) goto parse_error; z1 = z+1; z++; while( nParen>0 ){ e = cidxFindNext(z, &z); if( e==CIDX_PARSE_EOF ) goto parse_error; if( (e==CIDX_PARSE_COMMA || e==CIDX_PARSE_CLOSE) && nParen==1 ){ const char *z2 = z; if( pCol->zExpr ) goto parse_error; while( cidx_isspace(z[-1]) ) z--; if( 0==sqlite3_strnicmp(&z[-3], "asc", 3) && 0==cidx_isident(z[-4]) ){ z -= 3; while( cidx_isspace(z[-1]) ) z--; }else if( 0==sqlite3_strnicmp(&z[-4], "desc", 4) && 0==cidx_isident(z[-5]) ){ z -= 4; while( cidx_isspace(z[-1]) ) z--; } while( cidx_isspace(z1[0]) ) z1++; pCol->zExpr = cidxMprintf(&rc, "%.*s", z-z1, z1); pCol++; z = z1 = z2+1; } if( e==CIDX_PARSE_OPEN ) nParen++; if( e==CIDX_PARSE_CLOSE ) nParen--; z++; } return rc; parse_error: cidxCursorError(pCsr, "Parse error in: %s", zSql); return SQLITE_ERROR; } static int cidxLookupIndex( CidxCursor *pCsr, /* Cursor object */ const char *zIdx, /* Name of index to look up */ CidxIndex **ppIdx, /* OUT: Description of columns */ char **pzTab /* OUT: Table name */ ){ int rc = SQLITE_OK; char *zTab = 0; CidxIndex *pIdx = 0; sqlite3_stmt *pFindTab = 0; sqlite3_stmt *pInfo = 0; /* Find the table for this index. */ pFindTab = cidxPrepare(&rc, pCsr, |
︙ | |||
407 408 409 410 411 412 413 | 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | - + - + - + - + | int *pRc, CidxColumn *aCol, char **azAfter, int iGt, int bLastIsNull ){ char *zRet = 0; const char *zSep = ""; int i; for(i=0; i<iGt; i++){ |
︙ | |||
446 447 448 449 450 451 452 | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | - + - + - + - - + + - - + + - - + + | int *pRc, /* IN/OUT: Error code */ const char *zIdx, CidxIndex *pIdx, /* Indexed columns */ int eType /* True to include ASC/DESC */ ){ char *zRet = 0; if( *pRc==SQLITE_OK ){ |
︙ | |||
532 533 534 535 536 537 538 | 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | - + - - + + + + - + - + - + - - - - + + + + - + - + | rc = cidxLookupIndex(pCsr, zIdxName, &pIdx, &zTab); zOrderBy = cidxColumnList(&rc, zIdxName, pIdx, CIDX_CLIST_ORDERBY); zCurrentKey = cidxColumnList(&rc, zIdxName, pIdx, CIDX_CLIST_CURRENT_KEY); zSubWhere = cidxColumnList(&rc, zIdxName, pIdx, CIDX_CLIST_SUBWHERE); zSubExpr = cidxColumnList(&rc, zIdxName, pIdx, CIDX_CLIST_SUBEXPR); |
︙ |
Changes to test/checkindex.test.
︙ | |||
255 256 257 258 259 260 261 262 263 264 265 | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | do_index_check_test 4.3 t4cc { {} 'aaa','bbb',1 {row data mismatch} 'AAA','CCC',2 {row missing} 'aab','ddd',3 {} 'AAB','EEE',4 } #-------------------------------------------------------------------------- # Test an index on an expression. # do_execsql_test 5.0 { CREATE TABLE t5(x INTEGER PRIMARY KEY, y TEXT, UNIQUE(y)); INSERT INTO t5 VALUES(1, '{"x":1, "y":1}'); INSERT INTO t5 VALUES(2, '{"x":2, "y":2}'); INSERT INTO t5 VALUES(3, '{"x":3, "y":3}'); INSERT INTO t5 VALUES(4, '{"w":4, "z":4}'); INSERT INTO t5 VALUES(5, '{"x":5, "y":5}'); CREATE INDEX t5x ON t5( json_extract(y, '$.x') ); CREATE INDEX t5y ON t5( json_extract(y, '$.y') DESC ); } do_index_check_test 5.1.1 t5x { {} NULL,4 {} 1,1 {} 2,2 {} 3,3 {} 5,5 } do_index_check_test 5.1.2 t5y { {} 5,5 {} 3,3 {} 2,2 {} 1,1 {} NULL,4 } do_index_check_test 5.1.3 sqlite_autoindex_t5_1 { {} {'{"w":4, "z":4}',4} {} {'{"x":1, "y":1}',1} {} {'{"x":2, "y":2}',2} {} {'{"x":3, "y":3}',3} {} {'{"x":5, "y":5}',5} } do_test 5.2 { set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t5' }] sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot db eval {CREATE TABLE xt5(a INTEGER PRIMARY KEY, c1 TEXT);} sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0 execsql { UPDATE xt5 SET c1='{"x":22, "y":11}' WHERE rowid=1; DELETE FROM xt5 WHERE rowid = 4; } sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1 } {} do_index_check_test 5.3.1 t5x { {row missing} NULL,4 {row data mismatch} 1,1 {} 2,2 {} 3,3 {} 5,5 } do_index_check_test 5.3.2 sqlite_autoindex_t5_1 { {row missing} {'{"w":4, "z":4}',4} {row data mismatch} {'{"x":1, "y":1}',1} {} {'{"x":2, "y":2}',2} {} {'{"x":3, "y":3}',3} {} {'{"x":5, "y":5}',5} } finish_test |