Skip to content

[Refactoring]: VFT of types #10181

Todo
Todo

Description

@fengttt

Why do you want to refactor this code?

Now we switch type id all the places and code looks like 
switch type.typeid {
    case T_INT8: ...
    case T_INT16: ...
    ...
    case T_DECIMAL64: ...
}

Note that this has many problems.
1. If we add a type, we need to touch many many places.   Missing one will cause crash/panic or worse.
2. This switch, often is in a loop.   VERY SLOW.

Describe the solution you'd like

Consolidate every type switch to a "virtual function table" approach. We we create a type, then type now has a VFT
type Typ struct {
Oid T
...
vft *VFT
}

Where VFT is an array of function ptrs. Initialize this vft when we construct the type data structure.

func (t T) ToType() Type {
...
typ.vft = vft_of_t
return typ
}

All VFT of different types should be implemented in types module. Maybe even one file. At least, the vft entry for each type should intialized in one file.

Later all the switch should go away, we just call
typ.GetFunc(op_xxx)(args)

Describe alternatives you've considered

No response

Additional information

No response

Activity

  1. added
    priority/p0
    on Jun 21, 2023
  2. added this to the 1.0.0 milestone on Jun 21, 2023
  3. added
    source/dev
    attention/being-discussed
    on Jul 10, 2023
  4. removed
    attention/being-discussed
    on Jul 13, 2023
  5. modified the milestones: 1.0.0, 1.1.0 on Aug 19, 2023
  6. added
    priority/p1
    priority/p0
    and removed
    priority/p0
    priority/p1
    on Aug 28, 2023
  7. added
    priority/p1
    and removed
    priority/p0
    on Sep 7, 2023
  8. removed this from the 1.1.0 milestone on Oct 18, 2023
  9. 12 remaining items

  10. self-assigned this
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

long-term-jobpriority/p1source/dev

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions