perf: Drop `name` part from posting sort index (#33551)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 6be6e06..7495ab8 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -316,6 +316,7 @@
erpnext.patches.v14_0.fix_subcontracting_receipt_gl_entries
erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger
erpnext.patches.v13_0.update_schedule_type_in_loans
+erpnext.patches.v13_0.drop_unused_sle_index_parts
erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
erpnext.patches.v14_0.update_partial_tds_fields
erpnext.patches.v14_0.create_incoterms_and_migrate_shipment
diff --git a/erpnext/patches/v13_0/drop_unused_sle_index_parts.py b/erpnext/patches/v13_0/drop_unused_sle_index_parts.py
new file mode 100644
index 0000000..fa8a98c
--- /dev/null
+++ b/erpnext/patches/v13_0/drop_unused_sle_index_parts.py
@@ -0,0 +1,14 @@
+import frappe
+
+from erpnext.stock.doctype.stock_ledger_entry.stock_ledger_entry import on_doctype_update
+
+
+def execute():
+ try:
+ frappe.db.sql_ddl("ALTER TABLE `tabStock Ledger Entry` DROP INDEX `posting_sort_index`")
+ except Exception:
+ frappe.log_error("Failed to drop index")
+ return
+
+ # Recreate indexes
+ on_doctype_update()
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index c64370d..052f778 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -221,14 +221,9 @@
def on_doctype_update():
- if not frappe.db.has_index("tabStock Ledger Entry", "posting_sort_index"):
- frappe.db.commit()
- frappe.db.add_index(
- "Stock Ledger Entry",
- fields=["posting_date", "posting_time", "name"],
- index_name="posting_sort_index",
- )
-
+ frappe.db.add_index(
+ "Stock Ledger Entry", fields=["posting_date", "posting_time"], index_name="posting_sort_index"
+ )
frappe.db.add_index("Stock Ledger Entry", ["voucher_no", "voucher_type"])
frappe.db.add_index("Stock Ledger Entry", ["batch_no", "item_code", "warehouse"])
frappe.db.add_index("Stock Ledger Entry", ["warehouse", "item_code"], "item_warehouse")