pierrejeambrun commented on code in PR #69489: URL: https://github.com/apache/airflow/pull/69489#discussion_r3535106070
########## airflow-core/src/airflow/migrations/versions/0124_3_3_0_add_index_on_asset_uri.py: ########## @@ -0,0 +1,47 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Add index on asset.uri. + +Revision ID: c4e7a1f9b2d0 +Revises: d2f4e1b3c5a7 +Create Date: 2026-07-06 00:00:00.000000 +""" + +from __future__ import annotations + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "c4e7a1f9b2d0" +down_revision = "d2f4e1b3c5a7" +branch_labels = None +depends_on = None +airflow_version = "3.3.0" + + +def upgrade(): + """Apply Add index on asset.uri.""" + with op.batch_alter_table("asset", schema=None) as batch_op: + batch_op.create_index("idx_asset_uri", ["uri"], unique=False) + + +def downgrade(): + """Unapply Add index on asset.uri.""" + with op.batch_alter_table("asset", schema=None) as batch_op: + batch_op.drop_index("idx_asset_uri") Review Comment: ~~It's fine to have a 'filter/order_by' in the API that isn't backed by an index. Indeed it will be slow if the table grows out of control but does the table grows out of control in most common cases? I would avoid adding an index (costly) just for a single filter of a single endpoint. I'm not sure here but I would say the table isn't huge most of the time. (millions of assets) and no index is probably fine for most? (the index probably wasn't there in 2.x as well) If someone happen to have a huge asset table they can add their own index to improve performance following https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/performance.rst~~ ########## airflow-core/src/airflow/migrations/versions/0124_3_3_0_add_index_on_asset_uri.py: ########## @@ -0,0 +1,47 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Add index on asset.uri. + +Revision ID: c4e7a1f9b2d0 +Revises: d2f4e1b3c5a7 +Create Date: 2026-07-06 00:00:00.000000 +""" + +from __future__ import annotations + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "c4e7a1f9b2d0" +down_revision = "d2f4e1b3c5a7" +branch_labels = None +depends_on = None +airflow_version = "3.3.0" + + +def upgrade(): + """Apply Add index on asset.uri.""" + with op.batch_alter_table("asset", schema=None) as batch_op: + batch_op.create_index("idx_asset_uri", ["uri"], unique=False) + + +def downgrade(): + """Unapply Add index on asset.uri.""" + with op.batch_alter_table("asset", schema=None) as batch_op: + batch_op.drop_index("idx_asset_uri") Review Comment: ~~It's fine to have a 'filter/order_by' in the API that isn't backed by an index. Indeed it will be slow if the table grows out of control but does the table grows out of control in most common cases? I would avoid adding an index (costly) just for a single filter of a single endpoint. I'm not sure here but I would say the table isn't huge most of the time. (millions of assets) and no index is probably fine for most? (the index probably wasn't there in 2.x as well)~~ ~~If someone happen to have a huge asset table they can add their own index to improve performance following https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/performance.rst~~ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
