diff --git a/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/main/resources/mapper/common/ResourceManagerMapper.xml b/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/main/resources/mapper/common/ResourceManagerMapper.xml
index 559c5069e1e..21d0e8fafb7 100644
--- a/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/main/resources/mapper/common/ResourceManagerMapper.xml
+++ b/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/main/resources/mapper/common/ResourceManagerMapper.xml
@@ -72,8 +72,7 @@
(select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id=B.label_id and B.service_instance = #{instance} )
- select * from linkis_cg_manager_linkis_resources where resourceType = #{resourceType} and
- id in (select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id = B.label_id and B.service_instance=#{instance})
+ delete from linkis_cg_manager_linkis_resources where ticketId = #{ticketId}
diff --git a/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/test/java/org/apache/linkis/manager/dao/ResourceManagerMapperTest.java b/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/test/java/org/apache/linkis/manager/dao/ResourceManagerMapperTest.java
index f55a2d888aa..6fcb66b8008 100644
--- a/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/test/java/org/apache/linkis/manager/dao/ResourceManagerMapperTest.java
+++ b/linkis-computation-governance/linkis-manager/linkis-manager-persistence/src/test/java/org/apache/linkis/manager/dao/ResourceManagerMapperTest.java
@@ -113,9 +113,14 @@ void deleteResourceByInstance() {
@Test
void deleteResourceByTicketId() {
registerResource();
+ PersistenceResource otherResource = new PersistenceResource();
+ otherResource.setId(2);
+ otherResource.setTicketId("2");
+ resourceManagerMapper.registerResource(otherResource);
resourceManagerMapper.deleteResourceByTicketId("1");
PersistenceResource persistenceResource = resourceManagerMapper.getNodeResourceByTicketId("1");
assertTrue(persistenceResource == null);
+ assertTrue(resourceManagerMapper.getNodeResourceByTicketId("2") != null);
}
@Test
diff --git a/linkis-extensions/linkis-et-monitor/src/main/resources/mapper/common/JobHistoryMapper.xml b/linkis-extensions/linkis-et-monitor/src/main/resources/mapper/common/JobHistoryMapper.xml
index dcab938da91..aaefa38c6a2 100644
--- a/linkis-extensions/linkis-et-monitor/src/main/resources/mapper/common/JobHistoryMapper.xml
+++ b/linkis-extensions/linkis-et-monitor/src/main/resources/mapper/common/JobHistoryMapper.xml
@@ -100,7 +100,7 @@
status = #{targetStatus}
-
+
#{element}
diff --git a/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/mysql/JobHistoryMapper.xml b/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/mysql/JobHistoryMapper.xml
index 43c4f52bfaa..d7393a9cde3 100644
--- a/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/mysql/JobHistoryMapper.xml
+++ b/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/mysql/JobHistoryMapper.xml
@@ -144,12 +144,11 @@
- /*slave*/ SELECT id FROM linkis_ps_job_history_group_history
+ /*slave*/ SELECT MAX(id) FROM linkis_ps_job_history_group_history
and created_time >= #{startDate} AND created_time #{endDate}
and id >= #{startId}
- ORDER BY linkis_ps_job_history_group_history.created_time
diff --git a/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/postgresql/JobHistoryMapper.xml b/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/postgresql/JobHistoryMapper.xml
index 0289141e898..2c33cb44902 100644
--- a/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/postgresql/JobHistoryMapper.xml
+++ b/linkis-public-enhancements/linkis-jobhistory/src/main/resources/mapper/postgresql/JobHistoryMapper.xml
@@ -95,16 +95,23 @@
ORDER BY linkis_ps_job_history_group_history.created_time DESC
-
- /*slave*/ SELECT * FROM linkis_ps_job_history_group_history
+
+ /*slave*/ SELECT id FROM linkis_ps_job_history_group_history
- id >= #{id}
- and submit_user = #{umUser}
- and engine_type = #{engineType}
and created_time >= #{startDate} AND created_time #{endDate}
+ and id >= #{startId}
and #{element}
ORDER BY linkis_ps_job_history_group_history.id
+ LIMIT 2
+
+
+
+ /*slave*/ SELECT MAX(id) FROM linkis_ps_job_history_group_history
+
+ and created_time >= #{startDate} AND created_time #{endDate}
+ and id >= #{startId}
+
diff --git a/linkis-public-enhancements/linkis-jobhistory/src/test/java/org/apache/linkis/jobhistory/dao/JobHistoryMapperUndoneTaskTest.java b/linkis-public-enhancements/linkis-jobhistory/src/test/java/org/apache/linkis/jobhistory/dao/JobHistoryMapperUndoneTaskTest.java
new file mode 100644
index 00000000000..40d2e8d270f
--- /dev/null
+++ b/linkis-public-enhancements/linkis-jobhistory/src/test/java/org/apache/linkis/jobhistory/dao/JobHistoryMapperUndoneTaskTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.jobhistory.dao;
+
+import org.apache.ibatis.builder.xml.XMLMapperBuilder;
+import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.mapping.Environment;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
+
+import java.io.InputStream;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Covers the queries used by {@code DefaultQueryCacheManager#refreshUndoneTask} with both the MySQL
+ * and the PostgreSQL mapper. The Spring based DAO tests only load the MySQL mapper, so a plain
+ * MyBatis session is used here.
+ */
+class JobHistoryMapperUndoneTaskTest {
+
+ private static final Date START = Timestamp.valueOf("2026-01-01 00:00:00");
+ private static final Date END = Timestamp.valueOf("2026-01-02 00:00:00");
+
+ @Test
+ void searchWithIdOrderAscOnPostgresql() throws Exception {
+ try (SqlSession session = openSession("postgresql", "PostgreSQL")) {
+ List ids =
+ session
+ .getMapper(JobHistoryMapper.class)
+ .searchWithIdOrderAsc(
+ START, END, 3L, Arrays.asList("Running", "Inited", "Scheduled"));
+ assertEquals(Arrays.asList(4, 5), ids);
+ }
+ }
+
+ @ParameterizedTest
+ @CsvSource({"mysql, MySQL", "postgresql, PostgreSQL"})
+ void maxID(String dialect, String h2Mode) throws Exception {
+ try (SqlSession session = openSession(dialect, h2Mode)) {
+ assertEquals(
+ Integer.valueOf(6), session.getMapper(JobHistoryMapper.class).maxID(START, END, 3L));
+ }
+ }
+
+ private static SqlSession openSession(String dialect, String h2Mode) throws Exception {
+ UnpooledDataSource dataSource =
+ new UnpooledDataSource(
+ "org.h2.Driver", "jdbc:h2:mem:" + dialect + ";MODE=" + h2Mode, "sa", "");
+ Configuration configuration =
+ new Configuration(new Environment("test", new JdbcTransactionFactory(), dataSource));
+ String resource = "mapper/" + dialect + "/JobHistoryMapper.xml";
+ try (InputStream input = Resources.getResourceAsStream(resource)) {
+ new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
+ }
+ SqlSession session = new SqlSessionFactoryBuilder().build(configuration).openSession(true);
+ try (Statement statement = session.getConnection().createStatement()) {
+ statement.execute(
+ "CREATE TABLE linkis_ps_job_history_group_history "
+ + "(id BIGINT, status VARCHAR(50), created_time TIMESTAMP)");
+ // Inserted in descending id order so that a missing ORDER BY shows up.
+ statement.execute(
+ "INSERT INTO linkis_ps_job_history_group_history VALUES "
+ + "(7, 'Running', '2026-01-02 01:00:00'), "
+ + "(6, 'Running', '2026-01-01 13:00:00'), "
+ + "(5, 'Inited', '2026-01-01 12:00:00'), "
+ + "(4, 'Scheduled', '2026-01-01 11:00:00'), "
+ + "(3, 'Succeed', '2026-01-01 10:00:00'), "
+ + "(2, 'Running', '2026-01-01 09:00:00'), "
+ + "(1, 'Running', '2025-12-31 23:00:00')");
+ }
+ return session;
+ }
+}