You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2025/12/18 06:16:40 UTC
(doris) branch branch-3.1 updated: branch-3.1: [Opt](tbl_priv) Optimize PrivTable search and insert with ordered lookup #58828 (#59028)
This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new 394ee02b0ad branch-3.1: [Opt](tbl_priv) Optimize PrivTable search and insert with ordered lookup #58828 (#59028)
394ee02b0ad is described below
commit 394ee02b0ad8c19f0072f619e71f4db4fdd83920
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Thu Dec 18 14:16:33 2025 +0800
branch-3.1: [Opt](tbl_priv) Optimize PrivTable search and insert with ordered lookup #58828 (#59028)
Cherry-picked from #58828
Co-authored-by: linrrarity <li...@selectdb.com>
---
.../apache/doris/mysql/privilege/PrivTable.java | 35 +++++++++-------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PrivTable.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PrivTable.java
index 1588b3a67a7..d24e974d9e5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PrivTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/PrivTable.java
@@ -79,31 +79,28 @@ public abstract class PrivTable {
}
}
- PrivEntry existingEntry = getExistingEntry(newEntry);
- if (existingEntry == null) {
+ int idx = Collections.binarySearch(entries, newEntry);
+ if (idx < 0) {
if (errOnNonExist) {
throw new DdlException("entry does not exist");
}
- entries.add(newEntry);
- Collections.sort(entries);
- LOG.info("add priv entry: {}", newEntry);
+ int insertPos = -idx - 1;
+ entries.add(insertPos, newEntry);
return newEntry;
- } else {
- if (errOnExist) {
- throw new DdlException("entry already exist");
- } else {
- mergePriv(existingEntry, newEntry);
- if (LOG.isDebugEnabled()) {
- LOG.debug("merge priv entry: {}", existingEntry);
- }
- }
}
+
+ if (errOnExist) {
+ throw new DdlException("entry already exist");
+ }
+
+ PrivEntry existingEntry = entries.get(idx);
+ mergePriv(existingEntry, newEntry);
return existingEntry;
}
public List<PrivEntry> getEntries() {
- return entries;
+ return Collections.unmodifiableList(entries);
}
public void dropEntry(PrivEntry entry) {
@@ -160,12 +157,8 @@ public abstract class PrivTable {
// Get existing entry which is the keys match the given entry
protected PrivEntry getExistingEntry(PrivEntry entry) {
- for (PrivEntry existingEntry : entries) {
- if (existingEntry.keyMatch(entry)) {
- return existingEntry;
- }
- }
- return null;
+ int idx = Collections.binarySearch(entries, entry);
+ return idx >= 0 ? entries.get(idx) : null;
}
private void mergePriv(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org