MCPcopy Create free account
hub / github.com/apecloud/myduckserver / CreateIndex

Method CreateIndex

catalog/table.go:555–618  ·  view source on GitHub ↗

CreateIndex implements sql.IndexAlterableTable.

(ctx *sql.Context, indexDef sql.IndexDef)

Source from the content-addressed store, hash-verified

553}
554
555var _ sql.RowUpdater = (*EmptyTableEditor)(nil)
556
557// Updater implements sql.AlterableTable.
558func (t *Table) Updater(ctx *sql.Context) sql.RowUpdater {
559 // Called when altering a table’s default value. No update needed as DuckDB handles it internally.
560 return &EmptyTableEditor{}
561}
562
563// Inserter implements sql.InsertableTable.
564func (t *Table) Inserter(*sql.Context) sql.RowInserter {
565 return &rowInserter{
566 db: t.db.Name(),
567 table: t.name,
568 schema: t.schema.Schema,
569 hasPK: t.hasPrimaryKey,
570 }
571}
572
573// Deleter implements sql.DeletableTable.
574func (t *Table) Deleter(*sql.Context) sql.RowDeleter {
575 return nil
576}
577
578// Truncate implements sql.TruncateableTable.
579func (t *Table) Truncate(ctx *sql.Context) (int, error) {
580 result, err := adapter.ExecCatalog(ctx, `TRUNCATE TABLE `+FullTableName(t.db.catalog, t.db.name, t.name))
581 if err != nil {
582 return 0, err
583 }
584 affected, err := result.RowsAffected()
585 return int(affected), err
586}
587
588// Replacer implements sql.ReplaceableTable.
589func (t *Table) Replacer(*sql.Context) sql.RowReplacer {
590 hasKey := len(t.schema.PkOrdinals) > 0 || !sql.IsKeyless(t.schema.Schema)
591 return &rowInserter{
592 db: t.db.Name(),
593 table: t.name,
594 schema: t.schema.Schema,
595 hasPK: t.hasPrimaryKey,
596 replace: hasKey,
597 }
598}
599
600// CreateIndex implements sql.IndexAlterableTable.
601func (t *Table) CreateIndex(ctx *sql.Context, indexDef sql.IndexDef) error {
602 // Lock the table to ensure thread-safety during index creation
603 t.mu.Lock()
604 defer t.mu.Unlock()
605
606 // https://github.com/apecloud/myduckserver/issues/272
607 if isIndexCreationDisabled(ctx) {
608 return nil
609 }
610
611 if indexDef.IsPrimary() {
612 return fmt.Errorf("primary key cannot be created with CreateIndex, use ALTER TABLE ... ADD PRIMARY KEY instead")

Callers

nothing calls this directly

Calls 13

ExecFunction · 0.92
isIndexCreationDisabledFunction · 0.85
FullSchemaNameFunction · 0.85
EncodeIndexNameFunction · 0.85
FullTableNameFunction · 0.85
FullIndexNameFunction · 0.85
IsSpatialMethod · 0.80
IsFullTextMethod · 0.80
IsUniqueMethod · 0.80
EncodeMethod · 0.45

Tested by

no test coverage detected