public synchronized void releaseResource() {
    // For schema related query FI, closedFilePaths and unClosedFilePaths will be null
    if (closedFilePaths != null) {
      for (TsFileResource tsFile : closedFilePaths) {
        FileReaderManager.getInstance().decreaseFileReaderReference(tsFile, true);
      }
      closedFilePaths = null;
    }

    if (unClosedFilePaths != null) {
      for (TsFileResource tsFile : unClosedFilePaths) {
        FileReaderManager.getInstance().decreaseFileReaderReference(tsFile, false);
      }
      unClosedFilePaths = null;
    }

    // release TVList/AlignedTVList owned by current query
    releaseTVListOwnedByQuery();

    dataRegion = null;
    globalTimeFilter = null;
    sharedQueryDataSource = null;

    // record fragment instance execution time and metadata get time to metrics
    long durationTime = System.currentTimeMillis() - executionStartTime.get();
    DriverSchedulerMetricSet.getInstance()
        .recordTaskQueueTime(BLOCK_QUEUED_TIME, blockQueueTime.get());
    DriverSchedulerMetricSet.getInstance()
        .recordTaskQueueTime(READY_QUEUED_TIME, readyQueueTime.get());

    QueryRelatedResourceMetricSet.getInstance().updateFragmentInstanceTime(durationTime);

    SeriesScanCostMetricSet.getInstance()
        .recordBloomFilterMetrics(
            getQueryStatistics().getLoadBloomFilterFromCacheCount().get(),
            getQueryStatistics().getLoadBloomFilterFromDiskCount().get(),
            getQueryStatistics().getLoadBloomFilterActualIOSize().get(),
            getQueryStatistics().getLoadBloomFilterTime().get());

    SeriesScanCostMetricSet.getInstance()
        .recordNonAlignedTimeSeriesMetadataCount(
            getQueryStatistics().getLoadTimeSeriesMetadataDiskSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataDiskUnSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataMemSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataMemUnSeqCount().get());
    SeriesScanCostMetricSet.getInstance()
        .recordNonAlignedTimeSeriesMetadataTime(
            getQueryStatistics().getLoadTimeSeriesMetadataDiskSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataDiskUnSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataMemSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataMemUnSeqTime().get());
    SeriesScanCostMetricSet.getInstance()
        .recordAlignedTimeSeriesMetadataCount(
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedDiskSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedDiskUnSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedMemSeqCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedMemUnSeqCount().get());
    SeriesScanCostMetricSet.getInstance()
        .recordAlignedTimeSeriesMetadataTime(
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedDiskSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedDiskUnSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedMemSeqTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataAlignedMemUnSeqTime().get());

    SeriesScanCostMetricSet.getInstance()
        .recordTimeSeriesMetadataMetrics(
            getQueryStatistics().getLoadTimeSeriesMetadataFromCacheCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataFromDiskCount().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataActualIOSize().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataFromCacheTime().get(),
            getQueryStatistics().getLoadTimeSeriesMetadataFromDiskTime().get());

    SeriesScanCostMetricSet.getInstance()
        .recordConstructChunkReadersCount(
            getQueryStatistics().getConstructAlignedChunkReadersMemCount().get(),
            getQueryStatistics().getConstructAlignedChunkReadersDiskCount().get(),
            getQueryStatistics().getConstructNonAlignedChunkReadersMemCount().get(),
            getQueryStatistics().getConstructNonAlignedChunkReadersDiskCount().get());
    SeriesScanCostMetricSet.getInstance()
        .recordConstructChunkReadersTime(
            getQueryStatistics().getConstructAlignedChunkReadersMemTime().get(),
            getQueryStatistics().getConstructAlignedChunkReadersDiskTime().get(),
            getQueryStatistics().getConstructNonAlignedChunkReadersMemTime().get(),
            getQueryStatistics().getConstructNonAlignedChunkReadersDiskTime().get());

    SeriesScanCostMetricSet.getInstance()
        .recordChunkMetrics(
            getQueryStatistics().getLoadChunkFromCacheCount().get(),
            getQueryStatistics().getLoadChunkFromDiskCount().get(),
            getQueryStatistics().getLoadChunkActualIOSize().get());

    SeriesScanCostMetricSet.getInstance()
        .recordPageReadersDecompressCount(
            getQueryStatistics().getPageReadersDecodeAlignedMemCount().get(),
            getQueryStatistics().getPageReadersDecodeAlignedDiskCount().get(),
            getQueryStatistics().getPageReadersDecodeNonAlignedMemCount().get(),
            getQueryStatistics().getPageReadersDecodeNonAlignedDiskCount().get());
    SeriesScanCostMetricSet.getInstance()
        .recordPageReadersDecompressTime(
            getQueryStatistics().getPageReadersDecodeAlignedMemTime().get(),
            getQueryStatistics().getPageReadersDecodeAlignedDiskTime().get(),
            getQueryStatistics().getPageReadersDecodeNonAlignedMemTime().get(),
            getQueryStatistics().getPageReadersDecodeNonAlignedDiskTime().get());

    SeriesScanCostMetricSet.getInstance()
        .recordTimeSeriesMetadataModification(
            getQueryStatistics().getAlignedTimeSeriesMetadataModificationCount().get(),
            getQueryStatistics().getNonAlignedTimeSeriesMetadataModificationCount().get(),
            getQueryStatistics().getAlignedTimeSeriesMetadataModificationTime().get(),
            getQueryStatistics().getNonAlignedTimeSeriesMetadataModificationTime().get());

    SeriesScanCostMetricSet.getInstance()
        .updatePageReaderMemoryUsage(getQueryStatistics().getPageReaderMaxUsedMemorySize().get());
  }
All file paths used by this fragment instance must be cleared and thus the usage reference must
be decreased.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java