@@ -419,17 +419,24 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
419419
420420 var dt sql.Table
421421 found := false
422+ tname := doltdb.TableName {Name : lwrName , Schema : db .schemaName }
422423 switch lwrName {
423- case doltdb .LogTableName :
424- if head == nil {
425- var err error
426- head , err = ds .GetHeadCommit (ctx , db .RevisionQualifiedName ())
427- if err != nil {
428- return nil , false , err
429- }
424+ case doltdb .GetLogTableName (), doltdb .LogTableName :
425+ isDoltgresSystemTable , err := resolve .IsDoltgresSystemTable (ctx , tname , root )
426+ if err != nil {
427+ return nil , false , err
430428 }
429+ if ! resolve .UseSearchPath || isDoltgresSystemTable {
430+ if head == nil {
431+ var err error
432+ head , err = ds .GetHeadCommit (ctx , db .RevisionQualifiedName ())
433+ if err != nil {
434+ return nil , false , err
435+ }
436+ }
431437
432- dt , found = dtables .NewLogTable (ctx , db .Name (), db .ddb , head ), true
438+ dt , found = dtables .NewLogTable (ctx , db .Name (), db .ddb , head ), true
439+ }
433440 case doltdb .DiffTableName :
434441 if head == nil {
435442 var err error
@@ -456,8 +463,14 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
456463 dt , found = dtables .NewTableOfTablesConstraintViolations (ctx , root ), true
457464 case doltdb .SchemaConflictsTableName :
458465 dt , found = dtables .NewSchemaConflictsTable (ctx , db .RevisionQualifiedName (), db .ddb ), true
459- case doltdb .BranchesTableName :
460- dt , found = dtables .NewBranchesTable (ctx , db ), true
466+ case doltdb .GetBranchesTableName (), doltdb .BranchesTableName :
467+ isDoltgresSystemTable , err := resolve .IsDoltgresSystemTable (ctx , tname , root )
468+ if err != nil {
469+ return nil , false , err
470+ }
471+ if ! resolve .UseSearchPath || isDoltgresSystemTable {
472+ dt , found = dtables .NewBranchesTable (ctx , db ), true
473+ }
461474 case doltdb .RemoteBranchesTableName :
462475 dt , found = dtables .NewRemoteBranchesTable (ctx , db ), true
463476 case doltdb .RemotesTableName :
@@ -466,23 +479,35 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
466479 dt , found = dtables .NewCommitsTable (ctx , db .Name (), db .ddb ), true
467480 case doltdb .CommitAncestorsTableName :
468481 dt , found = dtables .NewCommitAncestorsTable (ctx , db .Name (), db .ddb ), true
469- case doltdb .StatusTableName :
470- sess := dsess .DSessFromSess (ctx .Session )
471- adapter := dsess .NewSessionStateAdapter (
472- sess , db .RevisionQualifiedName (),
473- concurrentmap .New [string , env.Remote ](),
474- concurrentmap .New [string , env.BranchConfig ](),
475- concurrentmap .New [string , env.Remote ]())
476- ws , err := sess .WorkingSet (ctx , db .RevisionQualifiedName ())
482+ case doltdb .GetStatusTableName (), doltdb .StatusTableName :
483+ isDoltgresSystemTable , err := resolve .IsDoltgresSystemTable (ctx , tname , root )
477484 if err != nil {
478485 return nil , false , err
479486 }
487+ if ! resolve .UseSearchPath || isDoltgresSystemTable {
488+ sess := dsess .DSessFromSess (ctx .Session )
489+ adapter := dsess .NewSessionStateAdapter (
490+ sess , db .RevisionQualifiedName (),
491+ concurrentmap .New [string , env.Remote ](),
492+ concurrentmap .New [string , env.BranchConfig ](),
493+ concurrentmap .New [string , env.Remote ]())
494+ ws , err := sess .WorkingSet (ctx , db .RevisionQualifiedName ())
495+ if err != nil {
496+ return nil , false , err
497+ }
480498
481- dt , found = dtables .NewStatusTable (ctx , db .ddb , ws , adapter ), true
499+ dt , found = dtables .NewStatusTable (ctx , db .ddb , ws , adapter ), true
500+ }
482501 case doltdb .MergeStatusTableName :
483502 dt , found = dtables .NewMergeStatusTable (db .RevisionQualifiedName ()), true
484- case doltdb .TagsTableName :
485- dt , found = dtables .NewTagsTable (ctx , db .ddb ), true
503+ case doltdb .GetTagsTableName (), doltdb .TagsTableName :
504+ isDoltgresSystemTable , err := resolve .IsDoltgresSystemTable (ctx , tname , root )
505+ if err != nil {
506+ return nil , false , err
507+ }
508+ if ! resolve .UseSearchPath || isDoltgresSystemTable {
509+ dt , found = dtables .NewTagsTable (ctx , db .ddb ), true
510+ }
486511 case dtables .AccessTableName :
487512 basCtx := branch_control .GetBranchAwareSession (ctx )
488513 if basCtx != nil {
@@ -508,16 +533,25 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
508533 versionableTable := backingTable .(dtables.VersionableTable )
509534 dt , found = dtables .NewIgnoreTable (ctx , versionableTable ), true
510535 }
511- case doltdb .DocTableName :
512- backingTable , _ , err := db . getTable (ctx , root , doltdb . DocTableName )
536+ case doltdb .GetDocTableName (), doltdb . DocTableName :
537+ isDoltgresSystemTable , err := resolve . IsDoltgresSystemTable (ctx , tname , root )
513538 if err != nil {
514539 return nil , false , err
515540 }
516- if backingTable == nil {
517- dt , found = dtables .NewEmptyDocsTable (ctx ), true
518- } else {
519- versionableTable := backingTable .(dtables.VersionableTable )
520- dt , found = dtables .NewDocsTable (ctx , versionableTable ), true
541+ if ! resolve .UseSearchPath || isDoltgresSystemTable {
542+ if resolve .UseSearchPath && lwrName == doltdb .DocTableName {
543+ db .schemaName = "dolt"
544+ }
545+ backingTable , _ , err := db .getTable (ctx , root , doltdb .GetDocTableName ())
546+ if err != nil {
547+ return nil , false , err
548+ }
549+ if backingTable == nil {
550+ dt , found = dtables .NewEmptyDocsTable (ctx ), true
551+ } else {
552+ versionableTable := backingTable .(dtables.VersionableTable )
553+ dt , found = dtables .NewDocsTable (ctx , versionableTable ), true
554+ }
521555 }
522556 case doltdb .StatisticsTableName :
523557 dt , found = dtables .NewStatisticsTable (ctx , db .Name (), db .ddb , asOf ), true
@@ -691,11 +725,12 @@ func (db Database) GetTableNamesAsOf(ctx *sql.Context, time interface{}) ([]stri
691725 return nil , nil
692726 }
693727
694- tblNames , err := root . GetTableNames (ctx , doltdb . DefaultSchemaName )
728+ tblNames , err := db . getAllTableNames (ctx , root , false )
695729 if err != nil {
696730 return nil , err
697731 }
698- return filterDoltInternalTables (tblNames ), nil
732+
733+ return filterDoltInternalTables (tblNames , db .schemaName ), nil
699734}
700735
701736// getTable returns the user table with the given baseName from the root given
@@ -799,9 +834,7 @@ func (db Database) checkForPgCatalogTable(ctx *sql.Context, tableName string) (s
799834// case-insensitive manner. The table is returned along with its case-sensitive matched name. An error is returned if
800835// no such table exists.
801836func (db Database ) resolveUserTable (ctx * sql.Context , root doltdb.RootValue , tableName string ) (doltdb.TableName , * doltdb.Table , bool , error ) {
802- // dolt_docs table is branch-specific, not schema-specific for doltgres
803- isDoltDocs := tableName == doltdb .DocTableName
804- if resolve .UseSearchPath && db .schemaName == "" && ! isDoltDocs {
837+ if resolve .UseSearchPath && db .schemaName == "" {
805838 return resolve .TableWithSearchPath (ctx , root , tableName )
806839 } else {
807840 return db .tableInsensitive (ctx , root , tableName )
@@ -838,7 +871,7 @@ func (db Database) tableInsensitive(ctx *sql.Context, root doltdb.RootValue, tab
838871 }
839872 }
840873
841- tableNames , err := db .getAllTableNames (ctx , root )
874+ tableNames , err := db .getAllTableNames (ctx , root , true )
842875 if err != nil {
843876 return doltdb.TableName {}, nil , false , err
844877 }
@@ -891,20 +924,23 @@ func (db Database) newDoltTable(tableName string, sch schema.Schema, tbl *doltdb
891924// name resolution in queries is handled by GetTableInsensitive. Use GetAllTableNames for an unfiltered list of all
892925// tables in user space.
893926func (db Database ) GetTableNames (ctx * sql.Context ) ([]string , error ) {
894- tblNames , err := db . GetAllTableNames (ctx )
927+ showSystemTablesVar , err := ctx . GetSessionVariable (ctx , dsess . ShowSystemTables )
895928 if err != nil {
896929 return nil , err
897930 }
898- // TODO: should just elide system table gathering if we don't need them
899- showSystemTables , err := ctx .GetSessionVariable (ctx , dsess .ShowSystemTables )
931+
932+ showSystemTables := showSystemTablesVar .(int8 ) == 1
933+ tblNames , err := db .GetAllTableNames (ctx , showSystemTables )
900934 if err != nil {
901935 return nil , err
902936 }
903- if showSystemTables .(int8 ) == 1 {
937+
938+ if showSystemTables {
904939 return tblNames , nil
905- } else {
906- return filterDoltInternalTables (tblNames ), nil
907940 }
941+
942+ // TODO: Figure out way to remove filterDoltInternalTables
943+ return filterDoltInternalTables (tblNames , db .schemaName ), nil
908944}
909945
910946func (db Database ) SchemaName () string {
@@ -913,22 +949,17 @@ func (db Database) SchemaName() string {
913949
914950// GetAllTableNames returns all user-space tables, including system tables in user space
915951// (e.g. dolt_docs, dolt_query_catalog).
916- func (db Database ) GetAllTableNames (ctx * sql.Context ) ([]string , error ) {
952+ func (db Database ) GetAllTableNames (ctx * sql.Context , showSystemTables bool ) ([]string , error ) {
917953 root , err := db .GetRoot (ctx )
918-
919954 if err != nil {
920955 return nil , err
921956 }
922957
923- return db .getAllTableNames (ctx , root )
958+ return db .getAllTableNames (ctx , root , showSystemTables )
924959}
925960
926- func (db Database ) getAllTableNames (ctx * sql.Context , root doltdb.RootValue ) ([]string , error ) {
927- systemTables , err := doltdb .GetGeneratedSystemTables (ctx , root )
928- if err != nil {
929- return nil , err
930- }
931-
961+ func (db Database ) getAllTableNames (ctx * sql.Context , root doltdb.RootValue , showSystemTables bool ) ([]string , error ) {
962+ var err error
932963 var result []string
933964 // If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all
934965 // schemas in the search_path
@@ -947,14 +978,21 @@ func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([]
947978 }
948979 }
949980
950- result = append (result , systemTables ... )
981+ if showSystemTables {
982+ systemTables , err := doltdb .GetGeneratedSystemTables (ctx , root )
983+ if err != nil {
984+ return nil , err
985+ }
986+ result = append (result , systemTables ... )
987+ }
988+
951989 return result , nil
952990}
953991
954- func filterDoltInternalTables (tblNames []string ) []string {
992+ func filterDoltInternalTables (tblNames []string , schemaName string ) []string {
955993 result := []string {}
956994 for _ , tbl := range tblNames {
957- if ! doltdb .HasDoltPrefix (tbl ) {
995+ if ! doltdb .HasDoltPrefix (tbl ) && schemaName != "dolt" {
958996 result = append (result , tbl )
959997 }
960998 }
@@ -1174,7 +1212,7 @@ func (db Database) CreateIndexedTable(ctx *sql.Context, tableName string, sch sq
11741212
11751213// CreateFulltextTableNames returns a set of names that will be used to create Full-Text pseudo-index tables.
11761214func (db Database ) CreateFulltextTableNames (ctx * sql.Context , parentTableName string , parentIndexName string ) (fulltext.IndexTableNames , error ) {
1177- allTableNames , err := db .GetAllTableNames (ctx )
1215+ allTableNames , err := db .GetAllTableNames (ctx , true )
11781216 if err != nil {
11791217 return fulltext.IndexTableNames {}, err
11801218 }
0 commit comments