[opt](sessionVar)show changed sessoin var first #28840

“show variables” command list changed vars before not changed vars,
This commit is contained in:
minghong
2023-12-22 14:45:33 +08:00
committed by GitHub
parent 9b67c86219
commit 7f310cec9c

View File

@ -691,7 +691,8 @@ public class VariableMgr {
// Dump all fields. Used for `show variables`
public static List<List<String>> dump(SetType type, SessionVariable sessionVar, PatternMatcher matcher) {
List<List<String>> rows = Lists.newArrayList();
List<List<String>> changedRows = Lists.newArrayList();
List<List<String>> defaultRows = Lists.newArrayList();
// Hold the read lock when session dump, because this option need to access global variable.
rlock.lock();
try {
@ -732,23 +733,35 @@ public class VariableMgr {
} else {
row.add(varContext.defaultValue);
}
row.add(row.get(1).equals(row.get(2)) ? "0" : "1");
rows.add(row);
if (row.get(1).equals(row.get(2))) {
row.add("0");
defaultRows.add(row);
} else {
row.add("1");
changedRows.add(row);
}
}
} finally {
rlock.unlock();
}
// Sort all variables by variable name.
Collections.sort(rows, new Comparator<List<String>>() {
Collections.sort(changedRows, new Comparator<List<String>>() {
@Override
public int compare(List<String> o1, List<String> o2) {
return o1.get(0).compareTo(o2.get(0));
}
});
return rows;
Collections.sort(defaultRows, new Comparator<List<String>>() {
@Override
public int compare(List<String> o1, List<String> o2) {
return o1.get(0).compareTo(o2.get(0));
}
});
changedRows.addAll(defaultRows);
return changedRows;
}
@Retention(RetentionPolicy.RUNTIME)