Skip to content

Commit

Permalink
Make SET default of trivial values much faster (#6134)
Browse files Browse the repository at this point in the history
Use postgres default values to populate the column, instead of doing
it explicitly. We don't ever actually *use* the default when
INSERTing, but that's fine.
  • Loading branch information
msullivan committed Sep 21, 2023
1 parent 0310b84 commit 567e14e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions edb/pgsql/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4039,10 +4039,15 @@ def get_pointer_default(self, ptr, schema, context):
if ptr.is_pure_computable(schema):
return None

# We only *need* to use postgres defaults for link properties
# and sequence values (since we always explicitly inject it in
# INSERTs anyway), but we *want* to use it whenever we can,
# since it is much faster than explicitly populating the
# column.
default = ptr.get_default(schema)
default_value = None

if default is not None and ptr.is_link_property(schema):
if default is not None:
default_value = schemamech.ptr_default_to_col_default(
schema, ptr, default)
elif self.is_sequence_ptr(ptr, schema):
Expand Down Expand Up @@ -4632,11 +4637,10 @@ def _alter_pointer_type(self, pointer, schema, orig_schema, context):
if changing_col_type:
# In case the column has a default, clear it out before
# changing the type
if is_lprop or self.is_sequence_ptr(pointer, orig_schema):
alter_table.add_operation(
dbops.AlterTableAlterColumnDefault(
column_name=old_ptr_stor_info.column_name,
default=None))
alter_table.add_operation(
dbops.AlterTableAlterColumnDefault(
column_name=old_ptr_stor_info.column_name,
default=None))

alter_type = dbops.AlterTableAlterColumnType(
old_ptr_stor_info.column_name,
Expand Down
2 changes: 1 addition & 1 deletion edb/pgsql/schemamech.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def ptr_default_to_col_default(schema, ptr, expr):
)
)
ir = qlcompiler.compile_ast_to_ir(eql, schema)
except errors.SchemaError:
except (errors.SchemaError, errors.QueryError):
# Reference errors mean that is is a non-constant default
# referring to a not-yet-existing objects.
return None
Expand Down

0 comments on commit 567e14e

Please sign in to comment.