/ Check-in [740d5ff6]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved header comment and precondition checking for the new isDupColumn() function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-3182d38790
Files: files | file ages | folders
SHA3-256: 740d5ff6cc9bf7b151dfb8b27409e5923cfb2789b5398fe13d89563aff8ffc07
User & Date: drh 2019-04-29 13:30:16
Context
2019-04-29
13:48
Do not de-duplicate columns index columns associated with a WITHOUT ROWID table if the columns have different collating sequences. This is the fix for ticket [3182d3879020ef3b2]. There is one test case added, but most of the tests are done in TH3. check-in: 1b1dd4d4 user: drh tags: trunk
13:30
Improved header comment and precondition checking for the new isDupColumn() function. Closed-Leaf check-in: 740d5ff6 user: drh tags: tkt-3182d38790
2019-04-28
19:27
Take collating sequence into account when removing redundant columns from indexes on WITHOUT ROWID tables. This is the first proof-of-concept fix for ticket [3182d3879020ef3]. More testing needed. check-in: b34fa5bf user: drh tags: tkt-3182d38790
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

1737
1738
1739
1740
1741
1742
1743
1744
1745


1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757




1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
      return 1;
    }
  }
  return 0;
}

/*
** Return true if any of the first nKey entries of index pIdx1 exactly
** match the iCol-th entry of pIdx2.


**
** The first nKey entries of pIdx1 are guaranteed to be ordinary columns,
** not a rowid or expression.
**
** This routine differs from hasColumn() in that both the column and the
** collating sequence must match for this routine, but for hasColumn() only
** the column name must match.
*/
static int isDupColumn(Index *pIdx1, int nKey, Index *pIdx2, int iCol){
  int i, j;
  assert( nKey<=pIdx1->nColumn );
  assert( iCol<MAX(pIdx2->nColumn,pIdx2->nKeyCol) );




  j = pIdx2->aiColumn[iCol];
  testcase( j==XN_EXPR );
  assert( j!=XN_ROWID );
  for(i=0; i<nKey; i++){
    assert( pIdx1->aiColumn[i]>=0 || j>=0 );
    if( pIdx1->aiColumn[i]==j 
     && sqlite3StrICmp(pIdx1->azColl[i],pIdx2->azColl[iCol])==0
    ){
      return 1;
    }
  }
  return 0;
}








|
|
>
>

|






|

|
|
>
>
>
>
|
<
|

|
|
|







1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764

1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
      return 1;
    }
  }
  return 0;
}

/*
** Return true if any of the first nKey entries of index pIdx exactly
** match the iCol-th entry of pPk.  pPk is always a WITHOUT ROWID
** PRIMARY KEY index.  pIdx is an index on the same table.  pIdx may
** or may not be the same index as pPk.
**
** The first nKey entries of pIdx are guaranteed to be ordinary columns,
** not a rowid or expression.
**
** This routine differs from hasColumn() in that both the column and the
** collating sequence must match for this routine, but for hasColumn() only
** the column name must match.
*/
static int isDupColumn(Index *pIdx, int nKey, Index *pPk, int iCol){
  int i, j;
  assert( nKey<=pIdx->nColumn );
  assert( iCol<MAX(pPk->nColumn,pPk->nKeyCol) );
  assert( pPk->idxType==SQLITE_IDXTYPE_PRIMARYKEY );
  assert( pPk->pTable->tabFlags & TF_WithoutRowid );
  assert( pPk->pTable==pIdx->pTable );
  testcase( pPk==pIdx );
  j = pPk->aiColumn[iCol];

  assert( j!=XN_ROWID && j!=XN_EXPR );
  for(i=0; i<nKey; i++){
    assert( pIdx->aiColumn[i]>=0 || j>=0 );
    if( pIdx->aiColumn[i]==j 
     && sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
    ){
      return 1;
    }
  }
  return 0;
}