mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
change table projection implementation (#1298)
* change table projection implementation * update gms * disable a plan test
This commit is contained in:
@@ -18,7 +18,7 @@ require (
|
||||
github.com/denisbrodbeck/machineid v1.0.1
|
||||
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20201005193433-3ee972b1d078
|
||||
github.com/dolthub/fslock v0.0.2
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204201530-d7e59cda1c0c
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204225036-6f1f6f38ba9b
|
||||
github.com/dolthub/ishell v0.0.0-20201107004254-1592c0036c8d
|
||||
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66
|
||||
github.com/dolthub/sqllogictest/go v0.0.0-20201105013724-5123fc66e12c
|
||||
|
||||
@@ -148,8 +148,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/dolthub/fslock v0.0.2 h1:8vUh47iKovgrtXNrXVIzsIoWLlspoXg+3nslhUzgKSw=
|
||||
github.com/dolthub/fslock v0.0.2/go.mod h1:0i7bsNkK+XHwFL3dIsSWeXSV7sykVzzVr6+jq8oeEo0=
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204201530-d7e59cda1c0c h1:Xp0gyfsofHVxMEmkoldU69NJj874OxiFNGiAXYSMzAw=
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204201530-d7e59cda1c0c/go.mod h1:MRKd4z13XtaT7yLEx2GtR1IIt3WHXVqkzNvYD7WXt3o=
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204225036-6f1f6f38ba9b h1:5S5nV4sE4xMTvLbSZda99Mj5qQMgviePr50/imSkpOw=
|
||||
github.com/dolthub/go-mysql-server v0.8.1-0.20210204225036-6f1f6f38ba9b/go.mod h1:MRKd4z13XtaT7yLEx2GtR1IIt3WHXVqkzNvYD7WXt3o=
|
||||
github.com/dolthub/ishell v0.0.0-20201107004254-1592c0036c8d h1:i0u1Ze9wZF/zLgyOB/aLkG01gDDNQ48PR0/a80mxEyQ=
|
||||
github.com/dolthub/ishell v0.0.0-20201107004254-1592c0036c8d/go.mod h1:dhGBqcCEfK5kuFmeO5+WOx3hqc1k3M29c1oS/R7N4ms=
|
||||
github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66 h1:WRPDbpJWEnPxPmiuOTndT+lUWUeGjx6eoNOK9O4tQQQ=
|
||||
|
||||
@@ -100,6 +100,9 @@ func TestQueryPlans(t *testing.T) {
|
||||
"SELECT pk,pk1,pk2,one_pk.c1 AS foo,two_pk.c1 AS bar FROM one_pk JOIN two_pk ON one_pk.c1=two_pk.c1 WHERE one_pk.c1=10",
|
||||
"SELECT pk,pk1,pk2 FROM one_pk t1, two_pk t2 WHERE pk=1 AND pk2=1 AND pk1=1 ORDER BY 1,2",
|
||||
"SELECT /*+ JOIN_ORDER(t1, t2) */ t1.i FROM mytable t1 JOIN mytable t2 on t1.i = t2.i + 1 where t1.i = 2 and t2.i = 1",
|
||||
`SELECT i FROM mytable mt
|
||||
WHERE (SELECT i FROM mytable where i = mt.i) IS NOT NULL
|
||||
AND (SELECT i2 FROM othertable where i2 = i and i > 2) IS NOT NULL`,
|
||||
})
|
||||
|
||||
tests := make([]enginetest.QueryPlanTest, 0, len(enginetest.PlanTests))
|
||||
|
||||
@@ -129,7 +129,7 @@ func (t *WritableIndexedDoltTable) Partitions(ctx *sql.Context) (sql.PartitionIt
|
||||
}
|
||||
|
||||
func (t *WritableIndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
|
||||
return partitionIndexedTableRows(ctx, t, nil, part)
|
||||
return partitionIndexedTableRows(ctx, t, t.projectedCols, part)
|
||||
}
|
||||
|
||||
// NumRows returns the unfiltered count of rows contained in the table
|
||||
@@ -154,19 +154,9 @@ func partitionIndexedTableRows(ctx *sql.Context, t *WritableIndexedDoltTable, pr
|
||||
return nil, errors.New("unknown partition type")
|
||||
}
|
||||
|
||||
type projectedWritableIndexedDoltTable struct {
|
||||
*WritableIndexedDoltTable
|
||||
projectedCols []string
|
||||
}
|
||||
|
||||
func (t *projectedWritableIndexedDoltTable) Projection() []string {
|
||||
return t.projectedCols
|
||||
}
|
||||
|
||||
func (t *WritableIndexedDoltTable) WithProjection(colNames []string) sql.Table {
|
||||
return &projectedWritableIndexedDoltTable{t, colNames}
|
||||
}
|
||||
|
||||
func (t *projectedWritableIndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
|
||||
return partitionIndexedTableRows(ctx, t.WritableIndexedDoltTable, t.projectedCols, part)
|
||||
return &WritableIndexedDoltTable{
|
||||
WritableDoltTable: t.WithProjection(colNames).(*WritableDoltTable),
|
||||
indexLookup: t.indexLookup,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ type DoltTable struct {
|
||||
table *doltdb.Table
|
||||
sch schema.Schema
|
||||
autoIncCol schema.Column
|
||||
|
||||
projectedCols []string
|
||||
}
|
||||
|
||||
func NewDoltTable(name string, sch schema.Schema, tbl *doltdb.Table, db SqlDatabase) DoltTable {
|
||||
@@ -91,11 +93,12 @@ func NewDoltTable(name string, sch schema.Schema, tbl *doltdb.Table, db SqlDatab
|
||||
})
|
||||
|
||||
return DoltTable{
|
||||
name: name,
|
||||
db: db,
|
||||
table: tbl,
|
||||
sch: sch,
|
||||
autoIncCol: autoCol,
|
||||
name: name,
|
||||
db: db,
|
||||
table: tbl,
|
||||
sch: sch,
|
||||
autoIncCol: autoCol,
|
||||
projectedCols: nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +281,7 @@ func (itr emptyRowIterator) Close() error {
|
||||
|
||||
// Returns the table rows for the partition given
|
||||
func (t *DoltTable) PartitionRows(ctx *sql.Context, partition sql.Partition) (sql.RowIter, error) {
|
||||
return partitionRows(ctx, t, nil, partition)
|
||||
return partitionRows(ctx, t, t.projectedCols, partition)
|
||||
}
|
||||
|
||||
func partitionRows(ctx *sql.Context, t *DoltTable, projCols []string, partition sql.Partition) (sql.RowIter, error) {
|
||||
@@ -321,6 +324,14 @@ func (t *WritableDoltTable) WithIndexLookup(lookup sql.IndexLookup) sql.Table {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *WritableDoltTable) WithProjection(colNames []string) sql.Table {
|
||||
return &WritableDoltTable{
|
||||
DoltTable: *t.DoltTable.WithProjection(colNames).(*DoltTable),
|
||||
db: t.db,
|
||||
ed: t.ed,
|
||||
}
|
||||
}
|
||||
|
||||
// Inserter implements sql.InsertableTable
|
||||
func (t *WritableDoltTable) Inserter(ctx *sql.Context) sql.RowInserter {
|
||||
te, err := t.getTableEditor(ctx)
|
||||
@@ -475,22 +486,19 @@ func (t *DoltTable) GetForeignKeys(ctx *sql.Context) ([]sql.ForeignKeyConstraint
|
||||
return toReturn, nil
|
||||
}
|
||||
|
||||
type projectedDoltTable struct {
|
||||
*DoltTable
|
||||
projectedCols []string
|
||||
}
|
||||
|
||||
func (t *projectedDoltTable) Projection() []string {
|
||||
func (t *DoltTable) Projection() []string {
|
||||
return t.projectedCols
|
||||
}
|
||||
|
||||
func (t *DoltTable) WithProjection(colNames []string) sql.Table {
|
||||
return &projectedDoltTable{t, colNames}
|
||||
}
|
||||
|
||||
// Returns the table rows for the partition given
|
||||
func (t *projectedDoltTable) PartitionRows(ctx *sql.Context, partition sql.Partition) (sql.RowIter, error) {
|
||||
return partitionRows(ctx, t.DoltTable, t.projectedCols, partition)
|
||||
return &DoltTable{
|
||||
name: t.name,
|
||||
db: t.db,
|
||||
table: t.table,
|
||||
sch: t.sch,
|
||||
autoIncCol: t.autoIncCol,
|
||||
projectedCols: colNames,
|
||||
}
|
||||
}
|
||||
|
||||
var _ sql.PartitionIter = (*doltTablePartitionIter)(nil)
|
||||
|
||||
Reference in New Issue
Block a user